@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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/dist/configs/index.d.mts +5 -0
  3. package/dist/configs/index.mjs +4 -943
  4. package/dist/configs/recommended.d.mts +5 -0
  5. package/dist/configs/recommended.mjs +33 -939
  6. package/dist/helpers/bun-workspace.d.mts +49 -0
  7. package/dist/helpers/bun-workspace.mjs +197 -244
  8. package/dist/helpers/{create-rule.d.ts → create-rule.d.mts} +6 -6
  9. package/dist/helpers/create-rule.mjs +37 -38
  10. package/dist/helpers/{iterate-dependencies.d.ts → iterate-dependencies.d.mts} +7 -7
  11. package/dist/helpers/iterate-dependencies.mjs +36 -56
  12. package/dist/index.d.mts +52 -0
  13. package/dist/index.mjs +29 -951
  14. package/dist/plugin-9WjNsG8_.mjs +20 -0
  15. package/dist/plugin.d.mts +31 -0
  16. package/dist/plugin.mjs +1 -807
  17. package/dist/rules/json-enforce-catalog.d.mts +14 -0
  18. package/dist/rules/json-enforce-catalog.mjs +102 -444
  19. package/dist/rules/json-no-duplicate-catalog-item.d.mts +8 -0
  20. package/dist/rules/json-no-duplicate-catalog-item.mjs +72 -386
  21. package/dist/rules/json-no-unused-catalog-item.d.mts +5 -0
  22. package/dist/rules/json-no-unused-catalog-item.mjs +70 -423
  23. package/dist/rules/json-valid-catalog.d.mts +11 -0
  24. package/dist/rules/json-valid-catalog.mjs +80 -422
  25. package/package.json +15 -22
  26. package/dist/configs/index.d.ts +0 -5
  27. package/dist/configs/recommended.d.ts +0 -5
  28. package/dist/helpers/bun-workspace.d.ts +0 -48
  29. package/dist/index.d.ts +0 -58
  30. package/dist/plugin.d.ts +0 -33
  31. package/dist/rules/json-enforce-catalog.d.ts +0 -18
  32. package/dist/rules/json-no-duplicate-catalog-item.d.ts +0 -12
  33. package/dist/rules/json-no-unused-catalog-item.d.ts +0 -7
  34. package/dist/rules/json-valid-catalog.d.ts +0 -15
@@ -1,63 +1,43 @@
1
- // src/helpers/iterate-dependencies.ts
1
+ //#region src/helpers/iterate-dependencies.ts
2
2
  function getPackageJsonRootNode(context) {
3
- if (!context.filename.endsWith("package.json")) {
4
- return void 0;
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
- const root = getPackageJsonRootNode(context);
15
- if (!root) {
16
- return;
17
- }
18
- for (const fieldName of fields) {
19
- const path = fieldName.split(".");
20
- let node = root;
21
- for (const segment of path) {
22
- const item = node.properties?.find(
23
- (property) => property.key.type === "JSONLiteral" && property.key.value === segment
24
- );
25
- if (!item?.value || item.value.type !== "JSONObjectExpression") {
26
- node = void 0;
27
- break;
28
- }
29
- node = item.value;
30
- }
31
- if (!node || node === root || !node.properties) {
32
- continue;
33
- }
34
- for (const property of node.properties) {
35
- if (property.value.type !== "JSONLiteral" || property.key.type !== "JSONLiteral") {
36
- continue;
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
- let current = obj;
51
- for (const key of path) {
52
- if (!current || typeof current !== "object") {
53
- return void 0;
54
- }
55
- current = current[key];
56
- if (!current) {
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 };
@@ -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 };