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