@rdjperron/lint 0.1.0 → 0.3.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 +147 -57
- package/dist/config.d.mts +122 -0
- package/dist/config.mjs +218 -0
- package/dist/config.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/{anti-slop.mjs → index.mjs} +290 -97
- package/dist/index.mjs.map +1 -0
- package/dist/verify.d.mts +92 -0
- package/dist/verify.mjs +400 -0
- package/dist/verify.mjs.map +1 -0
- package/fixtures/README.md +22 -23
- package/fixtures/{anti-slop/no-array-filter-map.fixture.ts → no-array-filter-map.fixture.ts} +1 -1
- package/fixtures/{anti-slop/no-chained-type-assertions.fixture.ts → no-chained-type-assertions.fixture.ts} +1 -1
- package/fixtures/{anti-slop/no-conditional-empty-object-spread.fixture.ts → no-conditional-empty-object-spread.fixture.ts} +1 -1
- package/fixtures/{i18n/no-hardcoded-jsx-text.fixture.tsx → no-hardcoded-jsx-text.fixture.tsx} +1 -1
- package/fixtures/{anti-slop/no-known-value-widening.fixture.ts → no-known-value-widening.fixture.ts} +1 -1
- package/fixtures/{anti-slop/no-module-mocking.fixture.ts → no-module-mocking.fixture.ts} +1 -1
- package/fixtures/{anti-slop/no-object-parameters.fixture.ts → no-object-parameters.fixture.ts} +1 -1
- package/fixtures/{anti-slop/no-reduce-accumulator-copy.fixture.ts → no-reduce-accumulator-copy.fixture.ts} +1 -1
- package/fixtures/{anti-slop/no-reflect-apply.fixture.ts → no-reflect-apply.fixture.ts} +1 -1
- package/fixtures/{anti-slop/no-reflect-get.fixture.ts → no-reflect-get.fixture.ts} +1 -1
- package/fixtures/{anti-slop/no-runtime-typeof.fixture.ts → no-runtime-typeof.fixture.ts} +1 -1
- package/fixtures/no-shape-in-symbol-names.fixture.ts +2 -0
- package/fixtures/{anti-slop/no-unknown-parameters.fixture.ts → no-unknown-parameters.fixture.ts} +1 -1
- package/fixtures/{anti-slop/no-unknown-returns.fixture.ts → no-unknown-returns.fixture.ts} +1 -1
- package/fixtures/no-unknown-type-aliases.fixture.ts +2 -0
- package/fixtures/no-unsafe-dictionary-type.fixture.ts +2 -0
- package/fixtures/{react/no-use-effect.fixture.tsx → no-use-effect.fixture.tsx} +1 -1
- package/fixtures/{anti-slop/no-widen-then-assert.fixture.ts → no-widen-then-assert.fixture.ts} +1 -1
- package/fixtures/{anti-slop/require-safety-comment-for-type-assertion.fixture.ts → require-safety-comment-for-type-assertion.fixture.ts} +1 -1
- package/fixtures/{expo/static-public-env.fixture.ts → static-public-env.fixture.ts} +1 -1
- package/package.json +26 -26
- package/dist/anti-slop.d.mts +0 -6
- package/dist/anti-slop.mjs.map +0 -1
- package/dist/expo.d.mts +0 -5
- package/dist/expo.mjs +0 -51
- package/dist/expo.mjs.map +0 -1
- package/dist/i18n.d.mts +0 -5
- package/dist/i18n.mjs +0 -50
- package/dist/i18n.mjs.map +0 -1
- package/dist/react.d.mts +0 -5
- package/dist/react.mjs +0 -73
- package/dist/react.mjs.map +0 -1
- package/dist/rule-options-DrAXz8BD.mjs +0 -18
- package/dist/rule-options-DrAXz8BD.mjs.map +0 -1
- package/fixtures/anti-slop/no-shape-in-symbol-names.fixture.ts +0 -2
- package/fixtures/anti-slop/no-unknown-type-aliases.fixture.ts +0 -2
- package/fixtures/anti-slop/no-unsafe-dictionary-type.fixture.ts +0 -2
package/dist/verify.mjs
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, rmdirSync, symlinkSync } from "node:fs";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
//#region src/verify.ts
|
|
8
|
+
/**
|
|
9
|
+
* Proof that every lint rule still fires.
|
|
10
|
+
*
|
|
11
|
+
* The linter lives inside the `vp` binary, so it moves independently of any
|
|
12
|
+
* lockfile, and the JS-plugin bridge it loads these rules through is alpha. A
|
|
13
|
+
* rule can stop firing with no diff anywhere, and a dead lint rule is silent:
|
|
14
|
+
* "reports nothing" looks exactly like "no violations". This is the thing that
|
|
15
|
+
* notices.
|
|
16
|
+
*
|
|
17
|
+
* A suite is a directory holding one deliberately-broken `<rule>.fixture.ts(x)`
|
|
18
|
+
* per rule. The check asserts a positive: every rule fired, each on the file
|
|
19
|
+
* named after it.
|
|
20
|
+
*
|
|
21
|
+
* Run the package's own suite from a consumer's repo root:
|
|
22
|
+
*
|
|
23
|
+
* npx rdjperron-lint-verify
|
|
24
|
+
*
|
|
25
|
+
* ---------------------------------------------------------------------------
|
|
26
|
+
* Why the symlink dance
|
|
27
|
+
* ---------------------------------------------------------------------------
|
|
28
|
+
* The fixtures ship inside `node_modules`, which oxlint never walks, and a
|
|
29
|
+
* consumer's own fixture directories are usually in `lint.ignorePatterns` so a
|
|
30
|
+
* plain `vp check` stays quiet. Measured on Vite+ 0.2.9 / oxlint 1.77.0 and
|
|
31
|
+
* again on 0.3.1 / oxlint 1.81.0: no flag re-includes an ignored path.
|
|
32
|
+
* `--no-ignore`, `--ignore-pattern '!<dir>/**'`, an explicit file, an absolute
|
|
33
|
+
* path, a cwd inside the directory and `-W <rule>` all answer "No files found
|
|
34
|
+
* to lint." `--no-ignore` only disables `.eslintignore`, `--ignore-path` and
|
|
35
|
+
* `--ignore-pattern`; it does not touch the config's own `ignorePatterns`, and
|
|
36
|
+
* `vp lint` has no `--config` flag.
|
|
37
|
+
*
|
|
38
|
+
* What does work: oxlint matches ignore patterns against the path it walked,
|
|
39
|
+
* not the realpath. Linting through a symlink outside the ignored prefix
|
|
40
|
+
* reaches the fixtures normally, plugin and all. This creates that view per
|
|
41
|
+
* suite, lints through it, and removes it in a `finally`.
|
|
42
|
+
*
|
|
43
|
+
* The severities cannot come from the command line either: `-A`, `-W` and `-D`
|
|
44
|
+
* reach built-in rules only and leave every JS plugin rule exactly as the config
|
|
45
|
+
* left it (measured on vite-plus 0.3.1 / oxlint 1.81.0, with `vp lint` and with
|
|
46
|
+
* the bare binary). That is why the consumer's config must carry the
|
|
47
|
+
* `fixtures()` override from `@rdjperron/lint/config`.
|
|
48
|
+
*/
|
|
49
|
+
const DEFAULT_SUFFIXES = [".fixture.ts", ".fixture.tsx"];
|
|
50
|
+
/** Deterministic, locale-independent ordering for the rule and file name lists. */
|
|
51
|
+
function byName(left, right) {
|
|
52
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
53
|
+
}
|
|
54
|
+
function basename(path) {
|
|
55
|
+
const parts = path.split(/[\\/]/u);
|
|
56
|
+
return parts[parts.length - 1] ?? path;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Locate the `vp` binary: PATH first, then the default install locations, the
|
|
60
|
+
* XDG layout used since Vite+ 0.3.0 and the pre-0.3.0 single-root layout that
|
|
61
|
+
* upgraded installs keep.
|
|
62
|
+
*/
|
|
63
|
+
function resolveViteplusBinary() {
|
|
64
|
+
if (spawnSync("vp", ["--version"], { encoding: "utf8" }).status === 0) return "vp";
|
|
65
|
+
const home = process.env.HOME ?? "";
|
|
66
|
+
const found = [join(home, ".local", "share", "vite-plus", "bin", "vp"), join(home, ".vite-plus", "bin", "vp")].find((candidate) => existsSync(candidate));
|
|
67
|
+
if (found !== void 0) return found;
|
|
68
|
+
throw new Error("Could not find the `vp` binary. Add it to PATH: export PATH=\"$HOME/.local/share/vite-plus/bin:$PATH\" (or \"$HOME/.vite-plus/bin\" for a pre-0.3.0 install)");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* `vp lint -f json` is an outside value, so this is the one place its shape is
|
|
72
|
+
* checked. Anything that does not look like a diagnostic is dropped rather than
|
|
73
|
+
* guessed at.
|
|
74
|
+
*/
|
|
75
|
+
function decodeReport(json) {
|
|
76
|
+
const parsed = JSON.parse(json);
|
|
77
|
+
if (typeof parsed !== "object" || parsed === null) throw new Error("`vp lint -f json` did not return an object.");
|
|
78
|
+
const report = parsed;
|
|
79
|
+
const numberOfFiles = typeof report.number_of_files === "number" ? report.number_of_files : 0;
|
|
80
|
+
const rows = Array.isArray(report.diagnostics) ? report.diagnostics : [];
|
|
81
|
+
const diagnostics = [];
|
|
82
|
+
for (const row of rows) {
|
|
83
|
+
if (typeof row !== "object" || row === null) continue;
|
|
84
|
+
const entry = row;
|
|
85
|
+
diagnostics.push({
|
|
86
|
+
code: typeof entry.code === "string" ? entry.code : "",
|
|
87
|
+
filename: typeof entry.filename === "string" ? entry.filename : ""
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
numberOfFiles,
|
|
92
|
+
diagnostics
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** Run `vp lint <target> -f json` from `root` and return the decoded report. */
|
|
96
|
+
function lintAsJson(binary, root, target) {
|
|
97
|
+
const result = spawnSync(binary, [
|
|
98
|
+
"lint",
|
|
99
|
+
target,
|
|
100
|
+
"-f",
|
|
101
|
+
"json",
|
|
102
|
+
"--no-error-on-unmatched-pattern"
|
|
103
|
+
], {
|
|
104
|
+
cwd: root,
|
|
105
|
+
encoding: "utf8",
|
|
106
|
+
maxBuffer: 67108864
|
|
107
|
+
});
|
|
108
|
+
if (result.error !== void 0 && result.error !== null) throw result.error;
|
|
109
|
+
const stdout = result.stdout ?? "";
|
|
110
|
+
const start = stdout.indexOf("{");
|
|
111
|
+
if (start === -1) throw new Error(`\`vp lint ${target} -f json\` produced no JSON.\nstdout: ${stdout}\nstderr: ${result.stderr ?? ""}`);
|
|
112
|
+
try {
|
|
113
|
+
return decodeReport(stdout.slice(start));
|
|
114
|
+
} catch (cause) {
|
|
115
|
+
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
116
|
+
throw new Error(`Could not read \`vp lint\` JSON output: ${reason}\nstdout: ${stdout}`, { cause });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Why a path is gitignored, or null. oxlint honours `.gitignore`, so a
|
|
121
|
+
* gitignored view yields "0 files" instead of a useful diagnostic.
|
|
122
|
+
*/
|
|
123
|
+
function gitIgnoreReason(root, relPath) {
|
|
124
|
+
const result = spawnSync("git", [
|
|
125
|
+
"check-ignore",
|
|
126
|
+
"-v",
|
|
127
|
+
relPath
|
|
128
|
+
], {
|
|
129
|
+
cwd: root,
|
|
130
|
+
encoding: "utf8"
|
|
131
|
+
});
|
|
132
|
+
const output = result.status === 0 ? result.stdout.trim() : "";
|
|
133
|
+
return output === "" ? null : output.split(" ")[0] ?? null;
|
|
134
|
+
}
|
|
135
|
+
/** Rule name to fixture file name, taken from the files that exist on disk. */
|
|
136
|
+
function fixtureFiles(root, suite) {
|
|
137
|
+
const dir = join(root, suite.fixtureDir);
|
|
138
|
+
if (!existsSync(dir)) throw new Error(`Fixture directory is missing: ${dir}`);
|
|
139
|
+
const suffixes = suite.suffixes ?? DEFAULT_SUFFIXES;
|
|
140
|
+
const files = /* @__PURE__ */ new Map();
|
|
141
|
+
for (const name of readdirSync(dir).toSorted(byName)) {
|
|
142
|
+
const suffix = suffixes.find((candidate) => name.endsWith(candidate));
|
|
143
|
+
if (suffix === void 0) continue;
|
|
144
|
+
files.set(name.slice(0, -suffix.length), name);
|
|
145
|
+
}
|
|
146
|
+
return files;
|
|
147
|
+
}
|
|
148
|
+
/** Create the un-ignored view; prefer a symlink, fall back to a copy on Windows. */
|
|
149
|
+
function createFixtureView(root, suite) {
|
|
150
|
+
removeFixtureView(root, suite);
|
|
151
|
+
const viewPath = join(root, suite.viewDir);
|
|
152
|
+
mkdirSync(dirname(viewPath), { recursive: true });
|
|
153
|
+
try {
|
|
154
|
+
symlinkSync(join(root, suite.fixtureDir), viewPath, "junction");
|
|
155
|
+
return "symlink";
|
|
156
|
+
} catch {
|
|
157
|
+
cpSync(join(root, suite.fixtureDir), viewPath, { recursive: true });
|
|
158
|
+
return "copy";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function removeFixtureView(root, suite) {
|
|
162
|
+
const viewPath = join(root, suite.viewDir);
|
|
163
|
+
rmSync(viewPath, {
|
|
164
|
+
recursive: true,
|
|
165
|
+
force: true
|
|
166
|
+
});
|
|
167
|
+
const top = resolve(root);
|
|
168
|
+
for (let dir = dirname(viewPath); dir !== top; dir = dirname(dir)) {
|
|
169
|
+
if (!existsSync(dir) || readdirSync(dir).length > 0) break;
|
|
170
|
+
rmdirSync(dir);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** `rdjperron(no-reflect-get)` -> `no-reflect-get` for this suite's plugin; anything else -> null. */
|
|
174
|
+
function ruleIdFor(plugin, code) {
|
|
175
|
+
const match = new RegExp(`^${plugin}\\(([^)]+)\\)$`, "u").exec(code);
|
|
176
|
+
return match === null ? null : match[1] ?? null;
|
|
177
|
+
}
|
|
178
|
+
/** Lint one suite and print its table. Returns the number of rules that did not fire. */
|
|
179
|
+
async function verifySuite(binary, root, suite) {
|
|
180
|
+
const files = fixtureFiles(root, suite);
|
|
181
|
+
const expectedRules = [...files.keys()];
|
|
182
|
+
console.log(`${suite.plugin} rule verification`);
|
|
183
|
+
console.log(` fixtures: ${suite.fixtureDir}`);
|
|
184
|
+
if (expectedRules.length === 0) {
|
|
185
|
+
console.error(` No fixture files found in ${suite.fixtureDir}. Nothing to verify.\n`);
|
|
186
|
+
return 1;
|
|
187
|
+
}
|
|
188
|
+
let mechanism = "direct path";
|
|
189
|
+
let report = suite.alwaysView === true ? {
|
|
190
|
+
numberOfFiles: 0,
|
|
191
|
+
diagnostics: []
|
|
192
|
+
} : lintAsJson(binary, root, suite.fixtureDir);
|
|
193
|
+
if (report.numberOfFiles === 0) {
|
|
194
|
+
const kind = createFixtureView(root, suite);
|
|
195
|
+
try {
|
|
196
|
+
mechanism = `${kind} at ${suite.viewDir} (\`${suite.fixtureDir}\` is not walked by \`vp lint\`)`;
|
|
197
|
+
report = lintAsJson(binary, root, suite.viewDir);
|
|
198
|
+
} finally {
|
|
199
|
+
removeFixtureView(root, suite);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
console.log(` lint via: ${mechanism}`);
|
|
203
|
+
console.log(` files: ${report.numberOfFiles}`);
|
|
204
|
+
console.log("");
|
|
205
|
+
if (report.numberOfFiles === 0) {
|
|
206
|
+
const ignoredBy = gitIgnoreReason(root, suite.viewDir);
|
|
207
|
+
console.error("FAIL: `vp lint` matched 0 files through both the direct path and the un-ignored view.\n" + (ignoredBy === null ? `Check that the config ignores the fixture directory itself and not a pattern such as
|
|
208
|
+
"**/*.fixture.ts", which would also hide the view at "${suite.viewDir}".\nCheck too that the config carries the \`fixtures()\` override from @rdjperron/lint/config,
|
|
209
|
+
on the view path: no command-line flag can switch a JS plugin rule on.
|
|
210
|
+
` : `CAUSE: "${suite.viewDir}" is gitignored (${ignoredBy}). oxlint skips gitignored paths,\nso the view this lints through is invisible to it. Remove that ignore rule; the view is
|
|
211
|
+
deleted in a \`finally\` block anyway.
|
|
212
|
+
`));
|
|
213
|
+
return expectedRules.length;
|
|
214
|
+
}
|
|
215
|
+
const firedByRule = /* @__PURE__ */ new Map();
|
|
216
|
+
const foreignDiagnostics = [];
|
|
217
|
+
for (const diagnostic of report.diagnostics) {
|
|
218
|
+
const ruleId = ruleIdFor(suite.plugin, diagnostic.code);
|
|
219
|
+
if (ruleId === null) {
|
|
220
|
+
foreignDiagnostics.push(diagnostic);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const seen = firedByRule.get(ruleId) ?? /* @__PURE__ */ new Set();
|
|
224
|
+
seen.add(basename(diagnostic.filename));
|
|
225
|
+
firedByRule.set(ruleId, seen);
|
|
226
|
+
}
|
|
227
|
+
const rows = expectedRules.map((rule) => {
|
|
228
|
+
const seen = firedByRule.get(rule) ?? /* @__PURE__ */ new Set();
|
|
229
|
+
const fixture = files.get(rule) ?? rule;
|
|
230
|
+
const firedOnOwnFixture = seen.has(fixture);
|
|
231
|
+
return {
|
|
232
|
+
rule,
|
|
233
|
+
fixture,
|
|
234
|
+
firedOnOwnFixture,
|
|
235
|
+
note: firedOnOwnFixture ? "" : seen.size > 0 ? `fired only on: ${[...seen].toSorted(byName).join(", ")}` : "rule did not fire on any fixture"
|
|
236
|
+
};
|
|
237
|
+
});
|
|
238
|
+
const width = Math.max(...rows.map((row) => row.rule.length), 4);
|
|
239
|
+
console.log(`${"RULE".padEnd(width)} RESULT FIXTURE`);
|
|
240
|
+
console.log(`${"-".repeat(width)} ------ -------`);
|
|
241
|
+
for (const row of rows) {
|
|
242
|
+
const verdict = row.firedOnOwnFixture ? "PASS " : "FAIL ";
|
|
243
|
+
const suffix = row.note === "" ? "" : ` <-- ${row.note}`;
|
|
244
|
+
console.log(`${row.rule.padEnd(width)} ${verdict} ${row.fixture}${suffix}`);
|
|
245
|
+
}
|
|
246
|
+
console.log("");
|
|
247
|
+
const failures = rows.filter((row) => !row.firedOnOwnFixture);
|
|
248
|
+
console.log(`${rows.length - failures.length}/${rows.length} ${suite.plugin} rules fired on their own fixture.`);
|
|
249
|
+
const registered = suite.registeredRules === void 0 ? null : await suite.registeredRules();
|
|
250
|
+
if (registered !== null) {
|
|
251
|
+
const missingFixture = registered.filter((rule) => !expectedRules.includes(rule));
|
|
252
|
+
const orphanFixture = expectedRules.filter((rule) => !registered.includes(rule));
|
|
253
|
+
if (missingFixture.length > 0) console.log(`\nWARN: registered by the ${suite.plugin} plugin but has no fixture: ${missingFixture.join(", ")}`);
|
|
254
|
+
if (orphanFixture.length > 0) console.log(`\nWARN: fixture exists but the ${suite.plugin} plugin registers no such rule: ${orphanFixture.join(", ")}`);
|
|
255
|
+
}
|
|
256
|
+
if (foreignDiagnostics.length > 0) {
|
|
257
|
+
console.log(`\nWARN: ${foreignDiagnostics.length} non-${suite.plugin} diagnostic(s) in the fixtures:`);
|
|
258
|
+
for (const diagnostic of foreignDiagnostics.slice(0, 20)) console.log(` ${basename(diagnostic.filename)}: ${diagnostic.code}`);
|
|
259
|
+
}
|
|
260
|
+
if (failures.length > 0) {
|
|
261
|
+
const where = suite.readme === void 0 ? "" : ` See ${suite.readme}.`;
|
|
262
|
+
console.error(`\nFAIL: ${failures.length} ${suite.plugin} rule(s) did not fire.${where}\nFirst thing to check: the config's override on "${suite.viewDir}" has to put every rule\nat error. For this plugin that override is \`fixtures()\` from @rdjperron/lint/config; no
|
|
263
|
+
command-line flag can switch a JS plugin rule on.`);
|
|
264
|
+
}
|
|
265
|
+
console.log("");
|
|
266
|
+
return failures.length;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Lint every suite and print one table each. Returns the number of rules that
|
|
270
|
+
* did not fire, so zero means every rule of every suite is alive.
|
|
271
|
+
*/
|
|
272
|
+
async function verifySuites(suites, options = {}) {
|
|
273
|
+
const root = resolve(options.root ?? process.cwd());
|
|
274
|
+
const binary = resolveViteplusBinary();
|
|
275
|
+
let failures = 0;
|
|
276
|
+
try {
|
|
277
|
+
for (const suite of suites) failures += await verifySuite(binary, root, suite);
|
|
278
|
+
} finally {
|
|
279
|
+
for (const suite of suites) removeFixtureView(root, suite);
|
|
280
|
+
}
|
|
281
|
+
if (failures > 0) {
|
|
282
|
+
console.error(`FAIL: ${failures} rule(s) did not fire across ${suites.length} suite(s).`);
|
|
283
|
+
return failures;
|
|
284
|
+
}
|
|
285
|
+
console.log(`OK: every rule of every suite (${suites.map((suite) => suite.plugin).join(", ")}) still fires.`);
|
|
286
|
+
return 0;
|
|
287
|
+
}
|
|
288
|
+
const PLUGINS_PACKAGE = "@oxlint/plugins";
|
|
289
|
+
function readManifest(path) {
|
|
290
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
291
|
+
if (typeof parsed !== "object" || parsed === null) throw new Error(`Not a manifest: ${path}`);
|
|
292
|
+
const entry = parsed;
|
|
293
|
+
return {
|
|
294
|
+
version: typeof entry.version === "string" ? entry.version : "",
|
|
295
|
+
declaredPlugins: entry.dependencies?.[PLUGINS_PACKAGE] ?? "",
|
|
296
|
+
peerPlugins: entry.peerDependencies?.[PLUGINS_PACKAGE] ?? ""
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/** The nearest `package.json` at or above a resolved module file. */
|
|
300
|
+
function manifestNear(modulePath) {
|
|
301
|
+
let dir = dirname(modulePath);
|
|
302
|
+
for (;;) {
|
|
303
|
+
const candidate = join(dir, "package.json");
|
|
304
|
+
if (existsSync(candidate)) return candidate;
|
|
305
|
+
const parent = dirname(dir);
|
|
306
|
+
if (parent === dir) return null;
|
|
307
|
+
dir = parent;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/** `^x.y.z` is satisfied by the same major, at or above the base. */
|
|
311
|
+
function caretAccepts(range, version) {
|
|
312
|
+
const match = /^\^(\d+)\.(\d+)\.(\d+)$/u.exec(range);
|
|
313
|
+
if (match === null) throw new Error(`Expected a caret range, got "${range}"`);
|
|
314
|
+
const [major, minor, patch] = match.slice(1).map(Number);
|
|
315
|
+
const [candidateMajor, candidateMinor, candidatePatch] = version.split(".").map(Number);
|
|
316
|
+
if (candidateMajor !== major) return false;
|
|
317
|
+
if (candidateMinor !== minor) return (candidateMinor ?? 0) > (minor ?? 0);
|
|
318
|
+
return (candidatePatch ?? 0) >= (patch ?? 0);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Two promises about the plugin API, held here as a failure instead.
|
|
322
|
+
*
|
|
323
|
+
* - the installed `@oxlint/plugins` is the exact version `vite-plus` declares;
|
|
324
|
+
* - this package's peer range accepts that version.
|
|
325
|
+
*
|
|
326
|
+
* The rules import `@oxlint/plugins`, so the installed one must be the one the
|
|
327
|
+
* linter was built against, or the rules compile against one plugin API and run
|
|
328
|
+
* under another with no error anywhere. Returns the failures, empty when the
|
|
329
|
+
* pins agree or when `vite-plus` is not installed (a consumer on another
|
|
330
|
+
* toolchain has nothing to pin against).
|
|
331
|
+
*/
|
|
332
|
+
function verifyPluginApiPin(root = process.cwd()) {
|
|
333
|
+
const requireFromRoot = createRequire(join(resolve(root), "package.json"));
|
|
334
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
335
|
+
let vitePlus;
|
|
336
|
+
try {
|
|
337
|
+
vitePlus = readManifest(requireFromRoot.resolve("vite-plus/package.json"));
|
|
338
|
+
} catch {
|
|
339
|
+
console.log("plugin API pin: skipped, `vite-plus` is not installed here.");
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
342
|
+
const declared = vitePlus.declaredPlugins.replace(/^=/u, "");
|
|
343
|
+
if (!/^\d+\.\d+\.\d+$/u.test(declared)) return [`vite-plus ${vitePlus.version} no longer declares an exact @oxlint/plugins version.`];
|
|
344
|
+
let installed;
|
|
345
|
+
try {
|
|
346
|
+
const manifest = manifestNear(requireFromRoot.resolve("@oxlint/plugins"));
|
|
347
|
+
if (manifest === null) throw new Error("no package.json above @oxlint/plugins");
|
|
348
|
+
installed = readManifest(manifest);
|
|
349
|
+
} catch {
|
|
350
|
+
return ["`@oxlint/plugins` is not installed. It is a peer dependency of @rdjperron/lint."];
|
|
351
|
+
}
|
|
352
|
+
const self = readManifest(requireFromHere.resolve("../package.json"));
|
|
353
|
+
const peer = self.peerPlugins;
|
|
354
|
+
const failures = [];
|
|
355
|
+
if (installed.version !== declared) failures.push(`@oxlint/plugins ${installed.version} is installed and vite-plus ${vitePlus.version} declares ${declared}. Move the pin: install @oxlint/plugins@${declared} exactly.`);
|
|
356
|
+
if (!caretAccepts(peer, declared)) failures.push(`@rdjperron/lint ${self.version} wants @oxlint/plugins ${peer} and vite-plus ${vitePlus.version} declares ${declared}. Move one of the two pins.`);
|
|
357
|
+
if (failures.length === 0) console.log(`plugin API pin: @oxlint/plugins ${installed.version}, what vite-plus ${vitePlus.version} declares.`);
|
|
358
|
+
return failures;
|
|
359
|
+
}
|
|
360
|
+
/** The suite for this package's own fixtures, as they sit in a consumer's `node_modules`. */
|
|
361
|
+
function packageSuite(root = process.cwd()) {
|
|
362
|
+
const packageDir = "node_modules/@rdjperron/lint";
|
|
363
|
+
return {
|
|
364
|
+
plugin: "rdjperron",
|
|
365
|
+
fixtureDir: `${packageDir}/fixtures`,
|
|
366
|
+
viewDir: "scripts/.lint-fixtures/rdjperron",
|
|
367
|
+
alwaysView: true,
|
|
368
|
+
readme: `${packageDir}/fixtures/README.md`,
|
|
369
|
+
registeredRules: async () => {
|
|
370
|
+
try {
|
|
371
|
+
const rules = (await import(createRequire(join(resolve(root), "package.json")).resolve("@rdjperron/lint"))).default?.rules;
|
|
372
|
+
return typeof rules === "object" && rules !== null ? Object.keys(rules).toSorted(byName) : null;
|
|
373
|
+
} catch {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
/** The bin: this package's suite, plus the plugin API pin, from the consumer's repo root. */
|
|
380
|
+
async function main(root = process.cwd()) {
|
|
381
|
+
const pinFailures = verifyPluginApiPin(root);
|
|
382
|
+
for (const failure of pinFailures) console.error(`FAIL: ${failure}`);
|
|
383
|
+
console.log("");
|
|
384
|
+
const ruleFailures = await verifySuites([packageSuite(root)], { root });
|
|
385
|
+
return pinFailures.length + ruleFailures > 0 ? 1 : 0;
|
|
386
|
+
}
|
|
387
|
+
const invoked = process.argv[1];
|
|
388
|
+
if (invoked !== void 0 && existsSync(invoked) && realpathSync(invoked) === fileURLToPath(import.meta.url)) {
|
|
389
|
+
let exitCode = 1;
|
|
390
|
+
try {
|
|
391
|
+
exitCode = await main();
|
|
392
|
+
} catch (error) {
|
|
393
|
+
console.error(`\nFAIL: ${error instanceof Error ? error.message : String(error)}`);
|
|
394
|
+
}
|
|
395
|
+
process.exit(exitCode);
|
|
396
|
+
}
|
|
397
|
+
//#endregion
|
|
398
|
+
export { main, packageSuite, resolveViteplusBinary, verifyPluginApiPin, verifySuites };
|
|
399
|
+
|
|
400
|
+
//# sourceMappingURL=verify.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.mjs","names":[],"sources":["../src/verify.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * Proof that every lint rule still fires.\n *\n * The linter lives inside the `vp` binary, so it moves independently of any\n * lockfile, and the JS-plugin bridge it loads these rules through is alpha. A\n * rule can stop firing with no diff anywhere, and a dead lint rule is silent:\n * \"reports nothing\" looks exactly like \"no violations\". This is the thing that\n * notices.\n *\n * A suite is a directory holding one deliberately-broken `<rule>.fixture.ts(x)`\n * per rule. The check asserts a positive: every rule fired, each on the file\n * named after it.\n *\n * Run the package's own suite from a consumer's repo root:\n *\n * npx rdjperron-lint-verify\n *\n * ---------------------------------------------------------------------------\n * Why the symlink dance\n * ---------------------------------------------------------------------------\n * The fixtures ship inside `node_modules`, which oxlint never walks, and a\n * consumer's own fixture directories are usually in `lint.ignorePatterns` so a\n * plain `vp check` stays quiet. Measured on Vite+ 0.2.9 / oxlint 1.77.0 and\n * again on 0.3.1 / oxlint 1.81.0: no flag re-includes an ignored path.\n * `--no-ignore`, `--ignore-pattern '!<dir>/**'`, an explicit file, an absolute\n * path, a cwd inside the directory and `-W <rule>` all answer \"No files found\n * to lint.\" `--no-ignore` only disables `.eslintignore`, `--ignore-path` and\n * `--ignore-pattern`; it does not touch the config's own `ignorePatterns`, and\n * `vp lint` has no `--config` flag.\n *\n * What does work: oxlint matches ignore patterns against the path it walked,\n * not the realpath. Linting through a symlink outside the ignored prefix\n * reaches the fixtures normally, plugin and all. This creates that view per\n * suite, lints through it, and removes it in a `finally`.\n *\n * The severities cannot come from the command line either: `-A`, `-W` and `-D`\n * reach built-in rules only and leave every JS plugin rule exactly as the config\n * left it (measured on vite-plus 0.3.1 / oxlint 1.81.0, with `vp lint` and with\n * the bare binary). That is why the consumer's config must carry the\n * `fixtures()` override from `@rdjperron/lint/config`.\n */\n\nimport { spawnSync } from \"node:child_process\";\nimport {\n cpSync,\n existsSync,\n mkdirSync,\n readdirSync,\n rmdirSync,\n readFileSync,\n realpathSync,\n rmSync,\n symlinkSync,\n} from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport interface Suite {\n /** The plugin alias the diagnostics carry, e.g. `rdjperron` in `rdjperron(no-reflect-get)`. */\n plugin: string;\n /** The fixture directory, relative to `root`. */\n fixtureDir: string;\n /** Where the un-ignored view is created, relative to `root`. */\n viewDir: string;\n /** Fixture file endings; the part before one of them is the rule name. */\n suffixes?: string[];\n /** Skip the direct path and always lint through the view (fixtures under `node_modules`). */\n alwaysView?: boolean;\n /** Advisory: the rule names the plugin registers, so a new rule without a fixture is named. */\n registeredRules?: () => Promise<string[] | null>;\n /** Where the failure message sends the reader. */\n readme?: string;\n}\n\nexport interface VerifyOptions {\n /** The repo root the paths are relative to and `vp lint` runs from. Defaults to the cwd. */\n root?: string;\n}\n\nconst DEFAULT_SUFFIXES = [\".fixture.ts\", \".fixture.tsx\"];\n\n/** Deterministic, locale-independent ordering for the rule and file name lists. */\nfunction byName(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n\nfunction basename(path: string): string {\n const parts = path.split(/[\\\\/]/u);\n return parts[parts.length - 1] ?? path;\n}\n\n/**\n * Locate the `vp` binary: PATH first, then the default install locations, the\n * XDG layout used since Vite+ 0.3.0 and the pre-0.3.0 single-root layout that\n * upgraded installs keep.\n */\nexport function resolveViteplusBinary(): string {\n const probe = spawnSync(\"vp\", [\"--version\"], { encoding: \"utf8\" });\n if (probe.status === 0) return \"vp\";\n const home = process.env.HOME ?? \"\";\n const fallbacks = [\n join(home, \".local\", \"share\", \"vite-plus\", \"bin\", \"vp\"),\n join(home, \".vite-plus\", \"bin\", \"vp\"),\n ];\n const found = fallbacks.find((candidate) => existsSync(candidate));\n if (found !== undefined) return found;\n throw new Error(\n \"Could not find the `vp` binary. Add it to PATH: \" +\n 'export PATH=\"$HOME/.local/share/vite-plus/bin:$PATH\" (or \"$HOME/.vite-plus/bin\" for a pre-0.3.0 install)',\n );\n}\n\ninterface LintDiagnostic {\n code: string;\n filename: string;\n}\n\ninterface LintReport {\n numberOfFiles: number;\n diagnostics: LintDiagnostic[];\n}\n\n/** The two fields of oxlint's JSON report this reads, before any of them is trusted. */\ninterface RawReport {\n number_of_files?: unknown;\n diagnostics?: unknown;\n}\n\n/** The two fields of one raw diagnostic, before either of them is trusted. */\ninterface RawDiagnostic {\n code?: unknown;\n filename?: unknown;\n}\n\n/**\n * `vp lint -f json` is an outside value, so this is the one place its shape is\n * checked. Anything that does not look like a diagnostic is dropped rather than\n * guessed at.\n */\nfunction decodeReport(json: string): LintReport {\n const parsed: unknown = JSON.parse(json);\n if (typeof parsed !== \"object\" || parsed === null) {\n throw new Error(\"`vp lint -f json` did not return an object.\");\n }\n // SAFETY: the check above makes it a non-null object, and every field of\n // `RawReport` is `unknown`, so nothing is claimed about its contents yet.\n const report = parsed as RawReport;\n const numberOfFiles = typeof report.number_of_files === \"number\" ? report.number_of_files : 0;\n const rows = Array.isArray(report.diagnostics) ? report.diagnostics : [];\n const diagnostics: LintDiagnostic[] = [];\n for (const row of rows) {\n if (typeof row !== \"object\" || row === null) continue;\n // SAFETY: same check, one level down; both fields of `RawDiagnostic` are\n // `unknown` and each is typed by its own test on the next lines.\n const entry = row as RawDiagnostic;\n diagnostics.push({\n code: typeof entry.code === \"string\" ? entry.code : \"\",\n filename: typeof entry.filename === \"string\" ? entry.filename : \"\",\n });\n }\n return { numberOfFiles, diagnostics };\n}\n\n/** Run `vp lint <target> -f json` from `root` and return the decoded report. */\nfunction lintAsJson(binary: string, root: string, target: string): LintReport {\n const result = spawnSync(\n binary,\n [\"lint\", target, \"-f\", \"json\", \"--no-error-on-unmatched-pattern\"],\n {\n cwd: root,\n encoding: \"utf8\",\n maxBuffer: 64 * 1024 * 1024,\n },\n );\n\n if (result.error !== undefined && result.error !== null) throw result.error;\n\n // `--no-error-on-unmatched-pattern` keeps the \"No files found to lint.\" banner\n // off stdout, so stdout is pure JSON even when nothing matched.\n const stdout = result.stdout ?? \"\";\n const start = stdout.indexOf(\"{\");\n if (start === -1) {\n throw new Error(\n `\\`vp lint ${target} -f json\\` produced no JSON.\\nstdout: ${stdout}\\nstderr: ${result.stderr ?? \"\"}`,\n );\n }\n\n try {\n return decodeReport(stdout.slice(start));\n } catch (cause) {\n const reason = cause instanceof Error ? cause.message : String(cause);\n throw new Error(`Could not read \\`vp lint\\` JSON output: ${reason}\\nstdout: ${stdout}`, {\n cause,\n });\n }\n}\n\n/**\n * Why a path is gitignored, or null. oxlint honours `.gitignore`, so a\n * gitignored view yields \"0 files\" instead of a useful diagnostic.\n */\nfunction gitIgnoreReason(root: string, relPath: string): string | null {\n const result = spawnSync(\"git\", [\"check-ignore\", \"-v\", relPath], { cwd: root, encoding: \"utf8\" });\n const output = result.status === 0 ? result.stdout.trim() : \"\";\n return output === \"\" ? null : (output.split(\"\\t\")[0] ?? null);\n}\n\n/** Rule name to fixture file name, taken from the files that exist on disk. */\nfunction fixtureFiles(root: string, suite: Suite): Map<string, string> {\n const dir = join(root, suite.fixtureDir);\n if (!existsSync(dir)) throw new Error(`Fixture directory is missing: ${dir}`);\n const suffixes = suite.suffixes ?? DEFAULT_SUFFIXES;\n const files = new Map<string, string>();\n for (const name of readdirSync(dir).toSorted(byName)) {\n const suffix = suffixes.find((candidate) => name.endsWith(candidate));\n if (suffix === undefined) continue;\n files.set(name.slice(0, -suffix.length), name);\n }\n return files;\n}\n\n/** Create the un-ignored view; prefer a symlink, fall back to a copy on Windows. */\nfunction createFixtureView(root: string, suite: Suite): string {\n removeFixtureView(root, suite);\n const viewPath = join(root, suite.viewDir);\n mkdirSync(dirname(viewPath), { recursive: true });\n try {\n symlinkSync(join(root, suite.fixtureDir), viewPath, \"junction\");\n return \"symlink\";\n } catch {\n cpSync(join(root, suite.fixtureDir), viewPath, { recursive: true });\n return \"copy\";\n }\n}\n\nfunction removeFixtureView(root: string, suite: Suite): void {\n const viewPath = join(root, suite.viewDir);\n rmSync(viewPath, { recursive: true, force: true });\n // The parents were created for the view alone when nothing else lives there, so they go too.\n const top = resolve(root);\n for (let dir = dirname(viewPath); dir !== top; dir = dirname(dir)) {\n if (!existsSync(dir) || readdirSync(dir).length > 0) break;\n rmdirSync(dir);\n }\n}\n\n/** `rdjperron(no-reflect-get)` -> `no-reflect-get` for this suite's plugin; anything else -> null. */\nfunction ruleIdFor(plugin: string, code: string): string | null {\n const match = new RegExp(`^${plugin}\\\\(([^)]+)\\\\)$`, \"u\").exec(code);\n return match === null ? null : (match[1] ?? null);\n}\n\ninterface Row {\n rule: string;\n fixture: string;\n firedOnOwnFixture: boolean;\n note: string;\n}\n\n/** Lint one suite and print its table. Returns the number of rules that did not fire. */\nasync function verifySuite(binary: string, root: string, suite: Suite): Promise<number> {\n const files = fixtureFiles(root, suite);\n const expectedRules = [...files.keys()];\n\n console.log(`${suite.plugin} rule verification`);\n console.log(` fixtures: ${suite.fixtureDir}`);\n\n if (expectedRules.length === 0) {\n console.error(` No fixture files found in ${suite.fixtureDir}. Nothing to verify.\\n`);\n return 1;\n }\n\n // 1. Try the fixture directory directly. Works only while it is un-ignored, so\n // a suite under node_modules skips it: oxlint never walks in there.\n let mechanism = \"direct path\";\n let report: LintReport =\n suite.alwaysView === true\n ? { numberOfFiles: 0, diagnostics: [] }\n : lintAsJson(binary, root, suite.fixtureDir);\n\n // 2. Ignored by the config or under node_modules: lint through an un-ignored view.\n if (report.numberOfFiles === 0) {\n const kind = createFixtureView(root, suite);\n try {\n mechanism = `${kind} at ${suite.viewDir} (\\`${suite.fixtureDir}\\` is not walked by \\`vp lint\\`)`;\n report = lintAsJson(binary, root, suite.viewDir);\n } finally {\n // Never leave the view behind: a stale one would show up in `vp check`.\n removeFixtureView(root, suite);\n }\n }\n\n console.log(` lint via: ${mechanism}`);\n console.log(` files: ${report.numberOfFiles}`);\n console.log(\"\");\n\n if (report.numberOfFiles === 0) {\n const ignoredBy = gitIgnoreReason(root, suite.viewDir);\n console.error(\n \"FAIL: `vp lint` matched 0 files through both the direct path and the un-ignored view.\\n\" +\n (ignoredBy === null\n ? \"Check that the config ignores the fixture directory itself and not a pattern such as\\n\" +\n `\"**/*.fixture.ts\", which would also hide the view at \"${suite.viewDir}\".\\n` +\n \"Check too that the config carries the `fixtures()` override from @rdjperron/lint/config,\\n\" +\n \"on the view path: no command-line flag can switch a JS plugin rule on.\\n\"\n : `CAUSE: \"${suite.viewDir}\" is gitignored (${ignoredBy}). oxlint skips gitignored paths,\\n` +\n \"so the view this lints through is invisible to it. Remove that ignore rule; the view is\\n\" +\n \"deleted in a `finally` block anyway.\\n\"),\n );\n return expectedRules.length;\n }\n\n const firedByRule = new Map<string, Set<string>>();\n const foreignDiagnostics: LintDiagnostic[] = [];\n\n for (const diagnostic of report.diagnostics) {\n const ruleId = ruleIdFor(suite.plugin, diagnostic.code);\n if (ruleId === null) {\n foreignDiagnostics.push(diagnostic);\n continue;\n }\n const seen = firedByRule.get(ruleId) ?? new Set<string>();\n seen.add(basename(diagnostic.filename));\n firedByRule.set(ruleId, seen);\n }\n\n const rows: Row[] = expectedRules.map((rule) => {\n const seen = firedByRule.get(rule) ?? new Set<string>();\n const fixture = files.get(rule) ?? rule;\n const firedOnOwnFixture = seen.has(fixture);\n return {\n rule,\n fixture,\n firedOnOwnFixture,\n note: firedOnOwnFixture\n ? \"\"\n : seen.size > 0\n ? `fired only on: ${[...seen].toSorted(byName).join(\", \")}`\n : \"rule did not fire on any fixture\",\n };\n });\n\n const width = Math.max(...rows.map((row) => row.rule.length), 4);\n console.log(`${\"RULE\".padEnd(width)} RESULT FIXTURE`);\n console.log(`${\"-\".repeat(width)} ------ -------`);\n for (const row of rows) {\n const verdict = row.firedOnOwnFixture ? \"PASS \" : \"FAIL \";\n const suffix = row.note === \"\" ? \"\" : ` <-- ${row.note}`;\n console.log(`${row.rule.padEnd(width)} ${verdict} ${row.fixture}${suffix}`);\n }\n console.log(\"\");\n\n const failures = rows.filter((row) => !row.firedOnOwnFixture);\n console.log(\n `${rows.length - failures.length}/${rows.length} ${suite.plugin} rules fired on their own fixture.`,\n );\n\n // Advisory: a plugin bump that adds a rule should also add a fixture.\n const registered = suite.registeredRules === undefined ? null : await suite.registeredRules();\n if (registered !== null) {\n const missingFixture = registered.filter((rule) => !expectedRules.includes(rule));\n const orphanFixture = expectedRules.filter((rule) => !registered.includes(rule));\n if (missingFixture.length > 0) {\n console.log(\n `\\nWARN: registered by the ${suite.plugin} plugin but has no fixture: ${missingFixture.join(\", \")}`,\n );\n }\n if (orphanFixture.length > 0) {\n console.log(\n `\\nWARN: fixture exists but the ${suite.plugin} plugin registers no such rule: ${orphanFixture.join(\", \")}`,\n );\n }\n }\n\n // Advisory: fixtures are meant to trip exactly one rule each.\n if (foreignDiagnostics.length > 0) {\n console.log(\n `\\nWARN: ${foreignDiagnostics.length} non-${suite.plugin} diagnostic(s) in the fixtures:`,\n );\n for (const diagnostic of foreignDiagnostics.slice(0, 20)) {\n console.log(` ${basename(diagnostic.filename)}: ${diagnostic.code}`);\n }\n }\n\n if (failures.length > 0) {\n const where = suite.readme === undefined ? \"\" : ` See ${suite.readme}.`;\n console.error(\n `\\nFAIL: ${failures.length} ${suite.plugin} rule(s) did not fire.${where}\\n` +\n `First thing to check: the config's override on \"${suite.viewDir}\" has to put every rule\\n` +\n \"at error. For this plugin that override is `fixtures()` from @rdjperron/lint/config; no\\n\" +\n \"command-line flag can switch a JS plugin rule on.\",\n );\n }\n console.log(\"\");\n return failures.length;\n}\n\n/**\n * Lint every suite and print one table each. Returns the number of rules that\n * did not fire, so zero means every rule of every suite is alive.\n */\nexport async function verifySuites(suites: Suite[], options: VerifyOptions = {}): Promise<number> {\n const root = resolve(options.root ?? process.cwd());\n const binary = resolveViteplusBinary();\n let failures = 0;\n try {\n for (const suite of suites) {\n failures += await verifySuite(binary, root, suite);\n }\n } finally {\n for (const suite of suites) removeFixtureView(root, suite);\n }\n if (failures > 0) {\n console.error(`FAIL: ${failures} rule(s) did not fire across ${suites.length} suite(s).`);\n return failures;\n }\n console.log(\n `OK: every rule of every suite (${suites.map((suite) => suite.plugin).join(\", \")}) still fires.`,\n );\n return 0;\n}\n\nconst PLUGINS_PACKAGE = \"@oxlint/plugins\";\n\n/** What this needs from a `package.json`: its version, and what it says about the plugin API. */\ninterface Manifest {\n version: string;\n /** The `@oxlint/plugins` spec in `dependencies`, or \"\". */\n declaredPlugins: string;\n /** The `@oxlint/plugins` spec in `peerDependencies`, or \"\". */\n peerPlugins: string;\n}\n\n/** npm's manifest schema: both tables map a package name to a version spec. */\ninterface DependencyTable {\n [name: string]: string | undefined;\n}\n\ninterface RawManifest {\n version?: unknown;\n dependencies?: DependencyTable;\n peerDependencies?: DependencyTable;\n}\n\nfunction readManifest(path: string): Manifest {\n const parsed: unknown = JSON.parse(readFileSync(path, \"utf8\"));\n if (typeof parsed !== \"object\" || parsed === null) throw new Error(`Not a manifest: ${path}`);\n // SAFETY: the check above makes it a non-null object, and npm's own schema makes\n // both dependency tables name-to-spec; a package.json that breaks that is not\n // installable, and a non-string spec reaching here simply fails the comparisons.\n const entry = parsed as RawManifest;\n return {\n version: typeof entry.version === \"string\" ? entry.version : \"\",\n declaredPlugins: entry.dependencies?.[PLUGINS_PACKAGE] ?? \"\",\n peerPlugins: entry.peerDependencies?.[PLUGINS_PACKAGE] ?? \"\",\n };\n}\n\n/** The nearest `package.json` at or above a resolved module file. */\nfunction manifestNear(modulePath: string): string | null {\n let dir = dirname(modulePath);\n for (;;) {\n const candidate = join(dir, \"package.json\");\n if (existsSync(candidate)) return candidate;\n const parent = dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\n/** `^x.y.z` is satisfied by the same major, at or above the base. */\nfunction caretAccepts(range: string, version: string): boolean {\n const match = /^\\^(\\d+)\\.(\\d+)\\.(\\d+)$/u.exec(range);\n if (match === null) throw new Error(`Expected a caret range, got \"${range}\"`);\n const [major, minor, patch] = match.slice(1).map(Number);\n const [candidateMajor, candidateMinor, candidatePatch] = version.split(\".\").map(Number);\n if (candidateMajor !== major) return false;\n if (candidateMinor !== minor) return (candidateMinor ?? 0) > (minor ?? 0);\n return (candidatePatch ?? 0) >= (patch ?? 0);\n}\n\n/**\n * Two promises about the plugin API, held here as a failure instead.\n *\n * - the installed `@oxlint/plugins` is the exact version `vite-plus` declares;\n * - this package's peer range accepts that version.\n *\n * The rules import `@oxlint/plugins`, so the installed one must be the one the\n * linter was built against, or the rules compile against one plugin API and run\n * under another with no error anywhere. Returns the failures, empty when the\n * pins agree or when `vite-plus` is not installed (a consumer on another\n * toolchain has nothing to pin against).\n */\nexport function verifyPluginApiPin(root = process.cwd()): string[] {\n const requireFromRoot = createRequire(join(resolve(root), \"package.json\"));\n const requireFromHere = createRequire(import.meta.url);\n\n let vitePlus: Manifest;\n try {\n vitePlus = readManifest(requireFromRoot.resolve(\"vite-plus/package.json\"));\n } catch {\n console.log(\"plugin API pin: skipped, `vite-plus` is not installed here.\");\n return [];\n }\n\n const declared = vitePlus.declaredPlugins.replace(/^=/u, \"\");\n if (!/^\\d+\\.\\d+\\.\\d+$/u.test(declared)) {\n return [`vite-plus ${vitePlus.version} no longer declares an exact @oxlint/plugins version.`];\n }\n\n let installed: Manifest;\n try {\n const entry = requireFromRoot.resolve(\"@oxlint/plugins\");\n const manifest = manifestNear(entry);\n if (manifest === null) throw new Error(\"no package.json above @oxlint/plugins\");\n installed = readManifest(manifest);\n } catch {\n return [\"`@oxlint/plugins` is not installed. It is a peer dependency of @rdjperron/lint.\"];\n }\n\n const self = readManifest(requireFromHere.resolve(\"../package.json\"));\n const peer = self.peerPlugins;\n const failures: string[] = [];\n\n if (installed.version !== declared) {\n failures.push(\n `@oxlint/plugins ${installed.version} is installed and vite-plus ${vitePlus.version} declares ` +\n `${declared}. Move the pin: install @oxlint/plugins@${declared} exactly.`,\n );\n }\n if (!caretAccepts(peer, declared)) {\n failures.push(\n `@rdjperron/lint ${self.version} wants @oxlint/plugins ${peer} and vite-plus ${vitePlus.version} ` +\n `declares ${declared}. Move one of the two pins.`,\n );\n }\n if (failures.length === 0) {\n console.log(\n `plugin API pin: @oxlint/plugins ${installed.version}, what vite-plus ${vitePlus.version} declares.`,\n );\n }\n return failures;\n}\n\n/** The suite for this package's own fixtures, as they sit in a consumer's `node_modules`. */\nexport function packageSuite(root = process.cwd()): Suite {\n const packageDir = \"node_modules/@rdjperron/lint\";\n return {\n plugin: \"rdjperron\",\n fixtureDir: `${packageDir}/fixtures`,\n viewDir: \"scripts/.lint-fixtures/rdjperron\",\n alwaysView: true,\n readme: `${packageDir}/fixtures/README.md`,\n registeredRules: async () => {\n try {\n const requireFromRoot = createRequire(join(resolve(root), \"package.json\"));\n const loaded: unknown = await import(requireFromRoot.resolve(\"@rdjperron/lint\"));\n // SAFETY: the plugin's default export is the object oxlint loads; `rules` is\n // still `unknown` here and is checked on the next line.\n const module_ = loaded as { default?: { rules?: unknown } };\n const rules = module_.default?.rules;\n return typeof rules === \"object\" && rules !== null\n ? Object.keys(rules).toSorted(byName)\n : null;\n } catch {\n return null;\n }\n },\n };\n}\n\n/** The bin: this package's suite, plus the plugin API pin, from the consumer's repo root. */\nexport async function main(root = process.cwd()): Promise<number> {\n const pinFailures = verifyPluginApiPin(root);\n for (const failure of pinFailures) console.error(`FAIL: ${failure}`);\n console.log(\"\");\n const ruleFailures = await verifySuites([packageSuite(root)], { root });\n return pinFailures.length + ruleFailures > 0 ? 1 : 0;\n}\n\nconst invoked = process.argv[1];\nconst isBin =\n invoked !== undefined &&\n existsSync(invoked) &&\n realpathSync(invoked) === fileURLToPath(import.meta.url);\n\nif (isBin) {\n let exitCode = 1;\n try {\n exitCode = await main();\n } catch (error) {\n console.error(`\\nFAIL: ${error instanceof Error ? error.message : String(error)}`);\n }\n process.exit(exitCode);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,MAAM,mBAAmB,CAAC,eAAe,cAAc;;AAGvD,SAAS,OAAO,MAAc,OAAuB;CACnD,OAAO,OAAO,QAAQ,KAAK,OAAO,Q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ClB,aAAa,OAAO,MAAM,cAAc,YAAY,GAAG,GAE9C;CACT,IAAI,WAAW;CACf,IAAI;EACF,WAAW,MAAM,KAAK;CACxB,SAAS,OAAO;EACd,QAAQ,MAAM,WAAW,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG;CACnF;CACA,QAAQ,KAAK,QAAQ;AACvB"}
|
package/fixtures/README.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# fixtures: load-bearing test data, do not delete
|
|
2
2
|
|
|
3
|
-
One deliberately violating file per rule,
|
|
4
|
-
|
|
5
|
-
`i18n/no-hardcoded-jsx-text.fixture.tsx` and `expo/static-public-env.fixture.ts`. Each file trips
|
|
6
|
-
exactly the rule it is named after, and nothing else.
|
|
3
|
+
One deliberately violating file per rule, `<rule>.fixture.ts` or `.fixture.tsx`, flat. Each file
|
|
4
|
+
trips exactly the rule it is named after, and nothing else.
|
|
7
5
|
|
|
8
6
|
These ship in the published package (`files` in `package.json`), so a consumer proves the rules
|
|
9
7
|
fire through its own linter, not ours.
|
|
@@ -18,18 +16,17 @@ pattern swallows the wrong path.
|
|
|
18
16
|
And a dead lint rule is silent. "Rule reports nothing" looks identical to "code has no
|
|
19
17
|
violations". Nothing else would notice.
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
goes dead, the run fails loudly instead of going quietly green.
|
|
19
|
+
`npx rdjperron-lint-verify` lints these files and asserts a positive: every rule must fire, each on its
|
|
20
|
+
own fixture. If a rule goes dead, the run fails loudly instead of going quietly green.
|
|
24
21
|
|
|
25
22
|
## How it relates to the unit tests
|
|
26
23
|
|
|
27
24
|
Two layers, different questions:
|
|
28
25
|
|
|
29
|
-
| Layer
|
|
30
|
-
|
|
|
31
|
-
| This directory +
|
|
32
|
-
| Unit tests (RuleTester)
|
|
26
|
+
| Layer | Question it answers | Where |
|
|
27
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------- |
|
|
28
|
+
| This directory + the verify command | Does each rule fire through the real pipeline: the bundled oxlint, the `jsPlugins` wiring, the actual config? | `fixtures/`, `rdjperron-lint-verify` |
|
|
29
|
+
| Unit tests (RuleTester) | Is each rule's logic right? Valid cases stay quiet, invalid cases report, with per-case precision. | `tests/` in the source repo (not published) |
|
|
33
30
|
|
|
34
31
|
The unit tests catch a locally edited rule that starts over- or under-firing. This layer catches
|
|
35
32
|
the rule not running at all. Both are needed.
|
|
@@ -38,26 +35,28 @@ the rule not running at all. Both are needed.
|
|
|
38
35
|
|
|
39
36
|
- Do not delete or "clean up" these files. They are the regression proof for rules nobody
|
|
40
37
|
upstream maintains for us.
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
- The consumer's config must carry the `fixtures()` override from `@rdjperron/lint/config`, which
|
|
39
|
+
puts every rule at `error` on the view path. No command-line flag can do it: `-A`, `-W` and `-D`
|
|
40
|
+
reach built-in rules only and leave a JS plugin rule exactly as the config left it.
|
|
41
|
+
- The fixtures sit under `node_modules`, which oxlint never walks, so the check lints them through
|
|
42
|
+
a transient symlink at `scripts/.lint-fixtures/rdjperron`. In the source repo they are also in
|
|
43
|
+
`lint.ignorePatterns` and `fmt.ignorePatterns`, so a plain `vp check` stays quiet; no `vp lint`
|
|
44
|
+
flag re-includes a config-ignored path.
|
|
45
45
|
- Never gitignore that view. oxlint honours `.gitignore`, so gitignoring anything on the
|
|
46
|
-
verification path silently disables the whole check (this happened once; the
|
|
46
|
+
verification path silently disables the whole check (this happened once; the check now detects
|
|
47
47
|
it with `git check-ignore` and says so).
|
|
48
48
|
- Name fixtures `*.fixture.ts` / `*.fixture.tsx`, never `*.test.ts`, or Vitest collects them and
|
|
49
49
|
the deliberately broken code fails the test run.
|
|
50
50
|
- One rule per file. A fixture that trips two rules makes the per-rule assertion ambiguous.
|
|
51
|
-
- Expected advisory noise
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
them; only a pack rule that did not fire fails the run.
|
|
51
|
+
- Expected advisory noise: a type-aware pass also reports `typescript(TS…)` on the view, because
|
|
52
|
+
no tsconfig covers it (no React types, no `process` types, no `jsx` setting). Those are listed
|
|
53
|
+
as non-plugin diagnostics rather than hidden; only a plugin rule that did not fire fails the run.
|
|
55
54
|
|
|
56
55
|
## When a rule stops firing after a `vp` upgrade
|
|
57
56
|
|
|
58
57
|
1. `vp toolchain oxlint`: did the bundled oxlint move?
|
|
59
58
|
2. `vp why @oxlint/plugins`: if `vite-plus` now declares a different version, move the exact
|
|
60
|
-
pin to it and reinstall.
|
|
61
|
-
3. Re-run the
|
|
59
|
+
pin to it and reinstall. `rdjperron-lint-verify` fails on that skew before it reaches the rules.
|
|
60
|
+
3. Re-run the check.
|
|
62
61
|
4. Still dead? The rule's AST expectations may have changed under the new oxc version. Read the
|
|
63
|
-
rule in `src
|
|
62
|
+
rule in `src/rules/` or `src/anti-slop/rules/`, fix it, add the case to `tests/`, and release.
|
package/fixtures/{anti-slop/no-known-value-widening.fixture.ts → no-known-value-widening.fixture.ts}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Fixture for
|
|
1
|
+
// Fixture for rdjperron/no-known-value-widening.
|
|
2
2
|
export const retrySettings: unknown = { retries: 3 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Fixture for
|
|
1
|
+
// Fixture for rdjperron/no-module-mocking.
|
|
2
2
|
// `vi` is deliberately left undeclared: the rule's global/unresolved-reference
|
|
3
3
|
// path is what recognises `vi.mock` without importing from "vitest" (which
|
|
4
4
|
// `vite-plus/prefer-vite-plus-imports` forbids in this repo).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Fixture for
|
|
1
|
+
// Fixture for rdjperron/no-reduce-accumulator-copy.
|
|
2
2
|
export function indexById(items: { id: string }[]): Record<string, { id: string }> {
|
|
3
3
|
return items.reduce((acc, item) => Object.assign({}, acc, { [item.id]: item }), {});
|
|
4
4
|
}
|