@storm-software/eslint-plugin-bun 0.0.6 → 0.0.8
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-DfH7W_YX.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 +17 -23
- 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,63 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/helpers/iterate-dependencies.ts
|
|
2
2
|
function getPackageJsonRootNode(context) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const ast = context.sourceCode.ast;
|
|
7
|
-
const root = ast.body[0];
|
|
8
|
-
if (root?.expression?.type === "JSONObjectExpression") {
|
|
9
|
-
return root.expression;
|
|
10
|
-
}
|
|
11
|
-
return void 0;
|
|
3
|
+
if (!context.filename.endsWith("package.json")) return;
|
|
4
|
+
const root = context.sourceCode.ast.body[0];
|
|
5
|
+
if (root?.expression?.type === "JSONObjectExpression") return root.expression;
|
|
12
6
|
}
|
|
13
7
|
function* iterateDependencies(context, fields) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (typeof property.value.value !== "string") {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
yield {
|
|
42
|
-
packageName: String(property.key.value),
|
|
43
|
-
specifier: String(property.value.value),
|
|
44
|
-
property
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
8
|
+
const root = getPackageJsonRootNode(context);
|
|
9
|
+
if (!root) return;
|
|
10
|
+
for (const fieldName of fields) {
|
|
11
|
+
const path = fieldName.split(".");
|
|
12
|
+
let node = root;
|
|
13
|
+
for (const segment of path) {
|
|
14
|
+
const item = node.properties?.find((property) => property.key.type === "JSONLiteral" && property.key.value === segment);
|
|
15
|
+
if (!item?.value || item.value.type !== "JSONObjectExpression") {
|
|
16
|
+
node = void 0;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
node = item.value;
|
|
20
|
+
}
|
|
21
|
+
if (!node || node === root || !node.properties) continue;
|
|
22
|
+
for (const property of node.properties) {
|
|
23
|
+
if (property.value.type !== "JSONLiteral" || property.key.type !== "JSONLiteral") continue;
|
|
24
|
+
if (typeof property.value.value !== "string") continue;
|
|
25
|
+
yield {
|
|
26
|
+
packageName: String(property.key.value),
|
|
27
|
+
specifier: String(property.value.value),
|
|
28
|
+
property
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
48
32
|
}
|
|
49
33
|
function getObjectPath(obj, path) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return void 0;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return current;
|
|
34
|
+
let current = obj;
|
|
35
|
+
for (const key of path) {
|
|
36
|
+
if (!current || typeof current !== "object") return;
|
|
37
|
+
current = current[key];
|
|
38
|
+
if (!current) return;
|
|
39
|
+
}
|
|
40
|
+
return current;
|
|
61
41
|
}
|
|
62
|
-
|
|
42
|
+
//#endregion
|
|
63
43
|
export { getObjectPath, getPackageJsonRootNode, iterateDependencies };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { configs } from "./configs/index.mjs";
|
|
2
|
+
import { RuleModule } from "./helpers/create-rule.mjs";
|
|
3
|
+
import { plugin } from "./plugin.mjs";
|
|
4
|
+
import { ESLint, Linter } from "eslint";
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* ESLint plugin for Storm Software to enforce Bun catalog usage across monorepo packages.
|
|
8
|
+
*
|
|
9
|
+
* Catalog versions are stored in the workspace root `package.json` (`catalog` /
|
|
10
|
+
* `catalogs`, top-level or under `workspaces`), matching Bun's catalog protocol:
|
|
11
|
+
* https://bun.com/docs/pm/catalogs
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```js
|
|
17
|
+
* import bun from "@storm-software/eslint-plugin-bun";
|
|
18
|
+
*
|
|
19
|
+
* export default [
|
|
20
|
+
* ...bun.configs.recommended,
|
|
21
|
+
* ];
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @see [Storm Software](https://stormsoftware.com) for more information about our projects and licensing.
|
|
25
|
+
*/
|
|
26
|
+
declare const eslintPlugin: ESLint.Plugin;
|
|
27
|
+
declare const rules: {
|
|
28
|
+
"json-enforce-catalog": RuleModule<[{
|
|
29
|
+
allowedProtocols?: string[];
|
|
30
|
+
autofix?: boolean;
|
|
31
|
+
defaultCatalog?: string;
|
|
32
|
+
reuseExistingCatalog?: boolean;
|
|
33
|
+
conflicts?: "new-catalog" | "overrides" | "error";
|
|
34
|
+
fields?: string[];
|
|
35
|
+
ignore?: string[];
|
|
36
|
+
}]>;
|
|
37
|
+
"json-valid-catalog": RuleModule<[{
|
|
38
|
+
autoInsert?: boolean;
|
|
39
|
+
autoInsertDefaultSpecifier?: string;
|
|
40
|
+
autofix?: boolean;
|
|
41
|
+
fields?: string[];
|
|
42
|
+
}]>;
|
|
43
|
+
"json-no-unused-catalog-item": RuleModule<[]>;
|
|
44
|
+
"json-no-duplicate-catalog-item": RuleModule<[{
|
|
45
|
+
allow?: string[];
|
|
46
|
+
}]>;
|
|
47
|
+
};
|
|
48
|
+
type RuleDefinitions = (typeof plugin)["rules"];
|
|
49
|
+
type RuleOptions = { [K in keyof RuleDefinitions]: RuleDefinitions[K]["defaultOptions"]; };
|
|
50
|
+
type Rules = { [K in keyof RuleOptions]: Linter.RuleEntry<RuleOptions[K]>; };
|
|
51
|
+
//#endregion
|
|
52
|
+
export { RuleOptions, Rules, configs, eslintPlugin as default, rules };
|