@rdjperron/lint 0.3.0 → 0.5.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 +179 -63
- package/dist/config-CD2iCM6L.mjs +346 -0
- package/dist/config-CD2iCM6L.mjs.map +1 -0
- package/dist/config.d.mts +109 -11
- package/dist/config.mjs +2 -218
- package/dist/index.mjs +44 -10
- package/dist/index.mjs.map +1 -1
- package/dist/verify.d.mts +1 -92
- package/dist/verify.mjs +124 -256
- package/dist/verify.mjs.map +1 -1
- package/fixtures/README.md +17 -24
- package/package.json +26 -17
- package/dist/config.mjs.map +0 -1
package/dist/verify.d.mts
CHANGED
|
@@ -1,92 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Proof that every lint rule still fires.
|
|
4
|
-
*
|
|
5
|
-
* The linter lives inside the `vp` binary, so it moves independently of any
|
|
6
|
-
* lockfile, and the JS-plugin bridge it loads these rules through is alpha. A
|
|
7
|
-
* rule can stop firing with no diff anywhere, and a dead lint rule is silent:
|
|
8
|
-
* "reports nothing" looks exactly like "no violations". This is the thing that
|
|
9
|
-
* notices.
|
|
10
|
-
*
|
|
11
|
-
* A suite is a directory holding one deliberately-broken `<rule>.fixture.ts(x)`
|
|
12
|
-
* per rule. The check asserts a positive: every rule fired, each on the file
|
|
13
|
-
* named after it.
|
|
14
|
-
*
|
|
15
|
-
* Run the package's own suite from a consumer's repo root:
|
|
16
|
-
*
|
|
17
|
-
* npx rdjperron-lint-verify
|
|
18
|
-
*
|
|
19
|
-
* ---------------------------------------------------------------------------
|
|
20
|
-
* Why the symlink dance
|
|
21
|
-
* ---------------------------------------------------------------------------
|
|
22
|
-
* The fixtures ship inside `node_modules`, which oxlint never walks, and a
|
|
23
|
-
* consumer's own fixture directories are usually in `lint.ignorePatterns` so a
|
|
24
|
-
* plain `vp check` stays quiet. Measured on Vite+ 0.2.9 / oxlint 1.77.0 and
|
|
25
|
-
* again on 0.3.1 / oxlint 1.81.0: no flag re-includes an ignored path.
|
|
26
|
-
* `--no-ignore`, `--ignore-pattern '!<dir>/**'`, an explicit file, an absolute
|
|
27
|
-
* path, a cwd inside the directory and `-W <rule>` all answer "No files found
|
|
28
|
-
* to lint." `--no-ignore` only disables `.eslintignore`, `--ignore-path` and
|
|
29
|
-
* `--ignore-pattern`; it does not touch the config's own `ignorePatterns`, and
|
|
30
|
-
* `vp lint` has no `--config` flag.
|
|
31
|
-
*
|
|
32
|
-
* What does work: oxlint matches ignore patterns against the path it walked,
|
|
33
|
-
* not the realpath. Linting through a symlink outside the ignored prefix
|
|
34
|
-
* reaches the fixtures normally, plugin and all. This creates that view per
|
|
35
|
-
* suite, lints through it, and removes it in a `finally`.
|
|
36
|
-
*
|
|
37
|
-
* The severities cannot come from the command line either: `-A`, `-W` and `-D`
|
|
38
|
-
* reach built-in rules only and leave every JS plugin rule exactly as the config
|
|
39
|
-
* left it (measured on vite-plus 0.3.1 / oxlint 1.81.0, with `vp lint` and with
|
|
40
|
-
* the bare binary). That is why the consumer's config must carry the
|
|
41
|
-
* `fixtures()` override from `@rdjperron/lint/config`.
|
|
42
|
-
*/
|
|
43
|
-
export interface Suite {
|
|
44
|
-
/** The plugin alias the diagnostics carry, e.g. `rdjperron` in `rdjperron(no-reflect-get)`. */
|
|
45
|
-
plugin: string;
|
|
46
|
-
/** The fixture directory, relative to `root`. */
|
|
47
|
-
fixtureDir: string;
|
|
48
|
-
/** Where the un-ignored view is created, relative to `root`. */
|
|
49
|
-
viewDir: string;
|
|
50
|
-
/** Fixture file endings; the part before one of them is the rule name. */
|
|
51
|
-
suffixes?: string[];
|
|
52
|
-
/** Skip the direct path and always lint through the view (fixtures under `node_modules`). */
|
|
53
|
-
alwaysView?: boolean;
|
|
54
|
-
/** Advisory: the rule names the plugin registers, so a new rule without a fixture is named. */
|
|
55
|
-
registeredRules?: () => Promise<string[] | null>;
|
|
56
|
-
/** Where the failure message sends the reader. */
|
|
57
|
-
readme?: string;
|
|
58
|
-
}
|
|
59
|
-
export interface VerifyOptions {
|
|
60
|
-
/** The repo root the paths are relative to and `vp lint` runs from. Defaults to the cwd. */
|
|
61
|
-
root?: string;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Locate the `vp` binary: PATH first, then the default install locations, the
|
|
65
|
-
* XDG layout used since Vite+ 0.3.0 and the pre-0.3.0 single-root layout that
|
|
66
|
-
* upgraded installs keep.
|
|
67
|
-
*/
|
|
68
|
-
export declare function resolveViteplusBinary(): string;
|
|
69
|
-
/**
|
|
70
|
-
* Lint every suite and print one table each. Returns the number of rules that
|
|
71
|
-
* did not fire, so zero means every rule of every suite is alive.
|
|
72
|
-
*/
|
|
73
|
-
export declare function verifySuites(suites: Suite[], options?: VerifyOptions): Promise<number>;
|
|
74
|
-
/**
|
|
75
|
-
* Two promises about the plugin API, held here as a failure instead.
|
|
76
|
-
*
|
|
77
|
-
* - the installed `@oxlint/plugins` is the exact version `vite-plus` declares;
|
|
78
|
-
* - this package's peer range accepts that version.
|
|
79
|
-
*
|
|
80
|
-
* The rules import `@oxlint/plugins`, so the installed one must be the one the
|
|
81
|
-
* linter was built against, or the rules compile against one plugin API and run
|
|
82
|
-
* under another with no error anywhere. Returns the failures, empty when the
|
|
83
|
-
* pins agree or when `vite-plus` is not installed (a consumer on another
|
|
84
|
-
* toolchain has nothing to pin against).
|
|
85
|
-
*/
|
|
86
|
-
export declare function verifyPluginApiPin(root?: string): string[];
|
|
87
|
-
/** The suite for this package's own fixtures, as they sit in a consumer's `node_modules`. */
|
|
88
|
-
export declare function packageSuite(root?: string): Suite;
|
|
89
|
-
/** The bin: this package's suite, plus the plugin API pin, from the consumer's repo root. */
|
|
90
|
-
export declare function main(root?: string): Promise<number>;
|
|
91
|
-
//#endregion
|
|
92
|
-
//# sourceMappingURL=verify.d.mts.map
|
|
1
|
+
export {}
|
package/dist/verify.mjs
CHANGED
|
@@ -1,52 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { s as plugin, t as RULE_IDS } from "./config-CD2iCM6L.mjs";
|
|
2
3
|
import { createRequire } from "node:module";
|
|
3
4
|
import { spawnSync } from "node:child_process";
|
|
4
|
-
import { cpSync, existsSync,
|
|
5
|
-
import {
|
|
5
|
+
import { cpSync, existsSync, mkdtempSync, readdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { join, resolve } from "node:path";
|
|
6
8
|
import { fileURLToPath } from "node:url";
|
|
7
9
|
//#region src/verify.ts
|
|
8
10
|
/**
|
|
9
|
-
* Proof that every
|
|
11
|
+
* Proof that every rule of this plugin still fires.
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* A dead lint rule is silent: "reports nothing" reads exactly like "no
|
|
14
|
+
* violations", so nothing else in a repo notices when a linter upgrade, a
|
|
15
|
+
* JS-plugin API change or an ignore pattern takes a rule out. This lints one
|
|
16
|
+
* deliberately-broken fixture per rule and asserts a positive: every rule fired,
|
|
17
|
+
* each on the file named after it.
|
|
16
18
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* It runs in a throwaway project under the system temp directory: its own
|
|
20
|
+
* generated config with every rule at error, the shipped fixtures copied in, and
|
|
21
|
+
* the caller's `node_modules` symlinked beside them. The caller's own config
|
|
22
|
+
* takes no part, so the answer is about the plugin and the linter alone and a
|
|
23
|
+
* consumer has nothing to write.
|
|
20
24
|
*
|
|
21
|
-
*
|
|
25
|
+
* The linter is the oxlint the LOCAL `vite-plus` depends on, so it follows the
|
|
26
|
+
* lockfile rather than the `vp` on PATH (measured 2026-09-19: a global `vp`
|
|
27
|
+
* 0.3.1 over a local `vite-plus` 0.2.9 ran oxlint 1.77.0). The run that earns
|
|
28
|
+
* this check its place is therefore the commit that moves `vite-plus`, and CI.
|
|
22
29
|
*
|
|
23
30
|
* 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
31
|
*/
|
|
49
|
-
const
|
|
32
|
+
const FIXTURE_SUFFIXES = [".fixture.ts", ".fixture.tsx"];
|
|
33
|
+
/** Relative to this module, so it resolves from `dist/verify.mjs` and from `src/verify.ts` alike. */
|
|
34
|
+
const FIXTURES_DIR = fileURLToPath(new URL("../fixtures", import.meta.url));
|
|
50
35
|
/** Deterministic, locale-independent ordering for the rule and file name lists. */
|
|
51
36
|
function byName(left, right) {
|
|
52
37
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
@@ -67,6 +52,17 @@ function resolveViteplusBinary() {
|
|
|
67
52
|
if (found !== void 0) return found;
|
|
68
53
|
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
54
|
}
|
|
55
|
+
/** The `vite-plus` whose oxlint will run, and the `node_modules` the project borrows. */
|
|
56
|
+
function resolveConsumerModules(root) {
|
|
57
|
+
const modules = join(root, "node_modules");
|
|
58
|
+
if (!existsSync(modules)) throw new Error(`No node_modules in ${root}. Install the dependencies and run this again.`);
|
|
59
|
+
try {
|
|
60
|
+
createRequire(join(root, "package.json")).resolve("vite-plus/package.json");
|
|
61
|
+
} catch {
|
|
62
|
+
throw new Error(`\`vite-plus\` is not installed in ${root}. The linter this check runs is the oxlint the local \`vite-plus\` depends on, so without it there is nothing to prove the rules against.`);
|
|
63
|
+
}
|
|
64
|
+
return modules;
|
|
65
|
+
}
|
|
70
66
|
/**
|
|
71
67
|
* `vp lint -f json` is an outside value, so this is the one place its shape is
|
|
72
68
|
* checked. Anything that does not look like a diagnostic is dropped rather than
|
|
@@ -92,8 +88,8 @@ function decodeReport(json) {
|
|
|
92
88
|
diagnostics
|
|
93
89
|
};
|
|
94
90
|
}
|
|
95
|
-
/** Run `vp lint <target> -f json` from `
|
|
96
|
-
function lintAsJson(binary,
|
|
91
|
+
/** Run `vp lint <target> -f json` from `cwd` and return the decoded report. */
|
|
92
|
+
function lintAsJson(binary, cwd, target) {
|
|
97
93
|
const result = spawnSync(binary, [
|
|
98
94
|
"lint",
|
|
99
95
|
target,
|
|
@@ -101,7 +97,7 @@ function lintAsJson(binary, root, target) {
|
|
|
101
97
|
"json",
|
|
102
98
|
"--no-error-on-unmatched-pattern"
|
|
103
99
|
], {
|
|
104
|
-
cwd
|
|
100
|
+
cwd,
|
|
105
101
|
encoding: "utf8",
|
|
106
102
|
maxBuffer: 67108864
|
|
107
103
|
});
|
|
@@ -116,106 +112,100 @@ function lintAsJson(binary, root, target) {
|
|
|
116
112
|
throw new Error(`Could not read \`vp lint\` JSON output: ${reason}\nstdout: ${stdout}`, { cause });
|
|
117
113
|
}
|
|
118
114
|
}
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
|
|
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;
|
|
115
|
+
/** Rule name to fixture file name, taken from the files that ship with the package. */
|
|
116
|
+
function fixtureFiles() {
|
|
117
|
+
if (!existsSync(FIXTURES_DIR)) throw new Error(`Fixture directory is missing: ${FIXTURES_DIR}`);
|
|
140
118
|
const files = /* @__PURE__ */ new Map();
|
|
141
|
-
for (const name of readdirSync(
|
|
142
|
-
const suffix =
|
|
119
|
+
for (const name of readdirSync(FIXTURES_DIR).toSorted(byName)) {
|
|
120
|
+
const suffix = FIXTURE_SUFFIXES.find((candidate) => name.endsWith(candidate));
|
|
143
121
|
if (suffix === void 0) continue;
|
|
144
122
|
files.set(name.slice(0, -suffix.length), name);
|
|
145
123
|
}
|
|
146
124
|
return files;
|
|
147
125
|
}
|
|
148
|
-
/**
|
|
149
|
-
function
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
126
|
+
/** The throwaway project: a config naming every rule at error, the fixtures, and the modules. */
|
|
127
|
+
function createProject(modules, specifier) {
|
|
128
|
+
const dir = mkdtempSync(join(tmpdir(), "rdjperron-lint-verify-"));
|
|
129
|
+
const rules = Object.fromEntries(RULE_IDS.map((id) => [id, "error"]));
|
|
130
|
+
writeFileSync(join(dir, "package.json"), `${JSON.stringify({
|
|
131
|
+
name: "rdjperron-lint-verify",
|
|
132
|
+
private: true,
|
|
133
|
+
type: "module"
|
|
134
|
+
}, null, 2)}\n`);
|
|
135
|
+
writeFileSync(join(dir, "vite.config.ts"), [
|
|
136
|
+
`import { defineConfig } from "vite-plus";`,
|
|
137
|
+
``,
|
|
138
|
+
`export default defineConfig({`,
|
|
139
|
+
` lint: {`,
|
|
140
|
+
` plugins: [],`,
|
|
141
|
+
` jsPlugins: [${JSON.stringify({
|
|
142
|
+
name: plugin.name,
|
|
143
|
+
specifier
|
|
144
|
+
})}],`,
|
|
145
|
+
` rules: ${JSON.stringify(rules, null, 2).replaceAll("\n", "\n ")},`,
|
|
146
|
+
` },`,
|
|
147
|
+
`});`,
|
|
148
|
+
``
|
|
149
|
+
].join("\n"));
|
|
150
|
+
cpSync(FIXTURES_DIR, join(dir, "fixtures"), { recursive: true });
|
|
151
|
+
symlinkSync(modules, join(dir, "node_modules"), "junction");
|
|
152
|
+
return dir;
|
|
153
|
+
}
|
|
154
|
+
/** `rdjperron(no-reflect-get)` -> `no-reflect-get`; a diagnostic from anything else -> null. */
|
|
155
|
+
function ruleIdFor(code) {
|
|
156
|
+
const match = new RegExp(`^${plugin.name}\\(([^)]+)\\)$`, "u").exec(code);
|
|
157
|
+
return match === null ? null : match[1] ?? null;
|
|
158
|
+
}
|
|
159
|
+
/** The rule names the loaded plugin registers, or null when it cannot be imported. */
|
|
160
|
+
async function registeredRules(specifier) {
|
|
153
161
|
try {
|
|
154
|
-
|
|
155
|
-
return "
|
|
162
|
+
const rules = (await import(specifier)).default?.rules;
|
|
163
|
+
return typeof rules === "object" && rules !== null ? Object.keys(rules).toSorted(byName) : null;
|
|
156
164
|
} catch {
|
|
157
|
-
|
|
158
|
-
return "copy";
|
|
165
|
+
return null;
|
|
159
166
|
}
|
|
160
167
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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;
|
|
168
|
+
/** `--plugin <path>` points the run at a plugin on disk, which is how this repo checks its source. */
|
|
169
|
+
function pluginSpecifier(argv) {
|
|
170
|
+
const index = argv.indexOf("--plugin");
|
|
171
|
+
if (index === -1) return plugin.specifier;
|
|
172
|
+
const value = argv[index + 1];
|
|
173
|
+
if (value === void 0) throw new Error("`--plugin` needs a path to the plugin module.");
|
|
174
|
+
return resolve(value);
|
|
177
175
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const
|
|
176
|
+
async function main(argv) {
|
|
177
|
+
const specifier = pluginSpecifier(argv);
|
|
178
|
+
const binary = resolveViteplusBinary();
|
|
179
|
+
const modules = resolveConsumerModules(process.cwd());
|
|
180
|
+
const files = fixtureFiles();
|
|
181
181
|
const expectedRules = [...files.keys()];
|
|
182
|
-
console.log(`${
|
|
183
|
-
console.log(`
|
|
182
|
+
console.log(`${plugin.name} rule verification`);
|
|
183
|
+
console.log(` plugin: ${specifier}`);
|
|
184
|
+
console.log(` fixtures: ${FIXTURES_DIR}`);
|
|
184
185
|
if (expectedRules.length === 0) {
|
|
185
|
-
console.error(` No fixture files
|
|
186
|
+
console.error(` No fixture files in ${FIXTURES_DIR}. Nothing to verify.\n`);
|
|
186
187
|
return 1;
|
|
187
188
|
}
|
|
188
|
-
|
|
189
|
-
let report
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
} finally {
|
|
199
|
-
removeFixtureView(root, suite);
|
|
200
|
-
}
|
|
189
|
+
const project = createProject(modules, specifier);
|
|
190
|
+
let report;
|
|
191
|
+
try {
|
|
192
|
+
console.log(` project: ${project}`);
|
|
193
|
+
report = lintAsJson(binary, project, "fixtures");
|
|
194
|
+
} finally {
|
|
195
|
+
rmSync(project, {
|
|
196
|
+
recursive: true,
|
|
197
|
+
force: true
|
|
198
|
+
});
|
|
201
199
|
}
|
|
202
|
-
console.log(`
|
|
203
|
-
console.log(` files: ${report.numberOfFiles}`);
|
|
204
|
-
console.log("");
|
|
200
|
+
console.log(` files: ${report.numberOfFiles}\n`);
|
|
205
201
|
if (report.numberOfFiles === 0) {
|
|
206
|
-
|
|
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
|
-
`));
|
|
202
|
+
console.error("FAIL: `vp lint` matched none of the fixtures in the throwaway project.\nNothing there is ignored and the fixtures are copied in, so this is `vp lint` refusing\nthe generated config rather than a rule going quiet.\n");
|
|
213
203
|
return expectedRules.length;
|
|
214
204
|
}
|
|
215
205
|
const firedByRule = /* @__PURE__ */ new Map();
|
|
216
206
|
const foreignDiagnostics = [];
|
|
217
207
|
for (const diagnostic of report.diagnostics) {
|
|
218
|
-
const ruleId = ruleIdFor(
|
|
208
|
+
const ruleId = ruleIdFor(diagnostic.code);
|
|
219
209
|
if (ruleId === null) {
|
|
220
210
|
foreignDiagnostics.push(diagnostic);
|
|
221
211
|
continue;
|
|
@@ -245,156 +235,34 @@ deleted in a \`finally\` block anyway.
|
|
|
245
235
|
}
|
|
246
236
|
console.log("");
|
|
247
237
|
const failures = rows.filter((row) => !row.firedOnOwnFixture);
|
|
248
|
-
console.log(`${rows.length - failures.length}/${rows.length} ${
|
|
249
|
-
const registered =
|
|
238
|
+
console.log(`${rows.length - failures.length}/${rows.length} ${plugin.name} rules fired on their own fixture.`);
|
|
239
|
+
const registered = await registeredRules(specifier);
|
|
250
240
|
if (registered !== null) {
|
|
251
241
|
const missingFixture = registered.filter((rule) => !expectedRules.includes(rule));
|
|
252
242
|
const orphanFixture = expectedRules.filter((rule) => !registered.includes(rule));
|
|
253
|
-
if (missingFixture.length > 0) console.log(`\nWARN: registered by the ${
|
|
254
|
-
if (orphanFixture.length > 0) console.log(`\nWARN: fixture exists but the ${
|
|
243
|
+
if (missingFixture.length > 0) console.log(`\nWARN: registered by the ${plugin.name} plugin but has no fixture: ${missingFixture.join(", ")}`);
|
|
244
|
+
if (orphanFixture.length > 0) console.log(`\nWARN: fixture exists but the ${plugin.name} plugin registers no such rule: ${orphanFixture.join(", ")}`);
|
|
255
245
|
}
|
|
256
246
|
if (foreignDiagnostics.length > 0) {
|
|
257
|
-
console.log(`\nWARN: ${foreignDiagnostics.length} non-${
|
|
247
|
+
console.log(`\nWARN: ${foreignDiagnostics.length} non-${plugin.name} diagnostic(s) in the fixtures:`);
|
|
258
248
|
for (const diagnostic of foreignDiagnostics.slice(0, 20)) console.log(` ${basename(diagnostic.filename)}: ${diagnostic.code}`);
|
|
259
249
|
}
|
|
260
250
|
if (failures.length > 0) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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);
|
|
251
|
+
console.error(`\nFAIL: ${failures.length} ${plugin.name} rule(s) did not fire. See ${join(FIXTURES_DIR, "README.md")}.\nEvery rule was at error in the generated config, so a rule that stayed quiet is one this
|
|
252
|
+
linter did not run, not one this config left off.`);
|
|
253
|
+
return failures.length;
|
|
280
254
|
}
|
|
281
|
-
|
|
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.`);
|
|
255
|
+
console.log(`\nOK: every ${plugin.name} rule still fires.`);
|
|
286
256
|
return 0;
|
|
287
257
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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);
|
|
258
|
+
let exitCode = 1;
|
|
259
|
+
try {
|
|
260
|
+
exitCode = await main(process.argv.slice(2));
|
|
261
|
+
} catch (error) {
|
|
262
|
+
console.error(`\nFAIL: ${error instanceof Error ? error.message : String(error)}`);
|
|
396
263
|
}
|
|
264
|
+
process.exit(exitCode === 0 ? 0 : 1);
|
|
397
265
|
//#endregion
|
|
398
|
-
export {
|
|
266
|
+
export {};
|
|
399
267
|
|
|
400
268
|
//# sourceMappingURL=verify.mjs.map
|