@storm-software/eslint-plugin-bun 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/configs/index.d.mts +5 -0
- package/dist/configs/index.mjs +4 -943
- package/dist/configs/recommended.d.mts +5 -0
- package/dist/configs/recommended.mjs +33 -939
- package/dist/helpers/bun-workspace.d.mts +49 -0
- package/dist/helpers/bun-workspace.mjs +197 -244
- package/dist/helpers/{create-rule.d.ts → create-rule.d.mts} +6 -6
- package/dist/helpers/create-rule.mjs +37 -38
- package/dist/helpers/{iterate-dependencies.d.ts → iterate-dependencies.d.mts} +7 -7
- package/dist/helpers/iterate-dependencies.mjs +36 -56
- package/dist/index.d.mts +52 -0
- package/dist/index.mjs +29 -951
- package/dist/plugin-9WjNsG8_.mjs +20 -0
- package/dist/plugin.d.mts +31 -0
- package/dist/plugin.mjs +1 -807
- package/dist/rules/json-enforce-catalog.d.mts +14 -0
- package/dist/rules/json-enforce-catalog.mjs +102 -444
- package/dist/rules/json-no-duplicate-catalog-item.d.mts +8 -0
- package/dist/rules/json-no-duplicate-catalog-item.mjs +72 -386
- package/dist/rules/json-no-unused-catalog-item.d.mts +5 -0
- package/dist/rules/json-no-unused-catalog-item.mjs +70 -423
- package/dist/rules/json-valid-catalog.d.mts +11 -0
- package/dist/rules/json-valid-catalog.mjs +80 -422
- package/package.json +15 -22
- package/dist/configs/index.d.ts +0 -5
- package/dist/configs/recommended.d.ts +0 -5
- package/dist/helpers/bun-workspace.d.ts +0 -48
- package/dist/index.d.ts +0 -58
- package/dist/plugin.d.ts +0 -33
- package/dist/rules/json-enforce-catalog.d.ts +0 -18
- package/dist/rules/json-no-duplicate-catalog-item.d.ts +0 -12
- package/dist/rules/json-no-unused-catalog-item.d.ts +0 -7
- package/dist/rules/json-valid-catalog.d.ts +0 -15
|
@@ -1,426 +1,84 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
...rule
|
|
14
|
-
}) {
|
|
15
|
-
return createRuleInfo({
|
|
16
|
-
meta: {
|
|
17
|
-
...meta,
|
|
18
|
-
docs: {
|
|
19
|
-
...meta.docs,
|
|
20
|
-
url: urlCreator(name)
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
...rule
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function createRuleInfo({
|
|
28
|
-
create,
|
|
29
|
-
defaultOptions,
|
|
30
|
-
meta
|
|
31
|
-
}) {
|
|
32
|
-
return {
|
|
33
|
-
create: ((context) => {
|
|
34
|
-
const optionsWithDefault = context.options.map((options, index) => {
|
|
35
|
-
return defu(defaultOptions?.[index] ?? {}, options);
|
|
36
|
-
});
|
|
37
|
-
return create(context, optionsWithDefault);
|
|
38
|
-
}),
|
|
39
|
-
defaultOptions: defaultOptions ?? {},
|
|
40
|
-
meta
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
var createRule = RuleCreator(
|
|
44
|
-
(ruleName) => `https://docs.stormsoftware.com/projects/storm-ops/eslint-plugin-bun/rules/${ruleName}.md`
|
|
45
|
-
);
|
|
46
|
-
function isWorkspaceObject(workspaces) {
|
|
47
|
-
return Boolean(workspaces) && typeof workspaces === "object" && !Array.isArray(workspaces);
|
|
48
|
-
}
|
|
49
|
-
function detectCatalogRoot(data) {
|
|
50
|
-
if (data.catalog || data.catalogs) {
|
|
51
|
-
return "top";
|
|
52
|
-
}
|
|
53
|
-
if (isWorkspaceObject(data.workspaces) && (data.workspaces.catalog || data.workspaces.catalogs)) {
|
|
54
|
-
return "workspaces";
|
|
55
|
-
}
|
|
56
|
-
return isWorkspaceObject(data.workspaces) ? "workspaces" : "top";
|
|
57
|
-
}
|
|
58
|
-
function normalizeCatalogName(name) {
|
|
59
|
-
return name.replace(/\^/g, "h").replace(/~/g, "t").replace(/\./g, "_").replace(/</g, "l").replace(/>/g, "g").replace(/=/g, "e").replace(/\*/g, "s").replace(/@/g, "a").replace(/\|/g, "p").replace(/&/g, "n").replace(/-/g, "m").replace(/\+/g, "u").replace(/\s/g, "_");
|
|
60
|
-
}
|
|
61
|
-
function sortObjectKeys(input) {
|
|
62
|
-
return Object.fromEntries(
|
|
63
|
-
Object.entries(input).sort(([left], [right]) => left.localeCompare(right))
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
function isWorkspaceRootPackageJson(data) {
|
|
67
|
-
return Boolean(
|
|
68
|
-
data.workspaces || data.catalog || data.catalogs
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
function readBunWorkspace(cwd = process.cwd()) {
|
|
72
|
-
const filepath = findUpSync("package.json", {
|
|
73
|
-
cwd,
|
|
74
|
-
type: "file"
|
|
75
|
-
});
|
|
76
|
-
if (!filepath) {
|
|
77
|
-
throw new Error("package.json not found");
|
|
78
|
-
}
|
|
79
|
-
let current = filepath;
|
|
80
|
-
let content = fs.readFileSync(current, "utf8");
|
|
81
|
-
let data = JSON.parse(content);
|
|
82
|
-
while (!isWorkspaceRootPackageJson(data)) {
|
|
83
|
-
const searchFrom = dirname(dirname(current));
|
|
84
|
-
const next = findUpSync("package.json", {
|
|
85
|
-
cwd: searchFrom,
|
|
86
|
-
type: "file"
|
|
87
|
-
});
|
|
88
|
-
if (!next || normalize(next) === normalize(current)) {
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
current = next;
|
|
92
|
-
content = fs.readFileSync(current, "utf8");
|
|
93
|
-
data = JSON.parse(content);
|
|
94
|
-
}
|
|
95
|
-
if (!isWorkspaceRootPackageJson(data)) {
|
|
96
|
-
throw new Error(
|
|
97
|
-
"Bun workspace root package.json with workspaces/catalog not found"
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
let hasChanged = false;
|
|
101
|
-
let queueTimer;
|
|
102
|
-
const queue = [];
|
|
103
|
-
let catalogRoot = detectCatalogRoot(data);
|
|
104
|
-
const write = () => {
|
|
105
|
-
if (!fs.existsSync(current)) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
fs.writeFileSync(current, `${JSON.stringify(data, null, 2)}
|
|
109
|
-
`);
|
|
110
|
-
};
|
|
111
|
-
const clearQueue = () => {
|
|
112
|
-
if (queueTimer != null) {
|
|
113
|
-
clearTimeout(queueTimer);
|
|
114
|
-
queueTimer = void 0;
|
|
115
|
-
}
|
|
116
|
-
queue.length = 0;
|
|
117
|
-
};
|
|
118
|
-
const getCatalogContainer = () => {
|
|
119
|
-
if (catalogRoot === "workspaces") {
|
|
120
|
-
if (!isWorkspaceObject(data.workspaces)) {
|
|
121
|
-
data.workspaces = {
|
|
122
|
-
packages: Array.isArray(data.workspaces) ? data.workspaces : [],
|
|
123
|
-
catalog: {},
|
|
124
|
-
catalogs: {}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
return data.workspaces;
|
|
128
|
-
}
|
|
129
|
-
return data;
|
|
130
|
-
};
|
|
131
|
-
const getCatalogData = () => {
|
|
132
|
-
const container = getCatalogContainer();
|
|
133
|
-
return {
|
|
134
|
-
catalog: container.catalog,
|
|
135
|
-
catalogs: container.catalogs
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
const setPackage = (catalogName, packageName, specifier) => {
|
|
139
|
-
const container = getCatalogContainer();
|
|
140
|
-
if (catalogName === "default") {
|
|
141
|
-
container.catalog ??= {};
|
|
142
|
-
if (container.catalog[packageName] !== specifier) {
|
|
143
|
-
container.catalog[packageName] = specifier;
|
|
144
|
-
container.catalog = sortObjectKeys(container.catalog);
|
|
145
|
-
hasChanged = true;
|
|
146
|
-
}
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
container.catalogs ??= {};
|
|
150
|
-
container.catalogs[catalogName] ??= {};
|
|
151
|
-
if (container.catalogs[catalogName][packageName] !== specifier) {
|
|
152
|
-
container.catalogs[catalogName][packageName] = specifier;
|
|
153
|
-
container.catalogs[catalogName] = sortObjectKeys(
|
|
154
|
-
container.catalogs[catalogName]
|
|
155
|
-
);
|
|
156
|
-
container.catalogs = sortObjectKeys(container.catalogs);
|
|
157
|
-
hasChanged = true;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
const hasSpecifierConflicts = (catalogName, packageName, specifier) => {
|
|
161
|
-
const { catalog, catalogs } = getCatalogData();
|
|
162
|
-
const existingSpecifier = catalogName === "default" ? catalog?.[packageName] : catalogs?.[catalogName]?.[packageName];
|
|
163
|
-
if (existingSpecifier === specifier) {
|
|
164
|
-
return {
|
|
165
|
-
conflicts: false,
|
|
166
|
-
newCatalogName: catalogName,
|
|
167
|
-
existingSpecifier
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
if (existingSpecifier) {
|
|
171
|
-
const versionSuffix = normalizeCatalogName(specifier);
|
|
172
|
-
const newCatalogName = catalogName === "default" ? `conflicts_${packageName}_${versionSuffix}` : `conflicts_${catalogName}_${versionSuffix}`;
|
|
173
|
-
return {
|
|
174
|
-
conflicts: true,
|
|
175
|
-
existingSpecifier,
|
|
176
|
-
newCatalogName
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
conflicts: false,
|
|
181
|
-
newCatalogName: catalogName
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
const getPackageCatalogs = (packageName) => {
|
|
185
|
-
const found = [];
|
|
186
|
-
const { catalog, catalogs } = getCatalogData();
|
|
187
|
-
if (catalogs) {
|
|
188
|
-
for (const name of Object.keys(catalogs)) {
|
|
189
|
-
if (catalogs[name]?.[packageName]) {
|
|
190
|
-
found.push(name);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (catalog?.[packageName]) {
|
|
195
|
-
found.push("default");
|
|
196
|
-
}
|
|
197
|
-
return found;
|
|
198
|
-
};
|
|
199
|
-
const workspace2 = {
|
|
200
|
-
filepath: current,
|
|
201
|
-
setContent(newContent) {
|
|
202
|
-
content = newContent;
|
|
203
|
-
data = JSON.parse(newContent);
|
|
204
|
-
catalogRoot = detectCatalogRoot(data);
|
|
205
|
-
hasChanged = false;
|
|
206
|
-
},
|
|
207
|
-
hasChanged: () => hasChanged,
|
|
208
|
-
hasQueue: () => queueTimer != null,
|
|
209
|
-
clearQueue,
|
|
210
|
-
queueChange(fn, order) {
|
|
211
|
-
if (order === "pre") {
|
|
212
|
-
queue.unshift(fn);
|
|
213
|
-
} else {
|
|
214
|
-
queue.push(fn);
|
|
215
|
-
}
|
|
216
|
-
if (queueTimer != null) {
|
|
217
|
-
clearTimeout(queueTimer);
|
|
218
|
-
}
|
|
219
|
-
queueTimer = setTimeout(() => {
|
|
220
|
-
queueTimer = void 0;
|
|
221
|
-
const clone = [...queue];
|
|
222
|
-
queue.length = 0;
|
|
223
|
-
for (const queued of clone) {
|
|
224
|
-
queued(workspace2);
|
|
225
|
-
}
|
|
226
|
-
if (hasChanged) {
|
|
227
|
-
write();
|
|
228
|
-
}
|
|
229
|
-
}, 1e3);
|
|
230
|
-
},
|
|
231
|
-
toJSON: () => data,
|
|
232
|
-
toString: () => `${JSON.stringify(data, null, 2)}
|
|
233
|
-
`,
|
|
234
|
-
setPackage,
|
|
235
|
-
setPackageNoConflicts(catalogName, packageName, specifier) {
|
|
236
|
-
const { newCatalogName } = hasSpecifierConflicts(
|
|
237
|
-
catalogName,
|
|
238
|
-
packageName,
|
|
239
|
-
specifier
|
|
240
|
-
);
|
|
241
|
-
setPackage(newCatalogName, packageName, specifier);
|
|
242
|
-
},
|
|
243
|
-
getPackageCatalogs,
|
|
244
|
-
hasSpecifierConflicts,
|
|
245
|
-
getCatalogData,
|
|
246
|
-
getWorkspacePackagePatterns() {
|
|
247
|
-
if (Array.isArray(data.workspaces)) {
|
|
248
|
-
return data.workspaces;
|
|
249
|
-
}
|
|
250
|
-
if (isWorkspaceObject(data.workspaces) && data.workspaces.packages) {
|
|
251
|
-
return data.workspaces.packages;
|
|
252
|
-
}
|
|
253
|
-
return [];
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
return workspace2;
|
|
257
|
-
}
|
|
258
|
-
var WORKSPACE_CACHE_TIME = 1e4;
|
|
259
|
-
var workspaceLastRead;
|
|
260
|
-
var workspace;
|
|
261
|
-
function getBunWorkspace(cwd = process.cwd()) {
|
|
262
|
-
if (workspaceLastRead && workspace && !workspace.hasQueue() && Date.now() - workspaceLastRead > WORKSPACE_CACHE_TIME) {
|
|
263
|
-
workspace = void 0;
|
|
264
|
-
}
|
|
265
|
-
if (!workspace) {
|
|
266
|
-
workspace = readBunWorkspace(cwd);
|
|
267
|
-
workspaceLastRead = Date.now();
|
|
268
|
-
}
|
|
269
|
-
return workspace;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// src/helpers/iterate-dependencies.ts
|
|
273
|
-
function getPackageJsonRootNode(context) {
|
|
274
|
-
if (!context.filename.endsWith("package.json")) {
|
|
275
|
-
return void 0;
|
|
276
|
-
}
|
|
277
|
-
const ast = context.sourceCode.ast;
|
|
278
|
-
const root = ast.body[0];
|
|
279
|
-
if (root?.expression?.type === "JSONObjectExpression") {
|
|
280
|
-
return root.expression;
|
|
281
|
-
}
|
|
282
|
-
return void 0;
|
|
283
|
-
}
|
|
284
|
-
function* iterateDependencies(context, fields) {
|
|
285
|
-
const root = getPackageJsonRootNode(context);
|
|
286
|
-
if (!root) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
for (const fieldName of fields) {
|
|
290
|
-
const path = fieldName.split(".");
|
|
291
|
-
let node = root;
|
|
292
|
-
for (const segment of path) {
|
|
293
|
-
const item = node.properties?.find(
|
|
294
|
-
(property) => property.key.type === "JSONLiteral" && property.key.value === segment
|
|
295
|
-
);
|
|
296
|
-
if (!item?.value || item.value.type !== "JSONObjectExpression") {
|
|
297
|
-
node = void 0;
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
node = item.value;
|
|
301
|
-
}
|
|
302
|
-
if (!node || node === root || !node.properties) {
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
for (const property of node.properties) {
|
|
306
|
-
if (property.value.type !== "JSONLiteral" || property.key.type !== "JSONLiteral") {
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
if (typeof property.value.value !== "string") {
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
yield {
|
|
313
|
-
packageName: String(property.key.value),
|
|
314
|
-
specifier: String(property.value.value),
|
|
315
|
-
property
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// src/rules/json-valid-catalog.ts
|
|
322
|
-
var RULE_NAME = "json-valid-catalog";
|
|
323
|
-
var DEFAULT_FIELDS = [
|
|
324
|
-
"dependencies",
|
|
325
|
-
"devDependencies",
|
|
326
|
-
"optionalDependencies",
|
|
327
|
-
"peerDependencies",
|
|
328
|
-
"resolutions",
|
|
329
|
-
"overrides"
|
|
1
|
+
import { createRule } from "../helpers/create-rule.mjs";
|
|
2
|
+
import { getBunWorkspace } from "../helpers/bun-workspace.mjs";
|
|
3
|
+
import { iterateDependencies } from "../helpers/iterate-dependencies.mjs";
|
|
4
|
+
//#region src/rules/json-valid-catalog.ts
|
|
5
|
+
const RULE_NAME = "json-valid-catalog";
|
|
6
|
+
const DEFAULT_FIELDS = [
|
|
7
|
+
"dependencies",
|
|
8
|
+
"devDependencies",
|
|
9
|
+
"optionalDependencies",
|
|
10
|
+
"peerDependencies",
|
|
11
|
+
"resolutions",
|
|
12
|
+
"overrides"
|
|
330
13
|
];
|
|
331
14
|
var json_valid_catalog_default = createRule({
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
specifier,
|
|
400
|
-
packageName
|
|
401
|
-
},
|
|
402
|
-
fix: !autofix || !autoInsert && !existingCatalogs.length ? void 0 : (fixer) => {
|
|
403
|
-
let catalog = existingCatalogs[0];
|
|
404
|
-
if (!catalog && autoInsert) {
|
|
405
|
-
catalog = currentCatalog;
|
|
406
|
-
workspace2.queueChange(() => {
|
|
407
|
-
workspace2.setPackage(
|
|
408
|
-
catalog,
|
|
409
|
-
packageName,
|
|
410
|
-
autoInsertDefaultSpecifier
|
|
411
|
-
);
|
|
412
|
-
}, "pre");
|
|
413
|
-
}
|
|
414
|
-
return fixer.replaceText(
|
|
415
|
-
property.value,
|
|
416
|
-
catalog === "default" ? JSON.stringify("catalog:") : JSON.stringify(`catalog:${catalog}`)
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return {};
|
|
423
|
-
}
|
|
15
|
+
name: RULE_NAME,
|
|
16
|
+
meta: {
|
|
17
|
+
type: "layout",
|
|
18
|
+
docs: { description: "Enforce using valid Bun catalog references in `package.json`" },
|
|
19
|
+
fixable: "code",
|
|
20
|
+
schema: [{
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
autoInsert: {
|
|
24
|
+
type: "boolean",
|
|
25
|
+
description: "Whether to auto insert to catalog if missing",
|
|
26
|
+
default: true
|
|
27
|
+
},
|
|
28
|
+
autoInsertDefaultSpecifier: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Default specifier to use when auto inserting to catalog",
|
|
31
|
+
default: "^0.0.0"
|
|
32
|
+
},
|
|
33
|
+
autofix: {
|
|
34
|
+
type: "boolean",
|
|
35
|
+
description: "Whether to autofix the linting error",
|
|
36
|
+
default: true
|
|
37
|
+
},
|
|
38
|
+
fields: {
|
|
39
|
+
type: "array",
|
|
40
|
+
description: "Fields to check for catalog",
|
|
41
|
+
default: DEFAULT_FIELDS
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
additionalProperties: false
|
|
45
|
+
}],
|
|
46
|
+
messages: { invalidCatalog: "Catalog \"{{specifier}}\" for package \"{{packageName}}\" is not defined in the workspace root `package.json`." }
|
|
47
|
+
},
|
|
48
|
+
defaultOptions: [{}],
|
|
49
|
+
create(context, [options = {}]) {
|
|
50
|
+
const { autoInsert = true, autofix = true, autoInsertDefaultSpecifier = "^0.0.0", fields = DEFAULT_FIELDS } = options || {};
|
|
51
|
+
for (const { packageName, specifier, property } of iterateDependencies(context, fields)) {
|
|
52
|
+
if (!specifier.startsWith("catalog:")) continue;
|
|
53
|
+
let workspace;
|
|
54
|
+
try {
|
|
55
|
+
workspace = getBunWorkspace();
|
|
56
|
+
} catch {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
const currentCatalog = specifier.replace(/^catalog:/, "").trim() || "default";
|
|
60
|
+
const existingCatalogs = workspace.getPackageCatalogs(packageName);
|
|
61
|
+
if (!existingCatalogs.includes(currentCatalog)) context.report({
|
|
62
|
+
node: property.value,
|
|
63
|
+
messageId: "invalidCatalog",
|
|
64
|
+
data: {
|
|
65
|
+
specifier,
|
|
66
|
+
packageName
|
|
67
|
+
},
|
|
68
|
+
fix: !autofix || !autoInsert && !existingCatalogs.length ? void 0 : (fixer) => {
|
|
69
|
+
let catalog = existingCatalogs[0];
|
|
70
|
+
if (!catalog && autoInsert) {
|
|
71
|
+
catalog = currentCatalog;
|
|
72
|
+
workspace.queueChange(() => {
|
|
73
|
+
workspace.setPackage(catalog, packageName, autoInsertDefaultSpecifier);
|
|
74
|
+
}, "pre");
|
|
75
|
+
}
|
|
76
|
+
return fixer.replaceText(property.value, catalog === "default" ? JSON.stringify("catalog:") : JSON.stringify(`catalog:${catalog}`));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
424
82
|
});
|
|
425
|
-
|
|
83
|
+
//#endregion
|
|
426
84
|
export { json_valid_catalog_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storm-software/eslint-plugin-bun",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "An ESLint Plugin that enforces Bun catalog rules in Storm Software projects.",
|
|
6
6
|
"keywords": ["eslint", "eslint-plugin", "storm-software", "bun", "catalog"],
|
|
@@ -40,29 +40,22 @@
|
|
|
40
40
|
],
|
|
41
41
|
"type": "module",
|
|
42
42
|
"exports": {
|
|
43
|
-
".":
|
|
44
|
-
"./
|
|
45
|
-
"./configs":
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"./
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"./
|
|
54
|
-
"types": "./dist/helpers/create-rule.d.ts",
|
|
55
|
-
"default": "./dist/helpers/create-rule.mjs"
|
|
56
|
-
},
|
|
57
|
-
"./plugin": {
|
|
58
|
-
"types": "./dist/plugin.d.ts",
|
|
59
|
-
"default": "./dist/plugin.mjs"
|
|
60
|
-
},
|
|
43
|
+
".": "./dist/index.mjs",
|
|
44
|
+
"./configs": "./dist/configs/index.mjs",
|
|
45
|
+
"./configs/recommended": "./dist/configs/recommended.mjs",
|
|
46
|
+
"./helpers/bun-workspace": "./dist/helpers/bun-workspace.mjs",
|
|
47
|
+
"./helpers/create-rule": "./dist/helpers/create-rule.mjs",
|
|
48
|
+
"./helpers/iterate-dependencies": "./dist/helpers/iterate-dependencies.mjs",
|
|
49
|
+
"./plugin": "./dist/plugin.mjs",
|
|
50
|
+
"./rules/json-enforce-catalog": "./dist/rules/json-enforce-catalog.mjs",
|
|
51
|
+
"./rules/json-no-duplicate-catalog-item": "./dist/rules/json-no-duplicate-catalog-item.mjs",
|
|
52
|
+
"./rules/json-no-unused-catalog-item": "./dist/rules/json-no-unused-catalog-item.mjs",
|
|
53
|
+
"./rules/json-valid-catalog": "./dist/rules/json-valid-catalog.mjs",
|
|
61
54
|
"./package.json": "./package.json"
|
|
62
55
|
},
|
|
63
56
|
"files": ["dist"],
|
|
64
57
|
"dependencies": {
|
|
65
|
-
"@storm-software/package-constants": "0.1.
|
|
58
|
+
"@storm-software/package-constants": "0.1.132",
|
|
66
59
|
"@typescript-eslint/utils": "^8.66.0",
|
|
67
60
|
"defu": "^6.1.7",
|
|
68
61
|
"find-up-simple": "^1.0.1",
|
|
@@ -73,7 +66,7 @@
|
|
|
73
66
|
"devDependencies": {
|
|
74
67
|
"@eslint/compat": "^2.1.0",
|
|
75
68
|
"@eslint/config-inspector": "^1.5.0",
|
|
76
|
-
"@storm-software/prettier": "0.59.
|
|
69
|
+
"@storm-software/prettier": "0.59.172",
|
|
77
70
|
"@types/eslint": "^9.6.1",
|
|
78
71
|
"@types/eslint__js": "^8.42.3",
|
|
79
72
|
"@types/node": "^25.9.5",
|
|
@@ -87,5 +80,5 @@
|
|
|
87
80
|
"peerDependencies": { "eslint": ">=9.39.3" },
|
|
88
81
|
"peerDependenciesMeta": { "eslint": { "optional": false } },
|
|
89
82
|
"publishConfig": { "access": "public" },
|
|
90
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "b0295f0d2bd154ea4c2eb15e55e0e6dc62978042"
|
|
91
84
|
}
|
package/dist/configs/index.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
interface BunWorkspacePackageJson {
|
|
2
|
-
catalog?: Record<string, string>;
|
|
3
|
-
catalogs?: Record<string, Record<string, string>>;
|
|
4
|
-
workspaces?: string[] | {
|
|
5
|
-
packages?: string[];
|
|
6
|
-
catalog?: Record<string, string>;
|
|
7
|
-
catalogs?: Record<string, Record<string, string>>;
|
|
8
|
-
};
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
}
|
|
11
|
-
type CatalogName = "default" | (string & {});
|
|
12
|
-
interface SpecifierConflicts {
|
|
13
|
-
conflicts: boolean;
|
|
14
|
-
newCatalogName: string;
|
|
15
|
-
existingSpecifier?: string;
|
|
16
|
-
}
|
|
17
|
-
interface BunWorkspace {
|
|
18
|
-
filepath: string;
|
|
19
|
-
setContent: (content: string) => void;
|
|
20
|
-
hasChanged: () => boolean;
|
|
21
|
-
hasQueue: () => boolean;
|
|
22
|
-
clearQueue: () => void;
|
|
23
|
-
queueChange: (fn: (workspace: BunWorkspace) => void, order?: "pre" | "post") => void;
|
|
24
|
-
toJSON: () => BunWorkspacePackageJson;
|
|
25
|
-
toString: () => string;
|
|
26
|
-
setPackage: (catalog: CatalogName, packageName: string, specifier: string) => void;
|
|
27
|
-
setPackageNoConflicts: (catalog: CatalogName, packageName: string, specifier: string) => void;
|
|
28
|
-
getPackageCatalogs: (packageName: string) => string[];
|
|
29
|
-
hasSpecifierConflicts: (catalog: CatalogName, packageName: string, specifier: string) => SpecifierConflicts;
|
|
30
|
-
getCatalogData: () => {
|
|
31
|
-
catalog?: Record<string, string>;
|
|
32
|
-
catalogs?: Record<string, Record<string, string>>;
|
|
33
|
-
};
|
|
34
|
-
getWorkspacePackagePatterns: () => string[];
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Find and parse the Bun workspace root `package.json` that holds catalogs.
|
|
38
|
-
*
|
|
39
|
-
* Catalogs live in root `package.json` (top-level or under `workspaces`), not
|
|
40
|
-
* `pnpm-workspace.yaml`. See https://bun.com/docs/pm/catalogs
|
|
41
|
-
*/
|
|
42
|
-
declare function readBunWorkspace(cwd?: string): BunWorkspace;
|
|
43
|
-
declare function getBunWorkspace(cwd?: string): BunWorkspace;
|
|
44
|
-
declare function resetBunWorkspaceCache(): void;
|
|
45
|
-
declare function isRootWorkspacePackageJson(filename: string, cwd?: string): boolean;
|
|
46
|
-
declare function collectWorkspacePackageJsonPaths(workspaceRoot: BunWorkspace): string[];
|
|
47
|
-
|
|
48
|
-
export { type BunWorkspace, type BunWorkspacePackageJson, type CatalogName, type SpecifierConflicts, collectWorkspacePackageJsonPaths, getBunWorkspace, isRootWorkspacePackageJson, readBunWorkspace, resetBunWorkspaceCache };
|