vigiles 41.0.0 → 41.2.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/action.yml +78 -2
- package/dist/cli-flag-check.js +11 -1
- package/dist/cli-main.js +82 -4
- package/dist/core/changed-base.d.ts +34 -0
- package/dist/core/changed-base.js +82 -0
- package/dist/core/config-schema.d.ts +9 -0
- package/dist/core/config-schema.js +7 -0
- package/dist/core/rule-proof/kits/eslint.d.ts +30 -0
- package/dist/core/rule-proof/kits/eslint.js +130 -0
- package/dist/core/rule-proof/kits/index.d.ts +7 -0
- package/dist/core/rule-proof/kits/index.js +12 -0
- package/dist/core/rule-proof/kits/ruff.d.ts +28 -0
- package/dist/core/rule-proof/kits/ruff.js +178 -0
- package/dist/core/rule-proof/node-install.d.ts +32 -0
- package/dist/core/rule-proof/node-install.js +117 -0
- package/dist/core/rule-proof/pair.d.ts +11 -0
- package/dist/core/rule-proof/pair.js +61 -0
- package/dist/core/rule-proof/port.d.ts +77 -0
- package/dist/core/rule-proof/port.js +3 -0
- package/dist/core/rule-proof/report.d.ts +11 -0
- package/dist/core/rule-proof/report.js +36 -0
- package/dist/core/rule-proof/run.d.ts +58 -0
- package/dist/core/rule-proof/run.js +260 -0
- package/dist/core/rule-proof/types.d.ts +119 -0
- package/dist/core/rule-proof/types.js +13 -0
- package/dist/core/test-reach.d.ts +99 -0
- package/dist/core/test-reach.js +725 -0
- package/dist/core/test-selection.d.ts +86 -0
- package/dist/core/test-selection.js +176 -0
- package/dist/entries/rule-proof.d.ts +18 -0
- package/dist/entries/rule-proof.js +23 -0
- package/dist/host/changed-files.io.d.ts +23 -0
- package/dist/host/changed-files.io.js +171 -0
- package/dist/host/rule-proof.io.d.ts +4 -0
- package/dist/host/rule-proof.io.js +64 -0
- package/dist/vigilesrc.schema.json +19 -0
- package/package.json +2 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ruffKit = void 0;
|
|
4
|
+
exports.ruffPin = ruffPin;
|
|
5
|
+
exports.ruffConfigToml = ruffConfigToml;
|
|
6
|
+
exports.parseRuffReport = parseRuffReport;
|
|
7
|
+
/**
|
|
8
|
+
* The Ruff kit: the version the repository pins, run through `uvx`, the
|
|
9
|
+
* reading's settings as the TOML Ruff reads, and `--output-format json` read
|
|
10
|
+
* back as per-file reports.
|
|
11
|
+
*/
|
|
12
|
+
const toml_1 = require("@iarna/toml");
|
|
13
|
+
const js_yaml_1 = require("js-yaml");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const report_js_1 = require("../report.js");
|
|
17
|
+
const lockSchema = zod_1.z.object({
|
|
18
|
+
package: zod_1.z.array(zod_1.z.object({ name: zod_1.z.string(), version: zod_1.z.string() })),
|
|
19
|
+
});
|
|
20
|
+
function fromLock(text) {
|
|
21
|
+
try {
|
|
22
|
+
const lock = lockSchema.safeParse((0, toml_1.parse)(text));
|
|
23
|
+
return lock.success
|
|
24
|
+
? (lock.data.package.find((p) => p.name === "ruff")?.version ?? null)
|
|
25
|
+
: null;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const EXACT = /^\s*ruff\s*==\s*([\w.]+)\s*$/m;
|
|
32
|
+
const exact = (text) => EXACT.exec(text)?.[1] ?? null;
|
|
33
|
+
/** Every string anywhere in a parsed document. */
|
|
34
|
+
function strings(value) {
|
|
35
|
+
if (typeof value === "string")
|
|
36
|
+
return [value];
|
|
37
|
+
if (typeof value !== "object" || value === null)
|
|
38
|
+
return [];
|
|
39
|
+
return Object.values(value).flatMap(strings);
|
|
40
|
+
}
|
|
41
|
+
function fromPyproject(text) {
|
|
42
|
+
try {
|
|
43
|
+
return (strings((0, toml_1.parse)(text))
|
|
44
|
+
.map(exact)
|
|
45
|
+
.find((v) => v !== null) ?? null);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const preCommitSchema = zod_1.z.object({
|
|
52
|
+
repos: zod_1.z.array(zod_1.z.object({ repo: zod_1.z.string(), rev: zod_1.z.string().optional() })),
|
|
53
|
+
});
|
|
54
|
+
function fromPreCommit(text) {
|
|
55
|
+
try {
|
|
56
|
+
const config = preCommitSchema.safeParse((0, js_yaml_1.load)(text));
|
|
57
|
+
const rev = config.success
|
|
58
|
+
? config.data.repos.find((r) => r.repo.endsWith("/ruff-pre-commit"))?.rev
|
|
59
|
+
: undefined;
|
|
60
|
+
return rev === undefined ? null : rev.replace(/^v/, "");
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const LOCKS = ["uv.lock", "poetry.lock", "pdm.lock"];
|
|
67
|
+
const REQUIREMENTS = /^requirements.*\.txt$/;
|
|
68
|
+
const PYPROJECT = "pyproject.toml";
|
|
69
|
+
const PRE_COMMIT = ".pre-commit-config.yaml";
|
|
70
|
+
/**
|
|
71
|
+
* The Ruff version a repository pins, from the files it would come from, most
|
|
72
|
+
* exact first: a lockfile, then `ruff==` in a requirements file or
|
|
73
|
+
* `pyproject.toml`, then the pre-commit hook's `rev`. A ranged requirement is no
|
|
74
|
+
* pin. Keys are file names at the repository root, values their text.
|
|
75
|
+
*/
|
|
76
|
+
function ruffPin(files) {
|
|
77
|
+
const named = (keep) => Object.entries(files)
|
|
78
|
+
.filter(([name]) => keep(name))
|
|
79
|
+
.map(([, text]) => text);
|
|
80
|
+
const candidates = [
|
|
81
|
+
...LOCKS.flatMap((lock) => named((n) => n === lock)).map((t) => () => fromLock(t)),
|
|
82
|
+
...named((n) => REQUIREMENTS.test(n)).map((t) => () => exact(t)),
|
|
83
|
+
...named((n) => n === PYPROJECT).map((t) => () => fromPyproject(t)),
|
|
84
|
+
...named((n) => n === PRE_COMMIT).map((t) => () => fromPreCommit(t)),
|
|
85
|
+
];
|
|
86
|
+
return candidates.reduce((found, next) => found ?? next(), null);
|
|
87
|
+
}
|
|
88
|
+
const isPinFile = (name) => LOCKS.some((lock) => lock === name) ||
|
|
89
|
+
REQUIREMENTS.test(name) ||
|
|
90
|
+
name === PYPROJECT ||
|
|
91
|
+
name === PRE_COMMIT;
|
|
92
|
+
const settingsSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.any());
|
|
93
|
+
/** A reading's settings as the TOML file `--config` reads. */
|
|
94
|
+
function ruffConfigToml(settings) {
|
|
95
|
+
return (0, toml_1.stringify)(settingsSchema.parse(settings));
|
|
96
|
+
}
|
|
97
|
+
const reportSchema = zod_1.z.array(zod_1.z.object({
|
|
98
|
+
code: zod_1.z.string().nullable(),
|
|
99
|
+
filename: zod_1.z.string(),
|
|
100
|
+
message: zod_1.z.string(),
|
|
101
|
+
}));
|
|
102
|
+
/** How each Ruff version spells "this file did not parse". */
|
|
103
|
+
const PARSE_CODES = new Set([
|
|
104
|
+
null,
|
|
105
|
+
"E999",
|
|
106
|
+
"invalid-syntax",
|
|
107
|
+
"syntax-error",
|
|
108
|
+
]);
|
|
109
|
+
/**
|
|
110
|
+
* Ruff's `--output-format json` as per-file reports. Ruff lists diagnostics,
|
|
111
|
+
* not files, so the files passed in are the denominator: one with no
|
|
112
|
+
* diagnostic was linted and is clean.
|
|
113
|
+
*/
|
|
114
|
+
function parseRuffReport(stdout, dir, files, rule) {
|
|
115
|
+
const parsed = reportSchema.safeParse((0, report_js_1.jsonArray)(stdout));
|
|
116
|
+
if (!parsed.success)
|
|
117
|
+
return (0, report_js_1.unreadable)(stdout);
|
|
118
|
+
const diags = parsed.data.map((d) => ({
|
|
119
|
+
...d,
|
|
120
|
+
path: (0, report_js_1.toRelative)(dir, d.filename),
|
|
121
|
+
}));
|
|
122
|
+
return {
|
|
123
|
+
kind: "parsed",
|
|
124
|
+
files: files.map((path) => {
|
|
125
|
+
const own = diags.filter((d) => d.path === path);
|
|
126
|
+
const broken = own.find((d) => PARSE_CODES.has(d.code));
|
|
127
|
+
if (broken !== undefined)
|
|
128
|
+
return { path, kind: "parse-error", message: broken.message };
|
|
129
|
+
return {
|
|
130
|
+
path,
|
|
131
|
+
kind: "linted",
|
|
132
|
+
hits: own.filter((d) => d.code === rule).length,
|
|
133
|
+
};
|
|
134
|
+
}),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
exports.ruffKit = {
|
|
138
|
+
linter: "ruff",
|
|
139
|
+
plan(root) {
|
|
140
|
+
const pins = root.names.filter(isPinFile);
|
|
141
|
+
const version = ruffPin(Object.fromEntries(pins.map((n) => [n, root.read(n) ?? ""])));
|
|
142
|
+
if (version === null)
|
|
143
|
+
return {
|
|
144
|
+
kind: "none",
|
|
145
|
+
stage: "no-pin",
|
|
146
|
+
reason: "no exact Ruff pin in a lockfile, requirements, pyproject.toml or pre-commit",
|
|
147
|
+
};
|
|
148
|
+
const tool = `ruff@${version}`;
|
|
149
|
+
return {
|
|
150
|
+
kind: "plan",
|
|
151
|
+
install: ["uvx", tool, "--version"],
|
|
152
|
+
command: () => ["uvx", tool],
|
|
153
|
+
version: () => version,
|
|
154
|
+
missing: "",
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
env: (cacheDir) => ({ UV_CACHE_DIR: node_path_1.posix.join(cacheDir, "uv") }),
|
|
158
|
+
// The config sits in the repository, so a relative `extend` in the settings
|
|
159
|
+
// resolves against the repository as it would in the repository's own file.
|
|
160
|
+
invocation: (reading, files, { dir }) => {
|
|
161
|
+
const configPath = (0, node_path_1.join)(dir, ".vigiles-rule-proof.ruff.toml");
|
|
162
|
+
return {
|
|
163
|
+
configPath,
|
|
164
|
+
configText: ruffConfigToml(reading.settings),
|
|
165
|
+
args: [
|
|
166
|
+
...["check", "--no-cache", "--output-format", "json", "--exit-zero"],
|
|
167
|
+
// A reading's own settings may not change WHAT is measured: with
|
|
168
|
+
// `force-exclude` an excluded twin vanishes from the report and would
|
|
169
|
+
// read clean, and with `fix` the planted violation is rewritten away.
|
|
170
|
+
...["--no-force-exclude", "--no-fix"],
|
|
171
|
+
...["--select", reading.rule, "--config", configPath, ...files],
|
|
172
|
+
],
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
reportCodes: [0],
|
|
176
|
+
parse: (stdout, files, reading, dir) => parseRuffReport(stdout, dir, files, reading.rule),
|
|
177
|
+
};
|
|
178
|
+
//# sourceMappingURL=ruff.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** What a repository says about its Node package manager. */
|
|
2
|
+
export interface NodeInstallFacts {
|
|
3
|
+
/** Entry names at the repository root (lockfiles among them). */
|
|
4
|
+
readonly lockfiles: readonly string[];
|
|
5
|
+
/** The `packageManager` field of the root `package.json`, if any. */
|
|
6
|
+
readonly packageManager?: string;
|
|
7
|
+
}
|
|
8
|
+
/** The install command, or why there is none. */
|
|
9
|
+
export type NodeInstallPlan = {
|
|
10
|
+
readonly kind: "plan";
|
|
11
|
+
readonly install: readonly [string, ...string[]];
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: "none";
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The install for a Node repository. No lockfile is no plan: an install without
|
|
18
|
+
* one would not reproduce the repository's linter version, which is the point
|
|
19
|
+
* of installing at all.
|
|
20
|
+
*/
|
|
21
|
+
export declare function nodeInstallPlan(facts: NodeInstallFacts): NodeInstallPlan;
|
|
22
|
+
/** The `packageManager` field of a `package.json` text, if it has one. */
|
|
23
|
+
export declare function packageManagerIn(text: string | null): string | undefined;
|
|
24
|
+
/** The `version` of a package's `package.json` text, or null. */
|
|
25
|
+
export declare function versionIn(text: string | null): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Every Node package manager's cache under `cacheDir`: one hand-written copy of
|
|
28
|
+
* this filled the root disk with a 6.8 GB yarn cache, and Yarn Berry and bun
|
|
29
|
+
* ignore `npm_config_cache`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function nodeCacheEnv(cacheDir: string): Readonly<Record<string, string>>;
|
|
32
|
+
//# sourceMappingURL=node-install.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nodeInstallPlan = nodeInstallPlan;
|
|
4
|
+
exports.packageManagerIn = packageManagerIn;
|
|
5
|
+
exports.versionIn = versionIn;
|
|
6
|
+
exports.nodeCacheEnv = nodeCacheEnv;
|
|
7
|
+
/**
|
|
8
|
+
* How a Node repository installs its pinned dependencies: the lockfile says
|
|
9
|
+
* which tool, `packageManager` decides between two and pins the tool's version.
|
|
10
|
+
* Shared by every kit whose linter ships through npm.
|
|
11
|
+
*/
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const LOCKFILE_TOOL = {
|
|
15
|
+
"package-lock.json": "npm",
|
|
16
|
+
"npm-shrinkwrap.json": "npm",
|
|
17
|
+
"pnpm-lock.yaml": "pnpm",
|
|
18
|
+
"yarn.lock": "yarn",
|
|
19
|
+
"bun.lock": "bun",
|
|
20
|
+
"bun.lockb": "bun",
|
|
21
|
+
};
|
|
22
|
+
const NO_SCRIPTS = "--ignore-scripts";
|
|
23
|
+
const FROZEN = "--frozen-lockfile";
|
|
24
|
+
/** The install arguments per tool; `as` is the tool spelled with its pin. */
|
|
25
|
+
const INSTALL_ARGS = {
|
|
26
|
+
npm: () => ["ci", NO_SCRIPTS, "--no-audit", "--no-fund"],
|
|
27
|
+
pnpm: (as) => [as, "install", FROZEN, NO_SCRIPTS],
|
|
28
|
+
yarn: (as, berry) => berry
|
|
29
|
+
? [as, "install", "--immutable", "--mode=skip-build"]
|
|
30
|
+
: [as, "install", FROZEN, NO_SCRIPTS, "--non-interactive"],
|
|
31
|
+
bun: (as) => ["--yes", as, "install", FROZEN, NO_SCRIPTS],
|
|
32
|
+
};
|
|
33
|
+
const INSTALL_COMMAND = {
|
|
34
|
+
npm: "npm",
|
|
35
|
+
pnpm: "corepack",
|
|
36
|
+
yarn: "corepack",
|
|
37
|
+
bun: "npx",
|
|
38
|
+
};
|
|
39
|
+
/** Yarn 1 when unpinned: corepack would otherwise pick the newest (Berry). */
|
|
40
|
+
const UNPINNED = {
|
|
41
|
+
npm: "npm",
|
|
42
|
+
pnpm: "pnpm",
|
|
43
|
+
yarn: "yarn@1",
|
|
44
|
+
bun: "bun",
|
|
45
|
+
};
|
|
46
|
+
function planFor(tool, version) {
|
|
47
|
+
const as = version === undefined ? UNPINNED[tool] : `${tool}@${version}`;
|
|
48
|
+
const berry = version !== undefined && !version.startsWith("1.");
|
|
49
|
+
return {
|
|
50
|
+
kind: "plan",
|
|
51
|
+
install: [INSTALL_COMMAND[tool], ...INSTALL_ARGS[tool](as, berry)],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The install for a Node repository. No lockfile is no plan: an install without
|
|
56
|
+
* one would not reproduce the repository's linter version, which is the point
|
|
57
|
+
* of installing at all.
|
|
58
|
+
*/
|
|
59
|
+
function nodeInstallPlan(facts) {
|
|
60
|
+
const tools = facts.lockfiles.flatMap((f) => {
|
|
61
|
+
const tool = LOCKFILE_TOOL[f];
|
|
62
|
+
return tool === undefined ? [] : [tool];
|
|
63
|
+
});
|
|
64
|
+
const pm = /^([^@]+)@([^+]+)/.exec(facts.packageManager ?? "");
|
|
65
|
+
const declared = tools.find((t) => t === pm?.[1]);
|
|
66
|
+
const tool = declared ?? tools[0];
|
|
67
|
+
if (tool === undefined)
|
|
68
|
+
return {
|
|
69
|
+
kind: "none",
|
|
70
|
+
reason: "no lockfile: the linter version would not be the repository's",
|
|
71
|
+
};
|
|
72
|
+
return planFor(tool, declared === undefined ? undefined : pm?.[2]);
|
|
73
|
+
}
|
|
74
|
+
const packageJsonSchema = zod_1.z.object({ packageManager: zod_1.z.string().optional() });
|
|
75
|
+
/** The `packageManager` field of a `package.json` text, if it has one. */
|
|
76
|
+
function packageManagerIn(text) {
|
|
77
|
+
try {
|
|
78
|
+
const parsed = packageJsonSchema.safeParse(JSON.parse(text ?? "{}"));
|
|
79
|
+
return parsed.success ? parsed.data.packageManager : undefined;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const versionSchema = zod_1.z.object({ version: zod_1.z.string() });
|
|
86
|
+
/** The `version` of a package's `package.json` text, or null. */
|
|
87
|
+
function versionIn(text) {
|
|
88
|
+
try {
|
|
89
|
+
const parsed = versionSchema.safeParse(JSON.parse(text ?? "null"));
|
|
90
|
+
return parsed.success ? parsed.data.version : null;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Every Node package manager's cache under `cacheDir`: one hand-written copy of
|
|
98
|
+
* this filled the root disk with a 6.8 GB yarn cache, and Yarn Berry and bun
|
|
99
|
+
* ignore `npm_config_cache`.
|
|
100
|
+
*/
|
|
101
|
+
function nodeCacheEnv(cacheDir) {
|
|
102
|
+
const at = (name) => node_path_1.posix.join(cacheDir, name);
|
|
103
|
+
return {
|
|
104
|
+
npm_config_cache: at("npm"),
|
|
105
|
+
npm_config_store_dir: at("pnpm"),
|
|
106
|
+
YARN_CACHE_FOLDER: at("yarn"),
|
|
107
|
+
YARN_GLOBAL_FOLDER: at("yarn-global"),
|
|
108
|
+
COREPACK_HOME: at("corepack"),
|
|
109
|
+
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
|
|
110
|
+
BUN_INSTALL_CACHE_DIR: at("bun"),
|
|
111
|
+
// Yarn Berry's default Plug'n'Play leaves no node_modules, so the linter
|
|
112
|
+
// and its version could not be found where every other tool puts them.
|
|
113
|
+
// The lockfile, not the linker, pins the versions.
|
|
114
|
+
YARN_NODE_LINKER: "node-modules",
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=node-install.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FileReport, Flagged, PairVerdict, ReadingScope } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Is `path` (relative, `/`-separated) in the scope? Dot files match, as they do
|
|
4
|
+
* in a linter's own `files` patterns.
|
|
5
|
+
*/
|
|
6
|
+
export declare function inScope(path: string, scope: ReadingScope): boolean;
|
|
7
|
+
/** Proved only when the bad file is flagged AND its twin is not. */
|
|
8
|
+
export declare function judgePair(bad: FileReport, good: FileReport): PairVerdict;
|
|
9
|
+
/** Split per-file reports into the three lists, each sorted. */
|
|
10
|
+
export declare function summarize(files: readonly FileReport[]): Flagged;
|
|
11
|
+
//# sourceMappingURL=pair.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inScope = inScope;
|
|
4
|
+
exports.judgePair = judgePair;
|
|
5
|
+
exports.summarize = summarize;
|
|
6
|
+
/**
|
|
7
|
+
* What every linter's proof shares: the scope test, the verdict on a planted
|
|
8
|
+
* pair, and the split of per-file reports into the lists a run returns.
|
|
9
|
+
*/
|
|
10
|
+
const minimatch_1 = require("minimatch");
|
|
11
|
+
const MATCH = { dot: true };
|
|
12
|
+
/**
|
|
13
|
+
* Is `path` (relative, `/`-separated) in the scope? Dot files match, as they do
|
|
14
|
+
* in a linter's own `files` patterns.
|
|
15
|
+
*/
|
|
16
|
+
function inScope(path, scope) {
|
|
17
|
+
const matches = (p) => (0, minimatch_1.minimatch)(path, p, MATCH);
|
|
18
|
+
return scope.files.some(matches) && !scope.ignores.some(matches);
|
|
19
|
+
}
|
|
20
|
+
/** A planted file's hits, or why it gives no verdict. */
|
|
21
|
+
function hitsOf(file) {
|
|
22
|
+
if (file.kind === "parse-error")
|
|
23
|
+
return {
|
|
24
|
+
kind: "not-run",
|
|
25
|
+
stage: "parse",
|
|
26
|
+
reason: `${file.path}: ${file.message}`,
|
|
27
|
+
};
|
|
28
|
+
if (file.kind === "ignored")
|
|
29
|
+
return {
|
|
30
|
+
kind: "not-run",
|
|
31
|
+
stage: "pair-ignored",
|
|
32
|
+
reason: `${file.path}: the linter ignored the planted file`,
|
|
33
|
+
};
|
|
34
|
+
return file.hits;
|
|
35
|
+
}
|
|
36
|
+
/** Proved only when the bad file is flagged AND its twin is not. */
|
|
37
|
+
function judgePair(bad, good) {
|
|
38
|
+
const badHits = hitsOf(bad);
|
|
39
|
+
if (typeof badHits !== "number")
|
|
40
|
+
return badHits;
|
|
41
|
+
const goodHits = hitsOf(good);
|
|
42
|
+
if (typeof goodHits !== "number")
|
|
43
|
+
return goodHits;
|
|
44
|
+
return badHits > 0 && goodHits === 0
|
|
45
|
+
? { kind: "proved" }
|
|
46
|
+
: { kind: "not-proved", badHits, goodHits };
|
|
47
|
+
}
|
|
48
|
+
/** Split per-file reports into the three lists, each sorted. */
|
|
49
|
+
function summarize(files) {
|
|
50
|
+
const paths = (keep) => files
|
|
51
|
+
.filter(keep)
|
|
52
|
+
.map((f) => f.path)
|
|
53
|
+
.sort((a, b) => a.localeCompare(b));
|
|
54
|
+
return {
|
|
55
|
+
linted: files.filter((f) => f.kind === "linted").length,
|
|
56
|
+
flagged: paths((f) => f.kind === "linted" && f.hits > 0),
|
|
57
|
+
parseErrors: paths((f) => f.kind === "parse-error"),
|
|
58
|
+
ignored: paths((f) => f.kind === "ignored"),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=pair.js.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two ports of `experimental_ruleProof`.
|
|
3
|
+
*
|
|
4
|
+
* {@link RuleProofHost} is every effect the steps need from the machine; the
|
|
5
|
+
* host adapter (`src/host/rule-proof.io.ts`) implements it. {@link ProofKit} is
|
|
6
|
+
* everything the steps need to know about ONE linter; each kit is a module in
|
|
7
|
+
* `./kits/`, and the set is assembled there and handed in by the entry root. The
|
|
8
|
+
* steps (`./run.ts`) know neither a machine nor a linter by name.
|
|
9
|
+
*/
|
|
10
|
+
import type { BaseReading, ExecOptions, ExecResult, LintParse } from "./types.js";
|
|
11
|
+
/** Every effect rule-proof needs. Paths are absolute unless a member says otherwise. */
|
|
12
|
+
export interface RuleProofHost {
|
|
13
|
+
readonly exec: (command: string, args: readonly string[], options: ExecOptions) => ExecResult;
|
|
14
|
+
/** A file's text, or null when it is absent or unreadable. */
|
|
15
|
+
readonly read: (path: string) => string | null;
|
|
16
|
+
readonly exists: (path: string) => boolean;
|
|
17
|
+
/** Entry names directly in `dir`. */
|
|
18
|
+
readonly list: (dir: string) => readonly string[];
|
|
19
|
+
/** Write a file, making its parent directories. */
|
|
20
|
+
readonly write: (path: string, text: string) => void;
|
|
21
|
+
/** Remove a file or a directory tree; absent is fine. */
|
|
22
|
+
readonly remove: (path: string) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Files under `dir` matching `patterns`: relative, `/`-separated, never
|
|
25
|
+
* inside node_modules or .git.
|
|
26
|
+
*/
|
|
27
|
+
readonly files: (dir: string, patterns: readonly string[]) => readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/** What a kit may look at in a repository's root before installing. */
|
|
30
|
+
export interface RootView {
|
|
31
|
+
/** Entry names at the root. */
|
|
32
|
+
readonly names: readonly string[];
|
|
33
|
+
/** A root file's text by name, or null. */
|
|
34
|
+
readonly read: (name: string) => string | null;
|
|
35
|
+
}
|
|
36
|
+
/** How to install a linter at the repository's pinned version, or why that is impossible. */
|
|
37
|
+
export type KitPlan = {
|
|
38
|
+
readonly kind: "plan";
|
|
39
|
+
/** The install command and its arguments, run in the repository. */
|
|
40
|
+
readonly install: readonly [string, ...string[]];
|
|
41
|
+
/** The argv prefix that runs the linter once installed. */
|
|
42
|
+
readonly command: (dir: string) => readonly string[];
|
|
43
|
+
/** The installed version, given a reader of repository-relative files; null when absent. */
|
|
44
|
+
readonly version: (read: (path: string) => string | null) => string | null;
|
|
45
|
+
/** What to say when `version` finds nothing after the install. */
|
|
46
|
+
readonly missing: string;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: "none";
|
|
49
|
+
readonly stage: "no-lockfile" | "no-pin";
|
|
50
|
+
readonly reason: string;
|
|
51
|
+
};
|
|
52
|
+
/** One lint call: the config file to write, and the arguments after the command. */
|
|
53
|
+
export interface Invocation {
|
|
54
|
+
readonly configPath: string;
|
|
55
|
+
readonly configText: string;
|
|
56
|
+
readonly args: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
/** Where a lint call runs and where its scratch files go. */
|
|
59
|
+
export interface Places {
|
|
60
|
+
readonly dir: string;
|
|
61
|
+
readonly cacheDir: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Everything the steps need to know about one linter. Methods, not function
|
|
65
|
+
* properties: a kit of a narrower reading is still a kit.
|
|
66
|
+
*/
|
|
67
|
+
export interface ProofKit<R extends BaseReading> {
|
|
68
|
+
readonly linter: R["linter"];
|
|
69
|
+
plan(root: RootView): KitPlan;
|
|
70
|
+
/** Environment that keeps this linter's tools' caches under `cacheDir`. */
|
|
71
|
+
env(cacheDir: string): Readonly<Record<string, string>>;
|
|
72
|
+
invocation(reading: R, files: readonly string[], places: Places): Invocation;
|
|
73
|
+
/** Exit codes after which stdout holds a report. Any other is `config-load`. */
|
|
74
|
+
readonly reportCodes: readonly number[];
|
|
75
|
+
parse(stdout: string, files: readonly string[], reading: R, dir: string): LintParse;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=port.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LintParse } from "./types.js";
|
|
2
|
+
/** `file` relative to `dir`, `/`-separated. */
|
|
3
|
+
export declare const toRelative: (dir: string, file: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* The JSON array in a linter's stdout. A plugin may print banner lines first,
|
|
6
|
+
* so the array starts at the first line that opens one.
|
|
7
|
+
*/
|
|
8
|
+
export declare function jsonArray(stdout: string): unknown;
|
|
9
|
+
/** Output that is not the report: never an empty list. */
|
|
10
|
+
export declare const unreadable: (stdout: string) => LintParse;
|
|
11
|
+
//# sourceMappingURL=report.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unreadable = exports.toRelative = void 0;
|
|
4
|
+
exports.jsonArray = jsonArray;
|
|
5
|
+
/**
|
|
6
|
+
* Helpers every kit uses to read its linter's JSON report: the array after any
|
|
7
|
+
* banner lines, paths made repository-relative, and the one shape an unreadable
|
|
8
|
+
* report takes.
|
|
9
|
+
*/
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
/** `file` relative to `dir`, `/`-separated. */
|
|
12
|
+
const toRelative = (dir, file) => (0, node_path_1.relative)(dir, file).split(node_path_1.sep).join(node_path_1.posix.sep);
|
|
13
|
+
exports.toRelative = toRelative;
|
|
14
|
+
/**
|
|
15
|
+
* The JSON array in a linter's stdout. A plugin may print banner lines first,
|
|
16
|
+
* so the array starts at the first line that opens one.
|
|
17
|
+
*/
|
|
18
|
+
function jsonArray(stdout) {
|
|
19
|
+
const start = stdout.search(/^\[/m);
|
|
20
|
+
if (start === -1)
|
|
21
|
+
return undefined;
|
|
22
|
+
try {
|
|
23
|
+
const value = JSON.parse(stdout.slice(start));
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Output that is not the report: never an empty list. */
|
|
31
|
+
const unreadable = (stdout) => ({
|
|
32
|
+
kind: "unreadable",
|
|
33
|
+
reason: `no JSON report in the linter's output: ${stdout.slice(0, 200)}`,
|
|
34
|
+
});
|
|
35
|
+
exports.unreadable = unreadable;
|
|
36
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ProofKit, RuleProofHost } from "./port.js";
|
|
2
|
+
import type { BaseReading, FlaggedRun, InstallOptions, NotInstalled, NotRun, PlantedPair } from "./types.js";
|
|
3
|
+
type Settled = Required<InstallOptions>;
|
|
4
|
+
/** A repository's own linter at its pinned version. Only `install` makes one. */
|
|
5
|
+
export declare class PinnedLinter<R extends BaseReading> {
|
|
6
|
+
readonly linter: R["linter"];
|
|
7
|
+
readonly version: string;
|
|
8
|
+
readonly dir: string;
|
|
9
|
+
/** @internal the kit, the argv prefix that runs the linter, the settled options */
|
|
10
|
+
readonly run: {
|
|
11
|
+
readonly kit: ProofKit<R>;
|
|
12
|
+
readonly command: readonly string[];
|
|
13
|
+
readonly options: Settled;
|
|
14
|
+
};
|
|
15
|
+
private readonly brand;
|
|
16
|
+
/** @internal */
|
|
17
|
+
constructor(linter: R["linter"], version: string, dir: string,
|
|
18
|
+
/** @internal the kit, the argv prefix that runs the linter, the settled options */
|
|
19
|
+
run: {
|
|
20
|
+
readonly kit: ProofKit<R>;
|
|
21
|
+
readonly command: readonly string[];
|
|
22
|
+
readonly options: Settled;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** A reading that passed its planted pair on one PinnedLinter. Only `prove` makes one. */
|
|
26
|
+
export declare class ProvedReading<R extends BaseReading> {
|
|
27
|
+
readonly pinned: PinnedLinter<R>;
|
|
28
|
+
readonly reading: R;
|
|
29
|
+
private readonly brand;
|
|
30
|
+
/** @internal */
|
|
31
|
+
constructor(pinned: PinnedLinter<R>, reading: R);
|
|
32
|
+
}
|
|
33
|
+
/** The install's outcome. */
|
|
34
|
+
export type Installed<R extends BaseReading> = {
|
|
35
|
+
readonly kind: "installed";
|
|
36
|
+
readonly linter: PinnedLinter<R>;
|
|
37
|
+
} | NotInstalled;
|
|
38
|
+
/** The verdict on one reading's planted pair. */
|
|
39
|
+
export type Proof<R extends BaseReading> = {
|
|
40
|
+
readonly kind: "proved";
|
|
41
|
+
readonly reading: ProvedReading<R>;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: "not-proved";
|
|
44
|
+
readonly badHits: number;
|
|
45
|
+
readonly goodHits: number;
|
|
46
|
+
} | NotRun;
|
|
47
|
+
/** A kit set keyed by linter name, each kit typed by its own reading. */
|
|
48
|
+
export type KitSet<M extends Record<string, BaseReading>> = {
|
|
49
|
+
readonly [N in keyof M]: ProofKit<M[N]>;
|
|
50
|
+
};
|
|
51
|
+
/** The three steps over one host and one kit set. */
|
|
52
|
+
export declare function ruleProofWith<M extends Record<string, BaseReading>>(host: RuleProofHost, kits: KitSet<M>): {
|
|
53
|
+
install: <N extends keyof M>(linter: N, dir: string, options: InstallOptions) => Installed<M[N]>;
|
|
54
|
+
prove: <R extends BaseReading>(pinned: PinnedLinter<R>, reading: NoInfer<R>, pair: PlantedPair) => Proof<R>;
|
|
55
|
+
flagged: <R extends BaseReading>(proved: ProvedReading<R>) => FlaggedRun;
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=run.d.ts.map
|