@kirill.konshin/lint 0.5.5 → 0.6.1

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 (91) hide show
  1. package/README.md +38 -3
  2. package/commands/spec-author.md +39 -0
  3. package/dist/configs/base.d.ts +4 -3
  4. package/dist/configs/base.js +61 -74
  5. package/dist/configs/imports.d.ts +3 -2
  6. package/dist/configs/imports.js +95 -146
  7. package/dist/configs/nx.d.ts +4 -3
  8. package/dist/configs/nx.js +31 -41
  9. package/dist/configs/prettier.d.ts +3 -2
  10. package/dist/configs/prettier.js +19 -16
  11. package/dist/configs/promise.d.ts +3 -2
  12. package/dist/configs/promise.js +16 -16
  13. package/dist/configs/react.d.ts +4 -3
  14. package/dist/configs/react.js +178 -217
  15. package/dist/configs/storybook.d.ts +4 -3
  16. package/dist/configs/storybook.js +22 -22
  17. package/dist/configs/tailwind.d.ts +4 -3
  18. package/dist/configs/tailwind.js +67 -91
  19. package/dist/configs/testing.d.ts +7 -6
  20. package/dist/configs/testing.js +112 -146
  21. package/dist/configs/turbo.d.ts +4 -3
  22. package/dist/configs/turbo.js +19 -27
  23. package/dist/configs/typescriptTypeAware.d.ts +4 -3
  24. package/dist/configs/typescriptTypeAware.js +99 -95
  25. package/dist/configs/unicorn.d.ts +3 -2
  26. package/dist/configs/unicorn.js +34 -41
  27. package/dist/exts.d.ts +2 -1
  28. package/dist/exts.js +10 -11
  29. package/dist/index.d.ts +44 -42
  30. package/dist/index.js +53 -85
  31. package/dist/lib.d.ts +21 -21
  32. package/dist/lib.js +262 -301
  33. package/dist/lintPrepare.d.ts +20 -17
  34. package/dist/lintPrepare.js +341 -371
  35. package/dist/lintStaged.d.ts +4 -3
  36. package/dist/lintStaged.js +25 -22
  37. package/dist/prettier.d.ts +4 -3
  38. package/dist/prettier.js +16 -17
  39. package/dist/restrictions.d.ts +11 -10
  40. package/dist/restrictions.js +18 -22
  41. package/dist/yarn.cjs +79 -98
  42. package/dist/yarn.d.cts +3 -2
  43. package/package.json +22 -8
  44. package/rules/agent.md +2 -0
  45. package/rules/openspec.md +1 -1
  46. package/skills/spec-steward/SKILL.md +4 -12
  47. package/skills/spec-steward/references/audit.md +18 -43
  48. package/skills/spec-steward/references/contract.md +9 -9
  49. package/skills/spec-steward/references/criteria.md +4 -4
  50. package/skills/spec-steward/references/review-format.md +6 -6
  51. package/skills/spec-steward/references/wiring.md +2 -2
  52. package/skills/spec-steward/references/worker.md +67 -0
  53. package/skills/spec-steward/sweeps.json +49 -0
  54. package/skills/spec-tools/SKILL.md +48 -0
  55. package/skills/spec-tools/references/contract.md +111 -0
  56. package/skills/spec-tools/references/gitlab.md +120 -0
  57. package/skills/spec-tools/scripts/cli.js +8129 -0
  58. package/skills/spec-verify/SKILL.md +153 -0
  59. package/dist/configs/base.d.ts.map +0 -1
  60. package/dist/configs/imports.d.ts.map +0 -1
  61. package/dist/configs/nx.d.ts.map +0 -1
  62. package/dist/configs/prettier.d.ts.map +0 -1
  63. package/dist/configs/promise.d.ts.map +0 -1
  64. package/dist/configs/react.d.ts.map +0 -1
  65. package/dist/configs/storybook.d.ts.map +0 -1
  66. package/dist/configs/tailwind.d.ts.map +0 -1
  67. package/dist/configs/testing.d.ts.map +0 -1
  68. package/dist/configs/turbo.d.ts.map +0 -1
  69. package/dist/configs/typescriptTypeAware.d.ts.map +0 -1
  70. package/dist/configs/unicorn.d.ts.map +0 -1
  71. package/dist/exts.d.ts.map +0 -1
  72. package/dist/index.d.ts.map +0 -1
  73. package/dist/lib.d.ts.map +0 -1
  74. package/dist/lintPrepare.d.ts.map +0 -1
  75. package/dist/lintStaged.d.ts.map +0 -1
  76. package/dist/prettier.d.ts.map +0 -1
  77. package/dist/restrictions.d.ts.map +0 -1
  78. package/dist/yarn.d.cts.map +0 -1
  79. package/skills/spec-steward/scripts/lib/align.mjs +0 -127
  80. package/skills/spec-steward/scripts/lib/checks.mjs +0 -589
  81. package/skills/spec-steward/scripts/lib/citations.mjs +0 -156
  82. package/skills/spec-steward/scripts/lib/corpus.mjs +0 -256
  83. package/skills/spec-steward/scripts/lib/coverage.mjs +0 -123
  84. package/skills/spec-steward/scripts/lib/evidence.mjs +0 -334
  85. package/skills/spec-steward/scripts/lib/git.mjs +0 -138
  86. package/skills/spec-steward/scripts/lib/review.mjs +0 -347
  87. package/skills/spec-steward/scripts/lib/scan.mjs +0 -364
  88. package/skills/spec-steward/scripts/lib/util.mjs +0 -161
  89. package/skills/spec-steward/scripts/lib/wire.mjs +0 -331
  90. package/skills/spec-steward/scripts/steward.mjs +0 -350
  91. package/skills/spec-steward/workflows/audit.js +0 -539
package/dist/lib.js CHANGED
@@ -1,329 +1,290 @@
1
- import { existsSync } from 'node:fs';
2
- import { dirname, isAbsolute, relative, resolve } from 'node:path';
3
- import { includeIgnoreFile } from '@eslint/config-helpers';
4
- import { findRootSync } from '@manypkg/find-root';
5
- import { getPackagesSync } from '@manypkg/get-packages';
6
- import { globSync } from 'glob';
7
- import { isPackageExists } from 'local-pkg';
8
- import { PathScurry } from 'path-scurry';
9
- //TODO coverage, dist, out, build?
10
- export const GLOBAL_IGNORES = [
11
- '**/next-env.d.ts',
12
- '**/viteEnv.d.ts',
13
- '**/node_modules',
14
- '**/.cache',
15
- '**/.nx',
16
- '**/.turbo',
17
- '**/.yarn',
1
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
2
+ import { includeIgnoreFile } from "@eslint/config-helpers";
3
+ import { existsSync } from "node:fs";
4
+ import { findRootSync } from "@manypkg/find-root";
5
+ import { getPackagesSync } from "@manypkg/get-packages";
6
+ import { globSync } from "glob";
7
+ import { isPackageExists } from "local-pkg";
8
+ import { PathScurry } from "path-scurry";
9
+ //#region src/lib.ts
10
+ const GLOBAL_IGNORES = [
11
+ "**/next-env.d.ts",
12
+ "**/viteEnv.d.ts",
13
+ "**/node_modules",
14
+ "**/.cache",
15
+ "**/.nx",
16
+ "**/.turbo",
17
+ "**/.yarn",
18
+ "**/skills/spec-tools/scripts/cli.js"
18
19
  ];
19
20
  const LINT_DEBUG = Boolean(process.env.LINT_DEBUG);
20
21
  /**
21
- * Structured debug logging, gated by the `LINT_DEBUG` env var (any non-empty value). Traces the
22
- * detection machinery: capability probes, workspace scans and per-tool gate verdicts.
23
- */
22
+ * Structured debug logging, gated by the `LINT_DEBUG` env var (any non-empty value). Traces the
23
+ * detection machinery: capability probes, workspace scans and per-tool gate verdicts.
24
+ */
24
25
  function debug(message, ...args) {
25
- if (!LINT_DEBUG)
26
- return;
27
- console.log(`[@kirill.konshin/lint] ${message}`, ...args);
26
+ if (!LINT_DEBUG) return;
27
+ console.log(`[@kirill.konshin/lint] ${message}`, ...args);
28
28
  }
29
29
  /**
30
- * Capability gate: is a package resolvable from the workspace root - the scope the ESLint plugins
31
- * themselves resolve from at lint time?
32
- */
33
- export function isPackageResolvable(packageName) {
34
- return isPackageExists(packageName, { paths: [findWorkspaceRoot()] });
30
+ * Capability gate: is a package resolvable from the workspace root - the scope the ESLint plugins
31
+ * themselves resolve from at lint time?
32
+ */
33
+ function isPackageResolvable(packageName) {
34
+ return isPackageExists(packageName, { paths: [findWorkspaceRoot()] });
35
35
  }
36
36
  /**
37
- * An env-supplied root candidate is only plausible when it is an absolute existing directory that
38
- * contains (or is) `cwd` - guards against stale env leaking in from an unrelated checkout.
39
- */
37
+ * An env-supplied root candidate is only plausible when it is an absolute existing directory that
38
+ * contains (or is) `cwd` - guards against stale env leaking in from an unrelated checkout.
39
+ */
40
40
  function isRootOf(root, cwd) {
41
- if (!root || !isAbsolute(root) || !existsSync(root))
42
- return false;
43
- const rel = relative(root, cwd);
44
- return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
41
+ if (!root || !isAbsolute(root) || !existsSync(root)) return false;
42
+ const rel = relative(root, cwd);
43
+ return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
45
44
  }
46
- const workspaceRoots = new Map();
45
+ const workspaceRoots = /* @__PURE__ */ new Map();
47
46
  /**
48
- * Workspace root of the consumer project - the anchor for every config-file scan (Tailwind entry,
49
- * `next.config.*`) and root-file detection (`nx.json`): `process.cwd()` alone is unreliable
50
- * because lint often runs from INSIDE a package (lint-staged, IDE, `yarn workspace x lint`) while
51
- * the shared config must see the whole repo.
52
- *
53
- * Resolution order, cheapest first - an env candidate must contain `cwd` or it is rejected:
54
- * 1. env the package manager sets for its child processes: `PROJECT_CWD` (Yarn Berry),
55
- * `npm_config_local_prefix` (npm >= 7, workspace-aware) - free, no fs walk at all
56
- * 2. `@manypkg/find-root`: walks up to the nearest workspace manifest (package.json `workspaces`,
57
- * pnpm-workspace.yaml, lerna.json, rush.json, bun), falling back to the nearest `package.json`
58
- * for single-package repos - covers every manager, incl. the env-less ones (pnpm, Yarn 1)
59
- *
60
- * Cached per `cwd` - the config is rebuilt on every lint run.
61
- *
62
- * Returns an absolute path, or `cwd` itself when there is no package.json anywhere above.
63
- */
64
- export function findWorkspaceRoot(cwd = process.cwd()) {
65
- const cached = workspaceRoots.get(cwd);
66
- if (cached)
67
- return cached;
68
- let root = [process.env.PROJECT_CWD, process.env.npm_config_local_prefix].find((dir) => isRootOf(dir, cwd));
69
- if (root) {
70
- root = resolve(root);
71
- }
72
- else {
73
- try {
74
- root = findRootSync(cwd).rootDir;
75
- }
76
- catch {
77
- root = cwd; // no package.json anywhere above - degenerate sandbox, scans just see less
78
- }
79
- }
80
- workspaceRoots.set(cwd, root);
81
- return root;
47
+ * Workspace root of the consumer project - the anchor for every config-file scan (Tailwind entry,
48
+ * `next.config.*`) and root-file detection (`nx.json`): `process.cwd()` alone is unreliable
49
+ * because lint often runs from INSIDE a package (lint-staged, IDE, `yarn workspace x lint`) while
50
+ * the shared config must see the whole repo.
51
+ *
52
+ * Resolution order, cheapest first - an env candidate must contain `cwd` or it is rejected:
53
+ * 1. env the package manager sets for its child processes: `PROJECT_CWD` (Yarn Berry),
54
+ * `npm_config_local_prefix` (npm >= 7, workspace-aware) - free, no fs walk at all
55
+ * 2. `@manypkg/find-root`: walks up to the nearest workspace manifest (package.json `workspaces`,
56
+ * pnpm-workspace.yaml, lerna.json, rush.json, bun), falling back to the nearest `package.json`
57
+ * for single-package repos - covers every manager, incl. the env-less ones (pnpm, Yarn 1)
58
+ *
59
+ * Cached per `cwd` - the config is rebuilt on every lint run.
60
+ *
61
+ * Returns an absolute path, or `cwd` itself when there is no package.json anywhere above.
62
+ */
63
+ function findWorkspaceRoot(cwd = process.cwd()) {
64
+ const cached = workspaceRoots.get(cwd);
65
+ if (cached) return cached;
66
+ let root = [process.env.PROJECT_CWD, process.env.npm_config_local_prefix].find((dir) => isRootOf(dir, cwd));
67
+ if (root) root = resolve(root);
68
+ else try {
69
+ root = findRootSync(cwd).rootDir;
70
+ } catch {
71
+ root = cwd;
72
+ }
73
+ workspaceRoots.set(cwd, root);
74
+ return root;
82
75
  }
83
- const workspacePackageDirs = new Map();
76
+ const workspacePackageDirs = /* @__PURE__ */ new Map();
84
77
  /**
85
- * Absolute directories of all workspace packages - the real `workspaces` / `pnpm-workspace.yaml`
86
- * globs expanded by `@manypkg/get-packages`, NOT a scan heuristic. Single-package repos yield the
87
- * root itself; no package.json at all yields an empty list (degenerate sandboxes, tests).
88
- */
78
+ * Absolute directories of all workspace packages - the real `workspaces` / `pnpm-workspace.yaml`
79
+ * globs expanded by `@manypkg/get-packages`, NOT a scan heuristic. Single-package repos yield the
80
+ * root itself; no package.json at all yields an empty list (degenerate sandboxes, tests).
81
+ */
89
82
  function findWorkspacePackages() {
90
- const root = findWorkspaceRoot();
91
- const cached = workspacePackageDirs.get(root);
92
- if (cached)
93
- return cached;
94
- let dirs = [];
95
- try {
96
- dirs = getPackagesSync(root).packages.map((pkg) => pkg.dir);
97
- }
98
- catch {
99
- // no package.json at the root - only the root scan applies
100
- }
101
- workspacePackageDirs.set(root, dirs);
102
- return dirs;
83
+ const root = findWorkspaceRoot();
84
+ const cached = workspacePackageDirs.get(root);
85
+ if (cached) return cached;
86
+ let dirs = [];
87
+ try {
88
+ dirs = getPackagesSync(root).packages.map((pkg) => pkg.dir);
89
+ } catch {}
90
+ workspacePackageDirs.set(root, dirs);
91
+ return dirs;
103
92
  }
104
93
  /**
105
- * The workspace package owning `file` (e.g. the Tailwind entry CSS) - matched against the real
106
- * workspace package dirs (see {@link findWorkspacePackages}), NOT by walking to the nearest
107
- * package.json: a directory that is not a declared workspace member belongs to the root. Returns
108
- * the workspace root when no package contains `file`.
109
- *
110
- */
111
- export function packageDirOf(file) {
112
- const root = findWorkspaceRoot();
113
- return (findWorkspacePackages()
114
- .filter((dir) => dir !== root)
115
- .sort((a, b) => b.length - a.length) // nested packages: the deepest match wins
116
- .find((dir) => {
117
- const rel = relative(dir, file);
118
- return !rel.startsWith('..') && !isAbsolute(rel);
119
- }) ?? root);
94
+ * The workspace package owning `file` (e.g. the Tailwind entry CSS) - matched against the real
95
+ * workspace package dirs (see {@link findWorkspacePackages}), NOT by walking to the nearest
96
+ * package.json: a directory that is not a declared workspace member belongs to the root. Returns
97
+ * the workspace root when no package contains `file`.
98
+ *
99
+ */
100
+ function packageDirOf(file) {
101
+ const root = findWorkspaceRoot();
102
+ return findWorkspacePackages().filter((dir) => dir !== root).sort((a, b) => b.length - a.length).find((dir) => {
103
+ const rel = relative(dir, file);
104
+ return !rel.startsWith("..") && !isAbsolute(rel);
105
+ }) ?? root;
120
106
  }
121
- /*
122
- * Build outputs regularly contain COPIES of the scanned files (compiled css, a next.config.js in a
123
- * published dist) and would poison the scans even in repos that don't gitignore them. Scan-only -
124
- * GLOBAL_IGNORES stays the deliberate lint-wide list. `.git` matters for `dot: true` scans;
125
- * `node_modules` because the scans are depth-unbounded within a package.
126
- */
127
107
  const SCAN_IGNORES = [
128
- '**/node_modules',
129
- '**/dist',
130
- '**/build',
131
- '**/out',
132
- '**/coverage',
133
- '**/.next',
134
- '**/.expo',
135
- '**/storybook-static',
136
- '**/.git',
108
+ "**/node_modules",
109
+ "**/dist",
110
+ "**/build",
111
+ "**/out",
112
+ "**/coverage",
113
+ "**/.next",
114
+ "**/.expo",
115
+ "**/storybook-static",
116
+ "**/.git"
137
117
  ];
138
- const scurries = new Map();
118
+ const scurries = /* @__PURE__ */ new Map();
139
119
  /**
140
- * Filesystem cache of a scanned directory, shared by every {@link scanWorkspace} call: the detection scans all walk
141
- * the same trees, so each directory is read once instead of once per scan. Cached per process, like the workspace
142
- * root and packages.
143
- */
120
+ * Filesystem cache of a scanned directory, shared by every {@link scanWorkspace} call: the detection scans all walk
121
+ * the same trees, so each directory is read once instead of once per scan. Cached per process, like the workspace
122
+ * root and packages.
123
+ */
144
124
  function scurryOf(dir) {
145
- const cached = scurries.get(dir);
146
- if (cached)
147
- return cached;
148
- const scurry = new PathScurry(dir);
149
- scurries.set(dir, scurry);
150
- return scurry;
125
+ const cached = scurries.get(dir);
126
+ if (cached) return cached;
127
+ const scurry = new PathScurry(dir);
128
+ scurries.set(dir, scurry);
129
+ return scurry;
151
130
  }
152
131
  /**
153
- * Glob for config-file candidates across the workspace: the root directory plus every workspace
154
- * package (the real `workspaces` globs via {@link findWorkspacePackages}, not a depth heuristic),
155
- * skipping dot dirs, build outputs, the given ignore patterns and everything in the root
156
- * `.gitignore`. Anchored to {@link findWorkspaceRoot}, NOT cwd.
157
- *
158
- * Public - useful for building consumer file lists (e.g. `typeAware.allowDefaultProject`, see README "Type-aware rules").
159
- *
160
- * `dot` also scans dot directories such as `.storybook`.
161
- */
162
- export function scanWorkspace(fileGlob, ignores = [], { dot = false } = {}) {
163
- const root = findWorkspaceRoot();
164
- const packages = findWorkspacePackages().filter((dir) => dir !== root);
165
- let gitignored = [];
166
- try {
167
- // Reuse ESLint's gitignore->minimatch conversion; glob's `ignore` speaks the same language.
168
- // Negations dropped: glob's ignore cannot un-ignore.
169
- gitignored = (includeIgnoreFile(resolve(root, '.gitignore')).ignores ?? []).filter((pattern) => !pattern.startsWith('!'));
170
- }
171
- catch {
172
- // no .gitignore - the scan is just less filtered
173
- }
174
- // `<dir-pattern>/**` variants prune the CONTENTS of ignored directories, not just the dir itself
175
- const ignore = [...ignores, ...SCAN_IGNORES, ...gitignored].flatMap((pattern) => [
176
- pattern,
177
- pattern.endsWith('/') ? `${pattern}**` : `${pattern}/**`,
178
- ]);
179
- // package dirs are scanned individually - keep the root scan from descending into them twice
180
- const rootIgnore = [
181
- ...ignore,
182
- ...packages.flatMap((dir) => {
183
- const rel = relative(root, dir).replaceAll('\\', '/');
184
- return [rel, `${rel}/**`];
185
- }),
186
- ];
187
- const files = [
188
- ...globSync(`**/${fileGlob}`, { cwd: root, scurry: scurryOf(root), ignore: rootIgnore, absolute: true, dot }),
189
- ...packages.flatMap((dir) => globSync(`**/${fileGlob}`, { cwd: dir, scurry: scurryOf(dir), ignore, absolute: true, dot })),
190
- ];
191
- // debug('scanWorkspace', { fileGlob, root, packages, dot, ignores, files });
192
- return files;
132
+ * Glob for config-file candidates across the workspace: the root directory plus every workspace
133
+ * package (the real `workspaces` globs via {@link findWorkspacePackages}, not a depth heuristic),
134
+ * skipping dot dirs, build outputs, the given ignore patterns and everything in the root
135
+ * `.gitignore`. Anchored to {@link findWorkspaceRoot}, NOT cwd.
136
+ *
137
+ * Public - useful for building consumer file lists (e.g. `typeAware.allowDefaultProject`, see README "Type-aware rules").
138
+ *
139
+ * `dot` also scans dot directories such as `.storybook`.
140
+ */
141
+ function scanWorkspace(fileGlob, ignores = [], { dot = false } = {}) {
142
+ const root = findWorkspaceRoot();
143
+ const packages = findWorkspacePackages().filter((dir) => dir !== root);
144
+ let gitignored = [];
145
+ try {
146
+ gitignored = (includeIgnoreFile(resolve(root, ".gitignore")).ignores ?? []).filter((pattern) => !pattern.startsWith("!"));
147
+ } catch {}
148
+ const ignore = [
149
+ ...ignores,
150
+ ...SCAN_IGNORES,
151
+ ...gitignored
152
+ ].flatMap((pattern) => [pattern, pattern.endsWith("/") ? `${pattern}**` : `${pattern}/**`]);
153
+ const rootIgnore = [...ignore, ...packages.flatMap((dir) => {
154
+ const rel = relative(root, dir).replaceAll("\\", "/");
155
+ return [rel, `${rel}/**`];
156
+ })];
157
+ return [...globSync(`**/${fileGlob}`, {
158
+ cwd: root,
159
+ scurry: scurryOf(root),
160
+ ignore: rootIgnore,
161
+ absolute: true,
162
+ dot
163
+ }), ...packages.flatMap((dir) => globSync(`**/${fileGlob}`, {
164
+ cwd: dir,
165
+ scurry: scurryOf(dir),
166
+ ignore,
167
+ absolute: true,
168
+ dot
169
+ }))];
193
170
  }
194
- /*
195
- * Capability detection, exported for debugging. Package probes resolve from the WORKSPACE ROOT -
196
- * the same scope the plugins' own resolution sees at lint time (eslint-plugin-tailwindcss's
197
- * workers, eslint-config-next's internal `require`s, eslint-plugin-storybook's static import,
198
- * eslint-plugin-jest's version sniffing). A tool hoisted to the root (default npm/yarn behavior)
199
- * is visible; a leaf-only install is not - `toolGate` then fails with hoisting guidance instead of
200
- * a cryptic plugin crash. `nx.json` is checked at the workspace root, not via cwd.
201
- */
202
- export const hasNext = isPackageResolvable('next');
203
- export const hasStorybook = isPackageResolvable('storybook');
204
- export const hasVite = isPackageResolvable('vite');
205
- export const hasJest = isPackageResolvable('jest');
206
- export const hasVitest = isPackageResolvable('vitest');
207
- export const hasTurbo = isPackageResolvable('turbo');
208
- export const hasNx = existsSync(resolve(findWorkspaceRoot(), 'nx.json'));
209
- export const hasTailwind = isPackageResolvable('tailwindcss');
210
- debug('capability probes', { hasNext, hasStorybook, hasVite, hasJest, hasVitest, hasTurbo, hasNx, hasTailwind });
171
+ const hasNext = isPackageResolvable("next");
172
+ const hasStorybook = isPackageResolvable("storybook");
173
+ const hasVite = isPackageResolvable("vite");
174
+ const hasJest = isPackageResolvable("jest");
175
+ const hasVitest = isPackageResolvable("vitest");
176
+ const hasTurbo = isPackageResolvable("turbo");
177
+ const hasNx = existsSync(resolve(findWorkspaceRoot(), "nx.json"));
178
+ const hasTailwind = isPackageResolvable("tailwindcss");
179
+ debug("capability probes", {
180
+ hasNext,
181
+ hasStorybook,
182
+ hasVite,
183
+ hasJest,
184
+ hasVitest,
185
+ hasTurbo,
186
+ hasNx,
187
+ hasTailwind
188
+ });
211
189
  /**
212
- * Normalize a defineLintConfig flag into its options object with a canonical `enabled`:
213
- * - `true` / `false` → `{ enabled: true | false }`
214
- * - an options object counts as enabled unless it explicitly says otherwise - `enabled` defaults
215
- * to `true`, so providing options (even `{}`) implies turning the tool on
216
- * - `undefined` (flag not passed) → `{}` - `enabled` stays undefined and the caller falls back to
217
- * detection: `const { enabled = hasX, ...options } = asOptions(option)`
218
- *
219
- */
220
- export function asOptions(option) {
221
- if (typeof option === 'boolean')
222
- return { enabled: option };
223
- if (typeof option === 'object' && option !== null) {
224
- return { enabled: true, ...option };
225
- }
226
- return {};
190
+ * Normalize a defineLintConfig flag into its options object with a canonical `enabled`:
191
+ * - `true` / `false` → `{ enabled: true | false }`
192
+ * - an options object counts as enabled unless it explicitly says otherwise - `enabled` defaults
193
+ * to `true`, so providing options (even `{}`) implies turning the tool on
194
+ * - `undefined` (flag not passed) → `{}` - `enabled` stays undefined and the caller falls back to
195
+ * detection: `const { enabled = hasX, ...options } = asOptions(option)`
196
+ *
197
+ */
198
+ function asOptions(option) {
199
+ if (typeof option === "boolean") return { enabled: option };
200
+ if (typeof option === "object" && option !== null) return {
201
+ enabled: true,
202
+ ...option
203
+ };
204
+ return {};
227
205
  }
228
206
  /**
229
- * Shared activation gate of the tool-scoped config blocks (next, storybook, turbo, nx, jest,
230
- * vitest, tailwind) - the one decision every block repeats: is the tool ON, and can its plugin
231
- * actually run. The `configs/*.ts` functions keep only their tool-specific parts (which blocks to
232
- * emit, how the evidence feeds settings) and differ solely in the spec they pass here.
233
- *
234
- * Decision flow:
235
- * - `enabled: false` → off, always.
236
- * - strict (defineLintConfig `detection.strict`): the same-scope probe gates (`strictHas`,
237
- * defaulting to `has`); `scan` never runs, but `absolutizeOptions` evidence still counts. A tool
238
- * that is ON while its package is unresolvable (`requirePackage`) or its mandatory evidence is
239
- * missing (`needs`) throws instead of producing a config that crashes at lint time.
240
- * - non-strict: evidence-based detection - `absolutizeOptions(options)` wins over the `scan()`
241
- * auto-discovery; the tool is detected when the package probe hits or evidence exists (`needs`
242
- * makes evidence mandatory even when the probe hits). A tool that is ON while `packageName` is
243
- * unresolvable from the workspace root throws an actionable HOISTING error (no silent skip, no
244
- * symlink bridging - the plugins resolve from the root scope, so only hoisting actually fixes
245
- * them; the user or their AI agent picks it up from the error).
246
- *
247
- */
248
- export function toolGate(option, strict, spec) {
249
- const { enabled, ...rawOptions } = asOptions(option);
250
- const options = rawOptions;
251
- let absolutized = [];
252
- let scanned = [];
253
- // every return path funnels through here so the effective verdict is always traceable
254
- const trace = (result, reason) => {
255
- debug(`toolGate \`${spec.tool}\` %o`, {
256
- strict,
257
- has: spec.has,
258
- enabled: result.enabled,
259
- reason,
260
- }, {
261
- supplied: option,
262
- absolutized,
263
- scanned,
264
- });
265
- return result;
266
- };
267
- const off = { enabled: false, options, files: [] };
268
- if (enabled === false)
269
- return trace(off, 'disabled explicitly');
270
- const { tool, has, strictHas = has, packageName, requirePackage = Boolean(packageName), absolutizeOptions, scan, allowMultiple = true, needs, } = spec;
271
- const prefix = `[@kirill.konshin/lint] \`${tool}\``;
272
- /*
273
- * Several candidates with allowMultiple off are a hard error even in auto mode: the evidence
274
- * proves the tool IS in use, the right candidate is unknowable, and silently skipping a tool
275
- * that is evidently present would be hard to detect.
276
- */
277
- const usable = (candidates) => {
278
- if (!allowMultiple && candidates.length > 1) {
279
- const fix = needs ? `pass ${needs.hint} to pick one, or set` : `set`;
280
- throw new Error(`${prefix} found several ${needs?.what ?? 'evidence'} candidates and cannot pick one - ` +
281
- `${fix} \`${tool}: false\`:\n${candidates.map((file) => ` - ${file}`).join('\n')}`);
282
- }
283
- return candidates;
284
- };
285
- if (strict) {
286
- if (!(enabled ?? strictHas))
287
- return trace(off, 'strict probe negative');
288
- if (requirePackage && !has) {
289
- throw new Error(`${prefix} is on under strict detection, but the \`${packageName}\` package is not ` +
290
- `resolvable at this scope - install it here or set \`${tool}: false\`.`);
291
- }
292
- absolutized = absolutizeOptions?.(options) ?? [];
293
- const files = usable(absolutized);
294
- if (needs && files.length === 0) {
295
- throw new Error(`${prefix} is on under strict detection, which cannot scan for the ${needs.what} - ` +
296
- `pass ${needs.hint} or set \`${tool}: false\`.`);
297
- }
298
- return trace({ enabled: true, options, files }, enabled ? 'strict, forced on' : 'strict probe positive');
299
- }
300
- absolutized = absolutizeOptions?.(options) ?? [];
301
- scanned = absolutized.length > 0 ? [] : (scan?.() ?? []);
302
- const files = usable(absolutized.length > 0 ? absolutized : scanned);
303
- if (needs && files.length === 0) {
304
- // `enabled` is only defined when the consumer explicitly turned the tool on - fail loudly
305
- // then; detection-driven activation (enabled === undefined) stays inert instead.
306
- if (enabled) {
307
- throw new Error(`${prefix} was enabled explicitly, but no ${needs.detail} was found - zero or several ` +
308
- `candidates. Pass ${needs.hint} explicitly.`);
309
- }
310
- return trace(off, `no ${needs.what} found`);
311
- }
312
- if (!(enabled ?? (has || files.length > 0)))
313
- return trace(off, 'not detected');
314
- /*
315
- * The tool is ON but its package is invisible at the workspace root - the scope the plugins
316
- * resolve from at lint time. No silent skip and no symlink bridging: fail with the fix
317
- * (hoisting) and let the user or their AI agent pick it up from here.
318
- */
319
- if (requirePackage && packageName && !has) {
320
- const leaf = files.map((file) => dirname(file)).find((dir) => isPackageExists(packageName, { paths: [dir] }));
321
- throw new Error(`${prefix} is in use, but the \`${packageName}\` package is not resolvable from the workspace root` +
322
- (leaf ? ` (it is installed near \`${leaf}\`)` : '') +
323
- ` - hoist it: keep the package manager's default hoisting (no \`installConfig.hoistingLimits\` / ` +
324
- `\`nohoist\`), on pnpm add \`public-hoist-pattern[]=${packageName}\` to .npmrc, or add ` +
325
- `\`${packageName}\` to the root devDependencies. Set \`${tool}: false\` to turn the tool off. ` +
326
- `Run eslint with LINT_DEBUG=1 to trace detection.`);
327
- }
328
- return trace({ enabled: true, options, files }, enabled ? 'forced on' : 'detected');
207
+ * Shared activation gate of the tool-scoped config blocks (next, storybook, turbo, nx, jest,
208
+ * vitest, tailwind) - the one decision every block repeats: is the tool ON, and can its plugin
209
+ * actually run. The `configs/*.ts` functions keep only their tool-specific parts (which blocks to
210
+ * emit, how the evidence feeds settings) and differ solely in the spec they pass here.
211
+ *
212
+ * Decision flow:
213
+ * - `enabled: false` → off, always.
214
+ * - strict (defineLintConfig `detection.strict`): the same-scope probe gates (`strictHas`,
215
+ * defaulting to `has`); `scan` never runs, but `absolutizeOptions` evidence still counts. A tool
216
+ * that is ON while its package is unresolvable (`requirePackage`) or its mandatory evidence is
217
+ * missing (`needs`) throws instead of producing a config that crashes at lint time.
218
+ * - non-strict: evidence-based detection - `absolutizeOptions(options)` wins over the `scan()`
219
+ * auto-discovery; the tool is detected when the package probe hits or evidence exists (`needs`
220
+ * makes evidence mandatory even when the probe hits). A tool that is ON while `packageName` is
221
+ * unresolvable from the workspace root throws an actionable HOISTING error (no silent skip, no
222
+ * symlink bridging - the plugins resolve from the root scope, so only hoisting actually fixes
223
+ * them; the user or their AI agent picks it up from the error).
224
+ *
225
+ */
226
+ function toolGate(option, strict, spec) {
227
+ const { enabled, ...rawOptions } = asOptions(option);
228
+ const options = rawOptions;
229
+ let absolutized = [];
230
+ let scanned = [];
231
+ const trace = (result, reason) => {
232
+ debug(`toolGate \`${spec.tool}\` %o`, {
233
+ strict,
234
+ has: spec.has,
235
+ enabled: result.enabled,
236
+ reason
237
+ }, {
238
+ supplied: option,
239
+ absolutized,
240
+ scanned
241
+ });
242
+ return result;
243
+ };
244
+ const off = {
245
+ enabled: false,
246
+ options,
247
+ files: []
248
+ };
249
+ if (enabled === false) return trace(off, "disabled explicitly");
250
+ const { tool, has, strictHas = has, packageName, requirePackage = Boolean(packageName), absolutizeOptions, scan, allowMultiple = true, needs } = spec;
251
+ const prefix = `[@kirill.konshin/lint] \`${tool}\``;
252
+ const usable = (candidates) => {
253
+ if (!allowMultiple && candidates.length > 1) {
254
+ const fix = needs ? `pass ${needs.hint} to pick one, or set` : `set`;
255
+ throw new Error(`${prefix} found several ${needs?.what ?? "evidence"} candidates and cannot pick one - ${fix} \`${tool}: false\`:\n${candidates.map((file) => ` - ${file}`).join("\n")}`);
256
+ }
257
+ return candidates;
258
+ };
259
+ if (strict) {
260
+ if (!(enabled ?? strictHas)) return trace(off, "strict probe negative");
261
+ if (requirePackage && !has) throw new Error(`${prefix} is on under strict detection, but the \`${packageName}\` package is not resolvable at this scope - install it here or set \`${tool}: false\`.`);
262
+ absolutized = absolutizeOptions?.(options) ?? [];
263
+ const files = usable(absolutized);
264
+ if (needs && files.length === 0) throw new Error(`${prefix} is on under strict detection, which cannot scan for the ${needs.what} - pass ${needs.hint} or set \`${tool}: false\`.`);
265
+ return trace({
266
+ enabled: true,
267
+ options,
268
+ files
269
+ }, enabled ? "strict, forced on" : "strict probe positive");
270
+ }
271
+ absolutized = absolutizeOptions?.(options) ?? [];
272
+ scanned = absolutized.length > 0 ? [] : scan?.() ?? [];
273
+ const files = usable(absolutized.length > 0 ? absolutized : scanned);
274
+ if (needs && files.length === 0) {
275
+ if (enabled) throw new Error(`${prefix} was enabled explicitly, but no ${needs.detail} was found - zero or several candidates. Pass ${needs.hint} explicitly.`);
276
+ return trace(off, `no ${needs.what} found`);
277
+ }
278
+ if (!(enabled ?? (has || files.length > 0))) return trace(off, "not detected");
279
+ if (requirePackage && packageName && !has) {
280
+ const leaf = files.map((file) => dirname(file)).find((dir) => isPackageExists(packageName, { paths: [dir] }));
281
+ throw new Error(`${prefix} is in use, but the \`${packageName}\` package is not resolvable from the workspace root` + (leaf ? ` (it is installed near \`${leaf}\`)` : "") + ` - hoist it: keep the package manager's default hoisting (no \`installConfig.hoistingLimits\` / \`nohoist\`), on pnpm add \`public-hoist-pattern[]=${packageName}\` to .npmrc, or add \`${packageName}\` to the root devDependencies. Set \`${tool}: false\` to turn the tool off. Run eslint with LINT_DEBUG=1 to trace detection.`);
282
+ }
283
+ return trace({
284
+ enabled: true,
285
+ options,
286
+ files
287
+ }, enabled ? "forced on" : "detected");
329
288
  }
289
+ //#endregion
290
+ export { GLOBAL_IGNORES, asOptions, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, isPackageResolvable, packageDirOf, scanWorkspace, toolGate };