@antelopejs/tooling-configs 0.7.3 → 0.7.5-next.356.g0d472b3
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 +63 -80
- package/dist/bin/api-diff.mjs +29 -49
- package/dist/bin/capture.mjs +4 -4
- package/dist/bin/check-size.mjs +12 -3
- package/dist/bin/checks.mjs +2 -2
- package/dist/bin/comment-proof.mjs +3 -4
- package/dist/bin/garden.mjs +45 -170
- package/dist/bin/readme-strip.mjs +2 -2
- package/dist/bin/suppressions.mjs +212 -9
- package/dist/bin/sync.mjs +318 -210
- package/dist/bin/tsc.mjs +24 -0
- package/dist/bin/verify.mjs +91 -671
- package/dist/{checks-CSlWvky1.mjs → checks-C60vMFin.mjs} +155 -310
- package/dist/{docs-compat-BAZiPLZt.mjs → docs-compat-CdgBviGf.mjs} +2 -2
- package/dist/eslint.mjs +1 -1
- package/dist/{files-C-JJhExM.mjs → files-BbzJEk-L.mjs} +5 -4
- package/dist/formal/index.mjs +1 -1
- package/dist/{guardrails-nj7NTglr.mjs → guardrails-Dron1AbR.mjs} +67 -673
- package/dist/{installed-typescript-6MtIWlE4.mjs → installed-typescript-CF_FR9DV.mjs} +17 -17
- package/dist/{map-BYkmnvNw.mjs → map-CbNbypUa.mjs} +2 -2
- package/dist/oxc/anti-slop/index.mjs +22 -964
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +1 -1
- package/dist/oxc/lint.d.mts +2 -14
- package/dist/oxc/lint.mjs +3 -20
- package/dist/{package-DDG3YH7W.mjs → package-7oylgBeT.mjs} +6 -19
- package/dist/{workflow-C-oBwL2H.mjs → renovate-D0su_v9p.mjs} +191 -91
- package/dist/{suppression-budget-CPDSFg4X.mjs → suppression-budget-De9nUzlD.mjs} +33 -13
- package/dist/{suppressions-CxPnh4sC.mjs → suppressions-CfJwL0fN.mjs} +6 -2
- package/dist/{templates-HG0fel2S.mjs → templates-DLW0Ubfk.mjs} +26 -29
- package/dist/typescript-C7eU-cig.mjs +581 -0
- package/dist/typescript-version-CptQKjGz.mjs +18 -0
- package/dist/typescript6-BWqCcXGY.mjs +2 -0
- package/dist/typescript6-HdyOMBv3.mjs +8 -0
- package/dist/verify/index.d.mts +5 -24
- package/package.json +27 -7
- package/dist/bin/body-check.mjs +0 -350
- package/dist/bin/ratchet.d.mts +0 -1
- package/dist/bin/ratchet.mjs +0 -375
- package/dist/ceilings-B7KayYIG.mjs +0 -76
- package/dist/oxlint-CIeonWMB.mjs +0 -133
- package/dist/proof-stamp-BFV7JTZT.mjs +0 -342
- package/dist/ratchet-DLCfeaPY.mjs +0 -453
- package/dist/renames-L2owF5GD.mjs +0 -59
- package/dist/size-CCGLY4Ke.mjs +0 -18
- package/dist/suppression-base-CYaLZAq7.mjs +0 -120
- package/dist/typescript-QfxkJYzd.mjs +0 -292
- /package/dist/bin/{body-check.d.mts → tsc.d.mts} +0 -0
|
@@ -1,14 +1,104 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
3
|
-
import { c as
|
|
4
|
-
import {
|
|
5
|
-
import { c as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { join, posix } from "node:path";
|
|
3
|
+
import { a as isAgentFile, c as resolveRevision, n as changedFiles, o as repositoryPath, s as repositoryRoot } from "../files-BbzJEk-L.mjs";
|
|
4
|
+
import { a as parseBudget, c as stagedSuppressions, i as checkSuppressions, l as checkPolicy, n as SUPPRESSIONS_FILE, o as safetyCeiling, s as stagedNames, u as coveredLimits } from "../suppression-budget-De9nUzlD.mjs";
|
|
5
|
+
import { c as suppressionsIn, i as inWorktree, o as revisionSuppressions, r as countSuppressions } from "../suppressions-CfJwL0fN.mjs";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import { mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { basename, dirname, join, posix } from "node:path";
|
|
10
9
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
11
10
|
import { parseArgs } from "node:util";
|
|
11
|
+
//#region src/guardrails/oxlint.ts
|
|
12
|
+
function resolveOxlint(root) {
|
|
13
|
+
try {
|
|
14
|
+
const require = createRequire(join(root, "package.json"));
|
|
15
|
+
return join(dirname(require.resolve("oxlint/package.json")), "bin/oxlint");
|
|
16
|
+
} catch {
|
|
17
|
+
throw new Error("oxlint is not installed in this repository. Install dependencies first.");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const NO_FILES = "No files found to lint.";
|
|
21
|
+
const PLUGIN_ERROR = "Error running JS plugin.";
|
|
22
|
+
/** Whether oxlint matched no file, in which case it prints a notice before its report and exits 1. */
|
|
23
|
+
function foundNoFiles(stdout) {
|
|
24
|
+
return stdout.startsWith(NO_FILES) && stdout.includes("{");
|
|
25
|
+
}
|
|
26
|
+
/** The `-f json` report in oxlint's stdout, or undefined when oxlint printed an error in its place. */
|
|
27
|
+
function parseReport(text) {
|
|
28
|
+
const json = foundNoFiles(text) ? text.slice(text.indexOf("{")) : text;
|
|
29
|
+
if (!json.startsWith("{")) return void 0;
|
|
30
|
+
const report = JSON.parse(json);
|
|
31
|
+
if (!Array.isArray(report?.diagnostics)) throw new Error("oxlint did not return a JSON diagnostics array.");
|
|
32
|
+
return report.diagnostics;
|
|
33
|
+
}
|
|
34
|
+
function runOxlint(root, config, files, flags) {
|
|
35
|
+
const binary = resolveOxlint(root);
|
|
36
|
+
const temporary = config === void 0 ? void 0 : mkdtempSync(join(root, ".antelopejs-measure.generated."));
|
|
37
|
+
try {
|
|
38
|
+
const args = [
|
|
39
|
+
binary,
|
|
40
|
+
"-f",
|
|
41
|
+
"json",
|
|
42
|
+
...flags
|
|
43
|
+
];
|
|
44
|
+
if (temporary) {
|
|
45
|
+
const path = join(temporary, "oxlint.config.ts");
|
|
46
|
+
writeFileSync(path, config ?? "");
|
|
47
|
+
args.push("--config", path, "--ignore-pattern", `${basename(temporary)}/**`);
|
|
48
|
+
}
|
|
49
|
+
if (files) args.push("--no-error-on-unmatched-pattern", "--", ...files);
|
|
50
|
+
const result = spawnSync(process.execPath, args, {
|
|
51
|
+
cwd: root,
|
|
52
|
+
encoding: "utf8",
|
|
53
|
+
maxBuffer: 67108864
|
|
54
|
+
});
|
|
55
|
+
if (result.error) throw result.error;
|
|
56
|
+
if (result.status !== 0 && result.status !== 1) throw new Error(`oxlint failed (${result.status ?? result.signal}): ${result.stderr || result.stdout}`);
|
|
57
|
+
const diagnostics = parseReport(result.stdout);
|
|
58
|
+
if (diagnostics === void 0) throw new Error(`oxlint failed (exit ${result.status}): ${result.stdout}${result.stderr}`.trimEnd());
|
|
59
|
+
if (result.status !== 0 && diagnostics.length === 0 && !foundNoFiles(result.stdout)) throw new Error(`oxlint failed without diagnostics: ${result.stderr || result.stdout}`);
|
|
60
|
+
const crash = diagnostics.find(({ code, message }) => code === void 0 && message.startsWith(PLUGIN_ERROR));
|
|
61
|
+
if (crash) throw new Error(crash.message);
|
|
62
|
+
return diagnostics;
|
|
63
|
+
} finally {
|
|
64
|
+
if (temporary) rmSync(temporary, {
|
|
65
|
+
recursive: true,
|
|
66
|
+
force: true
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const UNUSED_RULES = /\(no problems were reported from (.+)\)/u;
|
|
71
|
+
function isUnusedDirective(message) {
|
|
72
|
+
return message.startsWith("Unused ") && message.includes("-disable directive");
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The disable directives in `files` that suppress nothing and the files
|
|
76
|
+
* oxlint could not read.
|
|
77
|
+
* `files` must not be empty, which would lint the whole repository.
|
|
78
|
+
*/
|
|
79
|
+
function directiveReport(root, files) {
|
|
80
|
+
const report = {
|
|
81
|
+
unused: [],
|
|
82
|
+
unreadable: []
|
|
83
|
+
};
|
|
84
|
+
for (const item of runOxlint(root, void 0, files, ["--report-unused-disable-directives"])) {
|
|
85
|
+
if (item.code !== void 0) continue;
|
|
86
|
+
const file = item.filename === void 0 ? void 0 : repositoryPath(root, item.filename);
|
|
87
|
+
const span = item.labels?.[0]?.span;
|
|
88
|
+
if (file !== void 0 && isUnusedDirective(item.message)) report.unused.push({
|
|
89
|
+
file,
|
|
90
|
+
line: span?.line ?? 0,
|
|
91
|
+
message: item.message,
|
|
92
|
+
rules: UNUSED_RULES.exec(item.message)?.[1].split(/,\s*/u)
|
|
93
|
+
});
|
|
94
|
+
else report.unreadable.push({
|
|
95
|
+
location: file !== void 0 && span ? `${file}:${span.line}:${span.column}` : file,
|
|
96
|
+
message: item.message
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return report;
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
12
102
|
//#region src/guardrails/dead-directives.ts
|
|
13
103
|
const BLOCK_DISABLE = /-disable$/u;
|
|
14
104
|
const ESLINT_CONFIG = /^(?:eslint\.config\.[cm]?[jt]s|\.eslintrc(?:\..+)?)$/u;
|
|
@@ -62,8 +152,8 @@ function reasonlessFailure(directive) {
|
|
|
62
152
|
}
|
|
63
153
|
/**
|
|
64
154
|
* Fails, in each of `files`, every lint directive that suppresses nothing
|
|
65
|
-
* under the repository's own lint configuration
|
|
66
|
-
*
|
|
155
|
+
* under the repository's own lint configuration, and every directive naming
|
|
156
|
+
* rules that gives no reason. Directives
|
|
67
157
|
* in other files are left alone, so adopting the check changes no existing
|
|
68
158
|
* file until a change touches it. `eslint-` directives under an ESLint config
|
|
69
159
|
* are left to ESLint, and `.vue` files are not linted by oxlint.
|
|
@@ -125,6 +215,119 @@ function touchedFiles(root, revision) {
|
|
|
125
215
|
return [.../* @__PURE__ */ new Set([...tracked.split("\0"), ...changedFiles(root)])].filter(Boolean);
|
|
126
216
|
}
|
|
127
217
|
//#endregion
|
|
218
|
+
//#region src/guardrails/suppression-base.ts
|
|
219
|
+
function verified(root, ref) {
|
|
220
|
+
const result = spawnSync("git", [
|
|
221
|
+
"rev-parse",
|
|
222
|
+
"--verify",
|
|
223
|
+
"--quiet",
|
|
224
|
+
"--end-of-options",
|
|
225
|
+
`${ref}^{commit}`
|
|
226
|
+
], {
|
|
227
|
+
cwd: root,
|
|
228
|
+
encoding: "utf8"
|
|
229
|
+
});
|
|
230
|
+
return result.status === 0 ? result.stdout.trim() : void 0;
|
|
231
|
+
}
|
|
232
|
+
function fetchBase(root, branch, remote) {
|
|
233
|
+
const result = spawnSync("git", [
|
|
234
|
+
"fetch",
|
|
235
|
+
"--quiet",
|
|
236
|
+
"--no-tags",
|
|
237
|
+
"--depth=1",
|
|
238
|
+
"origin",
|
|
239
|
+
`+refs/heads/${branch}:${remote}`
|
|
240
|
+
], {
|
|
241
|
+
cwd: root,
|
|
242
|
+
encoding: "utf8",
|
|
243
|
+
env: {
|
|
244
|
+
...process.env,
|
|
245
|
+
GIT_TERMINAL_PROMPT: "0"
|
|
246
|
+
},
|
|
247
|
+
stdio: [
|
|
248
|
+
"ignore",
|
|
249
|
+
"ignore",
|
|
250
|
+
"pipe"
|
|
251
|
+
]
|
|
252
|
+
});
|
|
253
|
+
if (result.status === 0) return;
|
|
254
|
+
const detail = result.error?.message ?? result.stderr.trim();
|
|
255
|
+
throw new Error(`Cannot compare with the pull request base: ${remote} is missing and fetching ${branch} from origin failed${detail ? ` (${detail})` : ""}. In CI, fetch the base branch before this check with credentials, or pass --base.`);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* The commit a pull request merges into: `base` when given; in CI the
|
|
259
|
+
* `GITHUB_BASE_REF` branch, taken from the local `origin/<branch>` ref when
|
|
260
|
+
* present and otherwise fetched from `origin`, an error naming the missing ref
|
|
261
|
+
* when the fetch fails; otherwise `origin/HEAD`, the remote's default branch.
|
|
262
|
+
* A requested base that cannot be resolved is an error; without one, a
|
|
263
|
+
* repository with no `origin/HEAD` has no base.
|
|
264
|
+
*/
|
|
265
|
+
function suppressionBase(root, base) {
|
|
266
|
+
if (base !== void 0) return resolveRevision(root, base);
|
|
267
|
+
const branch = process.env.GITHUB_BASE_REF;
|
|
268
|
+
if (branch) {
|
|
269
|
+
const remote = `refs/remotes/origin/${branch}`;
|
|
270
|
+
if (verified(root, remote) === void 0) fetchBase(root, branch, remote);
|
|
271
|
+
return resolveRevision(root, remote);
|
|
272
|
+
}
|
|
273
|
+
return verified(root, "refs/remotes/origin/HEAD");
|
|
274
|
+
}
|
|
275
|
+
function agentFilesDropped(base, current) {
|
|
276
|
+
return base.agentFiles && !current.agentFiles ? [`${SUPPRESSIONS_FILE}: drops agentFiles, which the base has. Keep it; the repository's own files under the agent directories stay counted.`] : [];
|
|
277
|
+
}
|
|
278
|
+
/** What the agent directories hold, when `current` begins recording them and `base` does not; nothing otherwise. */
|
|
279
|
+
function adoptableAgentCounts(root, revision, base, current) {
|
|
280
|
+
const none = {
|
|
281
|
+
rules: {},
|
|
282
|
+
config: {},
|
|
283
|
+
tsExpectError: 0,
|
|
284
|
+
tsIgnore: 0,
|
|
285
|
+
safety: 0
|
|
286
|
+
};
|
|
287
|
+
if (base.agentFiles || !current.agentFiles) return none;
|
|
288
|
+
const counts = countSuppressions(revisionSuppressions(root, revision).filter(({ file }) => isAgentFile(file)));
|
|
289
|
+
return {
|
|
290
|
+
...counts,
|
|
291
|
+
config: counts.config ?? {}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Fails each ceiling of the working-tree budget that is higher than on
|
|
296
|
+
* `revision`, and each rule that `revision` lists but the working tree
|
|
297
|
+
* dropped, config rule-offs included once the base has their ceilings; a
|
|
298
|
+
* config ceiling may rise by what a containing scope of its rule falls. The
|
|
299
|
+
* safety ceiling may rise by what the SAFETY rule's own ceiling falls. A
|
|
300
|
+
* base that does not record the agent directories' files lets the working
|
|
301
|
+
* tree record them, each ceiling rising by no more than its count there; a
|
|
302
|
+
* base that does must keep recording them. A base without a budget, a first
|
|
303
|
+
* adoption, passes.
|
|
304
|
+
*/
|
|
305
|
+
function raisedCeilings(root, revision) {
|
|
306
|
+
const committed = spawnSync("git", ["show", `${revision}:${SUPPRESSIONS_FILE}`], {
|
|
307
|
+
cwd: root,
|
|
308
|
+
encoding: "utf8"
|
|
309
|
+
});
|
|
310
|
+
if (committed.status !== 0) return [];
|
|
311
|
+
const label = `${revision.slice(0, 12)}:${SUPPRESSIONS_FILE}`;
|
|
312
|
+
const base = parseBudget(committed.stdout, label);
|
|
313
|
+
const current = parseBudget(readFileSync(join(root, SUPPRESSIONS_FILE), "utf8"), SUPPRESSIONS_FILE);
|
|
314
|
+
const failures = agentFilesDropped(base, current);
|
|
315
|
+
const room = adoptableAgentCounts(root, revision, base, current);
|
|
316
|
+
const compare = (key, ceiling, after, adoptable = 0) => {
|
|
317
|
+
const before = ceiling + adoptable;
|
|
318
|
+
if (after === void 0) failures.push(`${SUPPRESSIONS_FILE}: removes ${key}, which has ceiling ${before} on the base. Keep the key; lower it with suppressions:update.`);
|
|
319
|
+
else if (after > before) failures.push(`${SUPPRESSIONS_FILE}: raises ${key} from ${ceiling} on the base to ${after}${adoptable ? `, above the ${before} that recording the agent files allows` : ""}.`);
|
|
320
|
+
};
|
|
321
|
+
for (const rule of /* @__PURE__ */ new Set([...Object.keys(base.rules), ...Object.keys(current.rules)])) compare(`lint rule \`${rule}\``, base.rules[rule] ?? 0, Object.hasOwn(base.rules, rule) ? current.rules[rule] : current.rules[rule] ?? 0, room.rules[rule]);
|
|
322
|
+
const baseConfig = base.config ?? {};
|
|
323
|
+
const covered = coveredLimits(baseConfig, current.config ?? {});
|
|
324
|
+
for (const rule of /* @__PURE__ */ new Set([...Object.keys(baseConfig), ...Object.keys(current.config ?? {})])) if (base.config !== void 0) compare(`lint config rule-off \`${rule}\``, covered[rule] ?? 0, current.config === void 0 || Object.hasOwn(baseConfig, rule) && !Object.hasOwn(current.config, rule) ? void 0 : current.config[rule] ?? 0, room.config[rule]);
|
|
325
|
+
compare("`@ts-expect-error`", base.tsExpectError, current.tsExpectError, room.tsExpectError);
|
|
326
|
+
compare("`@ts-ignore`", base.tsIgnore, current.tsIgnore, room.tsIgnore);
|
|
327
|
+
compare("`SAFETY:` comments", safetyCeiling(base, current.rules["anti-slop/require-safety-comment-for-type-assertion"] ?? 0), current.safety, room.safety);
|
|
328
|
+
return failures.length ? [...failures, "Ceilings only go down. Fix the code, or remove another suppression of the same kind; raising a ceiling needs the operator's approval through the ruleset bypass."] : [];
|
|
329
|
+
}
|
|
330
|
+
//#endregion
|
|
128
331
|
//#region src/bin/suppressions.ts
|
|
129
332
|
function fullCheck(root, update, base) {
|
|
130
333
|
const failures = checkSuppressions(root, update);
|