@antelopejs/tooling-configs 0.2.16 → 0.2.17

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.
Files changed (41) hide show
  1. package/README.md +88 -48
  2. package/dist/bin/api-diff.mjs +409 -97
  3. package/dist/bin/body-check.d.mts +1 -0
  4. package/dist/bin/body-check.mjs +344 -0
  5. package/dist/bin/check-size.mjs +3 -3
  6. package/dist/bin/checks.mjs +3 -3
  7. package/dist/bin/comment-proof.mjs +4 -3
  8. package/dist/bin/garden.mjs +5 -5
  9. package/dist/bin/ratchet.mjs +267 -7
  10. package/dist/bin/suppressions.mjs +118 -80
  11. package/dist/bin/sync.mjs +490 -35
  12. package/dist/bin/verify.mjs +5 -5
  13. package/dist/{ceilings-BSw9p4YB.mjs → ceilings-B7KayYIG.mjs} +11 -3
  14. package/dist/{checks-BlWDFYio.mjs → checks-CxkSu2E6.mjs} +1 -1
  15. package/dist/{ci-workflow-DIsoEgMd.mjs → ci-workflow-ChW4He0r.mjs} +84 -3
  16. package/dist/{files-2FikHZ9F.mjs → files-Bc036sJW.mjs} +2 -2
  17. package/dist/{json-BqvuCkqr.mjs → json-CG2L7YFl.mjs} +12 -8
  18. package/dist/oxc/anti-slop/index.mjs +160 -13
  19. package/dist/oxc/fmt.mjs +1 -1
  20. package/dist/oxc/guardrails/index.d.mts +1 -1
  21. package/dist/oxc/guardrails/index.mjs +645 -1
  22. package/dist/oxc/lint.d.mts +11 -3
  23. package/dist/oxc/lint.mjs +21 -8
  24. package/dist/oxlint-Bltmk8-6.mjs +94 -0
  25. package/dist/{package-Dtjt_lSa.mjs → package-DTxLPNDu.mjs} +3 -2
  26. package/dist/proof-stamp-w-3j47A-.mjs +279 -0
  27. package/dist/ratchet-DwRj9h4L.mjs +275 -0
  28. package/dist/{renames-BGO4dWJ8.mjs → renames-L2owF5GD.mjs} +2 -2
  29. package/dist/shared-CoUt4GUm.mjs +73 -0
  30. package/dist/{size-BVgNbLO6.mjs → size-DNtWruCO.mjs} +3 -3
  31. package/dist/suppression-base-DAfCXwjL.mjs +95 -0
  32. package/dist/{suppression-budget-Yyf5_J5l.mjs → suppression-budget-Bd2GqMYb.mjs} +248 -33
  33. package/dist/{suppressions-BJAngUxo.mjs → suppressions-BD_f8f7L.mjs} +180 -18
  34. package/dist/typescript-BmS5BmrS.mjs +222 -0
  35. package/dist/verify/index.mjs +1 -1
  36. package/package.json +4 -2
  37. package/dist/kinds-Bzyyi9yk.mjs +0 -25
  38. package/dist/ratchet-DRdIYwmv.mjs +0 -80
  39. package/dist/shared-CsXIMK3I.mjs +0 -34
  40. package/dist/staged-ratchet-CjoRfZaM.mjs +0 -236
  41. package/dist/typescript-C54ONh9m.mjs +0 -433
@@ -1,11 +1,267 @@
1
1
  #!/usr/bin/env node
2
- import { t as CEILINGS_FILE } from "../ceilings-BSw9p4YB.mjs";
2
+ import { l as readCeilings, t as CEILINGS_FILE } from "../ceilings-B7KayYIG.mjs";
3
+ import { n as renamedPaths } from "../renames-L2owF5GD.mjs";
3
4
  import { t as runCli } from "../cli-4Tv71vYk.mjs";
4
- import { a as repositoryPath, o as repositoryRoot, s as resolveRevision } from "../files-2FikHZ9F.mjs";
5
- import { n as stagedRatchet } from "../staged-ratchet-CjoRfZaM.mjs";
6
- import { n as ratchet } from "../ratchet-DRdIYwmv.mjs";
7
- import { resolve } from "node:path";
5
+ import { a as repositoryPath, o as repositoryRoot, s as resolveRevision } from "../files-Bc036sJW.mjs";
6
+ import { n as ratchet } from "../ratchet-DwRj9h4L.mjs";
7
+ import { t as lintDiagnostics } from "../oxlint-Bltmk8-6.mjs";
8
+ import { d as stagedAdditions, f as stagedChanges, u as previousLine } from "../suppression-budget-Bd2GqMYb.mjs";
9
+ import { n as suppressionBase } from "../suppression-base-DAfCXwjL.mjs";
10
+ import { copyFileSync, existsSync, mkdtempSync, rmSync, symlinkSync } from "node:fs";
11
+ import { join, resolve } from "node:path";
12
+ import { execFileSync, spawnSync } from "node:child_process";
8
13
  import { parseArgs } from "node:util";
14
+ import { tmpdir } from "node:os";
15
+ //#region src/guardrails/previous-tree.ts
16
+ function git(root, args, env, input = "") {
17
+ return execFileSync("git", args, {
18
+ cwd: root,
19
+ encoding: "utf8",
20
+ env: {
21
+ ...process.env,
22
+ ...env
23
+ },
24
+ input,
25
+ maxBuffer: 268435456
26
+ });
27
+ }
28
+ function revisionEntries(root, revision) {
29
+ const entries = /* @__PURE__ */ new Map();
30
+ for (const entry of git(root, [
31
+ "ls-tree",
32
+ "-r",
33
+ "-z",
34
+ revision
35
+ ], {}).split("\0")) {
36
+ const tab = entry.indexOf(" ");
37
+ if (tab > 0) entries.set(entry.slice(tab + 1), entry.slice(0, tab));
38
+ }
39
+ return entries;
40
+ }
41
+ /**
42
+ * Runs `use` on a checkout of the index in which each of `paths` holds its
43
+ * content at `revision`, or is absent when `revision` does not have it or does
44
+ * not exist, so the files are linted under the staged configuration. The
45
+ * checkout is deleted afterwards.
46
+ */
47
+ function withPreviousTree(root, revision, paths, use) {
48
+ const scratch = mkdtempSync(join(tmpdir(), "antelopejs-previous."));
49
+ try {
50
+ const exists = spawnSync("git", [
51
+ "rev-parse",
52
+ "--verify",
53
+ `${revision}^{commit}`
54
+ ], {
55
+ cwd: root,
56
+ stdio: "ignore"
57
+ }).status === 0;
58
+ const index = join(scratch, "index");
59
+ copyFileSync(git(root, [
60
+ "rev-parse",
61
+ "--path-format=absolute",
62
+ "--git-path",
63
+ "index"
64
+ ], {}).trim(), index);
65
+ const env = { GIT_INDEX_FILE: index };
66
+ const head = exists ? revisionEntries(root, revision) : /* @__PURE__ */ new Map();
67
+ const restored = paths.filter((path) => head.has(path));
68
+ const removed = paths.filter((path) => !head.has(path));
69
+ if (restored.length) git(root, [
70
+ "update-index",
71
+ "-z",
72
+ "--index-info"
73
+ ], env, restored.map((path) => `${head.get(path)}\t${path}\0`).join(""));
74
+ if (removed.length) git(root, [
75
+ "update-index",
76
+ "-z",
77
+ "--force-remove",
78
+ "--stdin"
79
+ ], env, removed.map((path) => `${path}\0`).join(""));
80
+ const tree = join(scratch, "tree");
81
+ git(root, [
82
+ "checkout-index",
83
+ "-a",
84
+ "-f",
85
+ `--prefix=${tree}/`
86
+ ], env);
87
+ if (existsSync(join(root, "node_modules"))) symlinkSync(join(root, "node_modules"), join(tree, "node_modules"), "dir");
88
+ return use(tree);
89
+ } finally {
90
+ rmSync(scratch, {
91
+ recursive: true,
92
+ force: true
93
+ });
94
+ }
95
+ }
96
+ //#endregion
97
+ //#region src/guardrails/staged-ratchet.ts
98
+ function stagedNames(root, filter) {
99
+ return execFileSync("git", [
100
+ "diff",
101
+ "--cached",
102
+ "--name-only",
103
+ `--diff-filter=${filter}`,
104
+ "-z"
105
+ ], {
106
+ cwd: root,
107
+ encoding: "utf8"
108
+ }).split("\0").filter(Boolean);
109
+ }
110
+ function countByRule(diagnostics) {
111
+ const counts = /* @__PURE__ */ new Map();
112
+ for (const { rule } of diagnostics) counts.set(rule, (counts.get(rule) ?? 0) + 1);
113
+ return counts;
114
+ }
115
+ const LINT_CONFIG = /(?:^|\/)(?:oxlint\.config\.[cm]?[jt]s|\.oxlintrc\.jsonc?)$/u;
116
+ function comparisonBase(root) {
117
+ const base = suppressionBase(root);
118
+ const name = process.env.GITHUB_BASE_REF ? `origin/${process.env.GITHUB_BASE_REF}` : "origin/HEAD";
119
+ if (base === void 0) return {
120
+ revision: void 0,
121
+ note: "No pull request base resolved (GITHUB_BASE_REF or origin/HEAD), so this compared with HEAD only. Run `git remote set-head origin --auto` to also compare with the merge-base, as CI does."
122
+ };
123
+ const result = spawnSync("git", [
124
+ "merge-base",
125
+ base,
126
+ "HEAD"
127
+ ], {
128
+ cwd: root,
129
+ encoding: "utf8"
130
+ });
131
+ if (result.status !== 0) return {
132
+ revision: void 0,
133
+ note: `HEAD has no merge-base with ${name}, so this compared with HEAD only. Run \`git fetch --unshallow origin\` (or \`git fetch origin <default-branch>\` when HEAD is not shallow) to also compare with the merge-base, as CI does.`
134
+ };
135
+ const revision = result.stdout.trim();
136
+ return {
137
+ revision,
138
+ label: `merge-base ${revision.slice(0, 12)} with ${name}`
139
+ };
140
+ }
141
+ function previousDiagnostics(root, targets, revision) {
142
+ const renames = renamedPaths(root, true, revision === void 0 ? [] : [revision]);
143
+ const deletedFrom = revision === void 0 ? /* @__PURE__ */ new Map() : renamedPaths(root, false, [revision, "HEAD"]);
144
+ const previous = [.../* @__PURE__ */ new Set([...targets.map((file) => renames.get(file) ?? file), ...stagedNames(root, "D").map((file) => deletedFrom.get(file) ?? file)])];
145
+ return withPreviousTree(root, revision ?? "HEAD", previous.filter((file) => !LINT_CONFIG.test(file)), (tree) => {
146
+ const existing = previous.filter((file) => existsSync(join(tree, file)));
147
+ return existing.length ? lintDiagnostics(tree, void 0, existing) : [];
148
+ });
149
+ }
150
+ /**
151
+ * How many of `staged` sit on a line unchanged since the base and match a
152
+ * finding `previous` reports on that line of the base, each base finding
153
+ * matched once.
154
+ */
155
+ function keptFindings(staged, previous, changes) {
156
+ const pool = /* @__PURE__ */ new Map();
157
+ for (const { file, line } of previous) {
158
+ const key = `${file}:${line}`;
159
+ pool.set(key, (pool.get(key) ?? 0) + 1);
160
+ }
161
+ let kept = 0;
162
+ for (const { file, line } of staged) {
163
+ const change = changes.get(file);
164
+ if (line === void 0 || change === void 0) continue;
165
+ const from = previousLine(change.hunks, line);
166
+ const key = `${change.previous}:${from}`;
167
+ const left = pool.get(key) ?? 0;
168
+ if (from === void 0 || left === 0) continue;
169
+ pool.set(key, left - 1);
170
+ kept += 1;
171
+ }
172
+ return kept;
173
+ }
174
+ /**
175
+ * Per rule, the findings in the files the branch changed since `revision`, at
176
+ * `revision` and in the index, so a merge-base credit is only paid while the
177
+ * branch as a whole does not raise the rule.
178
+ */
179
+ function branchCounts(root, revision) {
180
+ const paths = execFileSync("git", [
181
+ "diff",
182
+ "--cached",
183
+ "--name-only",
184
+ "--no-renames",
185
+ "-z",
186
+ revision
187
+ ], {
188
+ cwd: root,
189
+ encoding: "utf8"
190
+ }).split("\0").filter((file) => file && !LINT_CONFIG.test(file));
191
+ const lint = (tree) => {
192
+ const existing = paths.filter((file) => existsSync(join(tree, file)));
193
+ return countByRule(existing.length ? lintDiagnostics(tree, void 0, existing) : []);
194
+ };
195
+ return {
196
+ before: withPreviousTree(root, revision, paths, lint),
197
+ after: withPreviousTree(root, revision, [], lint)
198
+ };
199
+ }
200
+ function inRanges(ranges, file, line) {
201
+ return ranges.get(file)?.some(({ start, end }) => line >= start && line <= end) ?? false;
202
+ }
203
+ /**
204
+ * Fails each ceilinged rule whose findings in the staged files outnumber both
205
+ * what the same files, rename sources and deleted files had at HEAD and the
206
+ * staged findings that sit, on a line unchanged since the merge-base of HEAD
207
+ * with the pull request base (`GITHUB_BASE_REF`, else `origin/HEAD`), where
208
+ * the merge-base has a finding of the same rule, while the files the branch
209
+ * changed hold no more findings of that rule than at the merge-base; without a
210
+ * merge-base, HEAD alone.
211
+ * The count is net across the staged files, so a block moved between them, a
212
+ * legacy line that is reformatted, a line restored to its base form, or an
213
+ * edit of a file a legacy finding moved into earlier on the branch passes; a
214
+ * rise above both fails, and lists the findings on the lines that differ from
215
+ * HEAD and from the base.
216
+ */
217
+ function stagedRatchet(root, files) {
218
+ const targets = files ?? stagedNames(root, "ACMR");
219
+ if (!targets.length) return [];
220
+ const ceilings = readCeilings(root);
221
+ const after = lintDiagnostics(root, void 0, targets).filter(({ rule }) => Object.hasOwn(ceilings.rules, rule));
222
+ if (!after.length) return [];
223
+ const base = comparisonBase(root);
224
+ const atHead = countByRule(previousDiagnostics(root, targets, void 0));
225
+ const headAdditions = stagedAdditions(root, targets);
226
+ const atBase = base.revision === void 0 ? void 0 : previousDiagnostics(root, targets, base.revision);
227
+ const baseChanges = base.revision === void 0 ? void 0 : stagedChanges(root, targets, base.revision);
228
+ let branch;
229
+ const measure = (rule, matches, head, total) => {
230
+ const kept = atBase === void 0 || baseChanges === void 0 ? void 0 : keptFindings(matches, atBase.filter((diagnostic) => diagnostic.rule === rule), baseChanges);
231
+ const rise = total - Math.max(head, kept ?? 0);
232
+ if (kept === void 0 || kept <= head || base.revision === void 0) return {
233
+ kept,
234
+ rise,
235
+ raised: void 0
236
+ };
237
+ branch ??= branchCounts(root, base.revision);
238
+ const from = branch.before.get(rule) ?? 0;
239
+ const to = branch.after.get(rule) ?? 0;
240
+ if (to <= from) return {
241
+ kept,
242
+ rise,
243
+ raised: void 0
244
+ };
245
+ return {
246
+ kept,
247
+ rise: Math.min(total - head, Math.max(to - from, rise)),
248
+ raised: `the files this branch changed hold ${to} at the index against ${from} at that merge-base, so the merge-base credit covers no added finding`
249
+ };
250
+ };
251
+ const failures = [];
252
+ for (const [rule, total] of countByRule(after)) {
253
+ const head = atHead.get(rule) ?? 0;
254
+ if (total <= head) continue;
255
+ const matches = after.filter((diagnostic) => diagnostic.rule === rule);
256
+ const { kept, rise, raised } = measure(rule, matches, head, total);
257
+ if (rise <= 0) continue;
258
+ const added = matches.filter(({ file, line }) => line !== void 0 && inRanges(headAdditions, file, line) && (baseChanges === void 0 || previousLine(baseChanges.get(file)?.hunks ?? [], line) === void 0));
259
+ const counts = kept === void 0 || base.revision === void 0 ? `${head} at HEAD` : `${head} at HEAD, ${kept} unchanged since ${base.label}`;
260
+ failures.push(`${rule}: this commit adds ${rise} to the staged files (${counts}, ${total} staged)${raised === void 0 ? "" : `; ${raised}`}; the ceiling covers only legacy findings.`, ...(added.length ? added : matches).map((diagnostic) => ` ${diagnostic.location}: ${diagnostic.message}\n Fix: ${diagnostic.help ?? "Resolve this finding; moving, reformatting or restoring a legacy finding to its base form is allowed, adding one is not."}`));
261
+ }
262
+ return failures.length && base.revision === void 0 ? [...failures, base.note] : failures;
263
+ }
264
+ //#endregion
9
265
  //#region src/bin/ratchet.ts
10
266
  runCli(() => {
11
267
  const { values, positionals } = parseArgs({
@@ -23,8 +279,12 @@ runCli(() => {
23
279
  const result = values.staged ? {
24
280
  failures: stagedRatchet(root, positionals.length ? positionals.map((file) => repositoryPath(root, resolve(file))) : void 0),
25
281
  lowered: [],
26
- retired: false
27
- } : ratchet(root, values.update, values.base === void 0 ? void 0 : resolveRevision(root, values.base));
282
+ adoptions: [],
283
+ retired: false,
284
+ created: false
285
+ } : ratchet(root, values.update, values.base === void 0 ? void 0 : resolveRevision(root, values.base), suppressionBase(root, values.base));
286
+ if (result.created) process.stdout.write(`Created ${CEILINGS_FILE} for the rules the pack newly enabled. Run antelopejs-sync.\n`);
287
+ for (const message of result.adoptions) process.stdout.write(`Adopted ${message}\n`);
28
288
  if (result.retired) process.stdout.write(`Deleted ${CEILINGS_FILE}: no debt left. Run antelopejs-sync.\n`);
29
289
  for (const message of result.lowered) process.stdout.write(`Lowered ${message}\n`);
30
290
  for (const message of result.failures) process.stderr.write(`${message}\n`);
@@ -1,103 +1,141 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as runCli } from "../cli-4Tv71vYk.mjs";
3
- import { o as repositoryRoot, s as resolveRevision } from "../files-2FikHZ9F.mjs";
4
- import { a as parseBudget, c as checkPolicy, i as checkSuppressions, n as SUPPRESSIONS_FILE, o as safetyCeiling, s as stagedSuppressions } from "../suppression-budget-Yyf5_J5l.mjs";
5
- import { readFileSync } from "node:fs";
6
- import { join } from "node:path";
7
- import { spawnSync } from "node:child_process";
3
+ import { n as changedFiles, o as repositoryRoot } from "../files-Bc036sJW.mjs";
4
+ import { n as unusedDirectives } from "../oxlint-Bltmk8-6.mjs";
5
+ import { c as stagedSuppressions, i as checkSuppressions, l as checkPolicy, s as stagedNames } from "../suppression-budget-Bd2GqMYb.mjs";
6
+ import { c as suppressionsIn, i as inWorktree } from "../suppressions-BD_f8f7L.mjs";
7
+ import { n as suppressionBase, t as raisedCeilings } from "../suppression-base-DAfCXwjL.mjs";
8
+ import { readdirSync } from "node:fs";
9
+ import { dirname, join } from "node:path";
10
+ import { execFileSync, spawnSync } from "node:child_process";
8
11
  import { parseArgs } from "node:util";
9
- //#region src/guardrails/suppression-base.ts
10
- function verified(root, ref) {
11
- const result = spawnSync("git", [
12
- "rev-parse",
13
- "--verify",
14
- "--quiet",
15
- "--end-of-options",
16
- `${ref}^{commit}`
17
- ], {
18
- cwd: root,
19
- encoding: "utf8"
20
- });
21
- return result.status === 0 ? result.stdout.trim() : void 0;
12
+ //#region src/guardrails/dead-directives.ts
13
+ const BLOCK_DISABLE = /-disable$/u;
14
+ const ESLINT_CONFIG = /^(?:eslint\.config\.[cm]?[jt]s|\.eslintrc(?:\..+)?)$/u;
15
+ function directivesIn(file, text) {
16
+ const grouped = /* @__PURE__ */ new Map();
17
+ for (const found of suppressionsIn(file, text)) {
18
+ if (found.kind !== "rule") continue;
19
+ const key = `${found.line}\0${found.directive}`;
20
+ const known = grouped.get(key);
21
+ if (known === void 0) grouped.set(key, entry(found));
22
+ else known.rules.push(found.rule);
23
+ }
24
+ return [...grouped.values()];
22
25
  }
23
- function fetchBase(root, branch, remote) {
24
- const result = spawnSync("git", [
25
- "fetch",
26
- "--quiet",
27
- "--no-tags",
28
- "--depth=1",
29
- "origin",
30
- `+refs/heads/${branch}:${remote}`
31
- ], {
32
- cwd: root,
33
- encoding: "utf8",
34
- env: {
35
- ...process.env,
36
- GIT_TERMINAL_PROMPT: "0"
37
- },
38
- stdio: [
39
- "ignore",
40
- "ignore",
41
- "pipe"
42
- ]
43
- });
44
- if (result.status === 0) return;
45
- const detail = result.error?.message ?? result.stderr.trim();
46
- 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.`);
26
+ function entry(found) {
27
+ return {
28
+ file: found.file,
29
+ line: found.line,
30
+ directive: found.directive,
31
+ rules: [found.rule],
32
+ reason: found.reason
33
+ };
34
+ }
35
+ function written(directive, rules = directive.rules) {
36
+ const named = rules.filter((rule) => rule !== "*");
37
+ return `\`${[directive.directive, ...named.length ? [named.join(", ")] : []].join(" ")}\``;
38
+ }
39
+ /** Whether an ESLint config sits in the file's directory or above it, so ESLint may run the rules an `eslint-` directive names. */
40
+ function lintedByEslint(root, file) {
41
+ for (let directory = dirname(join(root, file)); directory.startsWith(root); directory = dirname(directory)) {
42
+ if (readdirSync(directory).some((name) => ESLINT_CONFIG.test(name))) return true;
43
+ if (directory === root) break;
44
+ }
45
+ return false;
46
+ }
47
+ /** The directive oxlint's report is about: on its line, else the nearest earlier block disable it ends at an `-enable` on that line, naming the dead rule when oxlint names one. */
48
+ function reported(directives, unused) {
49
+ const named = (directive) => unused.rules === void 0 || unused.rules.every((rule) => directive.rules.includes(rule));
50
+ const here = directives.filter((directive) => directive.file === unused.file && directive.line === unused.line && named(directive));
51
+ if (here.length) return here[0];
52
+ return directives.filter((directive) => directive.file === unused.file && directive.line < unused.line && BLOCK_DISABLE.test(directive.directive) && named(directive)).at(-1);
53
+ }
54
+ function deadFailure(directive, dead) {
55
+ const at = `${directive.file}:${directive.line}`;
56
+ if (directive.rules.every((rule) => dead.has(rule))) return [`${at}: ${written(directive)} suppresses nothing. Fix: delete the directive.`];
57
+ const closing = BLOCK_DISABLE.test(directive.directive) ? " and from its enable" : "";
58
+ return [...dead].map((rule) => `${at}: ${written(directive, [rule])} suppresses nothing. Fix: drop \`${rule}\` from the directive${closing}.`);
59
+ }
60
+ function reasonlessFailure(directive) {
61
+ if (directive.reason !== "" || directive.rules.includes("*")) return [];
62
+ return [`${directive.file}:${directive.line}: ${written(directive)} gives no reason. Fix: add \` -- <why this line needs it>\` after the rules, or delete the directive.`];
47
63
  }
48
64
  /**
49
- * The commit a pull request merges into: `base` when given; in CI the
50
- * `GITHUB_BASE_REF` branch, taken from the local `origin/<branch>` ref when
51
- * present and otherwise fetched from `origin`, an error naming the missing ref
52
- * when the fetch fails; otherwise `origin/HEAD`, the remote's default branch.
53
- * A requested base that cannot be resolved is an error; without one, a
54
- * repository with no `origin/HEAD` has no base.
65
+ * Fails, in each of `files`, every lint directive that suppresses nothing
66
+ * under the repository's own lint configuration with its ratchet rules
67
+ * enabled, and every directive naming rules that gives no reason. Directives
68
+ * in other files are left alone, so adopting the check changes no existing
69
+ * file until a change touches it. `eslint-` directives under an ESLint config
70
+ * are left to ESLint, and `.vue` files are not linted by oxlint.
55
71
  */
56
- function suppressionBase(root, base) {
57
- if (base !== void 0) return resolveRevision(root, base);
58
- const branch = process.env.GITHUB_BASE_REF;
59
- if (branch) {
60
- const remote = `refs/remotes/origin/${branch}`;
61
- if (verified(root, remote) === void 0) fetchBase(root, branch, remote);
62
- return resolveRevision(root, remote);
72
+ function deadDirectiveFailures(root, files) {
73
+ const directives = inWorktree(root, directivesIn, files);
74
+ const readByOxlint = directives.filter(({ file, directive }) => !file.endsWith(".vue") && !(directive.startsWith("eslint-") && lintedByEslint(root, file)));
75
+ const lintable = [...new Set(readByOxlint.map(({ file }) => file))];
76
+ const dead = /* @__PURE__ */ new Map();
77
+ const unplaced = [];
78
+ for (const item of lintable.length ? unusedDirectives(root, lintable) : []) {
79
+ const directive = reported(readByOxlint, item);
80
+ if (directive === void 0) {
81
+ unplaced.push(`${item.file}:${item.line}: ${item.message} Fix: delete the directive.`);
82
+ continue;
83
+ }
84
+ const rules = dead.get(directive) ?? /* @__PURE__ */ new Set();
85
+ for (const rule of item.rules ?? directive.rules) rules.add(rule);
86
+ dead.set(directive, rules);
63
87
  }
64
- return verified(root, "refs/remotes/origin/HEAD");
88
+ return [...unplaced, ...directives.flatMap((directive) => {
89
+ const rules = dead.get(directive);
90
+ return rules === void 0 ? reasonlessFailure(directive) : deadFailure(directive, rules);
91
+ })];
92
+ }
93
+ function mergeBase(root, revision) {
94
+ const result = spawnSync("git", [
95
+ "merge-base",
96
+ revision,
97
+ "HEAD"
98
+ ], {
99
+ cwd: root,
100
+ encoding: "utf8"
101
+ });
102
+ return result.status === 0 ? result.stdout.trim() : revision;
65
103
  }
66
104
  /**
67
- * Fails each ceiling of the working-tree budget that is higher than on
68
- * `revision`, and each rule that `revision` lists but the working tree
69
- * dropped. The safety ceiling may rise by what the SAFETY rule's own
70
- * ceiling falls. A base without a budget, a first adoption, passes.
105
+ * The files a pull request changes: the working tree against the merge-base
106
+ * of `revision` and HEAD (`revision` itself when they have none, as in a
107
+ * shallow checkout), untracked files included; against HEAD without one.
71
108
  */
72
- function raisedCeilings(root, revision) {
73
- const committed = spawnSync("git", ["show", `${revision}:${SUPPRESSIONS_FILE}`], {
109
+ function touchedFiles(root, revision) {
110
+ if (revision === void 0) return [...changedFiles(root)];
111
+ const tracked = execFileSync("git", [
112
+ "diff",
113
+ "--name-only",
114
+ "--no-renames",
115
+ "-z",
116
+ mergeBase(root, revision)
117
+ ], {
74
118
  cwd: root,
75
- encoding: "utf8"
119
+ encoding: "utf8",
120
+ maxBuffer: 67108864
76
121
  });
77
- if (committed.status !== 0) return [];
78
- const label = `${revision.slice(0, 12)}:${SUPPRESSIONS_FILE}`;
79
- const base = parseBudget(committed.stdout, label);
80
- const current = parseBudget(readFileSync(join(root, SUPPRESSIONS_FILE), "utf8"), SUPPRESSIONS_FILE);
81
- const failures = [];
82
- const compare = (key, before, after) => {
83
- 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.`);
84
- else if (after > before) failures.push(`${SUPPRESSIONS_FILE}: raises ${key} from ${before} on the base to ${after}.`);
85
- };
86
- 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);
87
- compare("`@ts-expect-error`", base.tsExpectError, current.tsExpectError);
88
- compare("`@ts-ignore`", base.tsIgnore, current.tsIgnore);
89
- compare("`SAFETY:` comments", safetyCeiling(base, current.rules["anti-slop/require-safety-comment-for-type-assertion"] ?? 0), current.safety);
90
- 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."] : [];
122
+ return [.../* @__PURE__ */ new Set([...tracked.split("\0"), ...changedFiles(root)])].filter(Boolean);
91
123
  }
92
124
  //#endregion
93
125
  //#region src/bin/suppressions.ts
94
126
  function fullCheck(root, update, base) {
95
127
  const failures = checkSuppressions(root, update);
96
128
  const revision = suppressionBase(root, base);
97
- return revision === void 0 ? [...failures, ...checkPolicy(root)] : [
129
+ const dead = deadDirectiveFailures(root, touchedFiles(root, revision));
130
+ return revision === void 0 ? [
131
+ ...failures,
132
+ ...checkPolicy(root),
133
+ ...dead
134
+ ] : [
98
135
  ...raisedCeilings(root, revision),
99
136
  ...failures,
100
- ...checkPolicy(root, revision)
137
+ ...checkPolicy(root, revision),
138
+ ...dead
101
139
  ];
102
140
  }
103
141
  runCli(() => {
@@ -111,7 +149,7 @@ runCli(() => {
111
149
  });
112
150
  if (values.staged && (values.update || values.base !== void 0)) throw new Error("--staged cannot be combined with --update or --base.");
113
151
  const root = repositoryRoot();
114
- const failures = values.staged ? stagedSuppressions(root) : fullCheck(root, values.update, values.base);
152
+ const failures = values.staged ? [...stagedSuppressions(root), ...deadDirectiveFailures(root, stagedNames(root, "ACMR"))] : fullCheck(root, values.update, values.base);
115
153
  for (const failure of failures) process.stderr.write(`${failure}\n`);
116
154
  return failures.length ? 1 : 0;
117
155
  });