@antelopejs/tooling-configs 0.2.15 → 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 +48 -26
  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-C0nT5SnX.mjs → ci-workflow-ChW4He0r.mjs} +103 -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
@@ -0,0 +1,275 @@
1
+ import { a as formatCeilings, c as parseCeilings, n as MAX_FILE_BYTES, o as isPackRelease, s as isRetired, t as CEILINGS_FILE } from "./ceilings-B7KayYIG.mjs";
2
+ import { n as renamedPaths, t as readCarriedCeilings } from "./renames-L2owF5GD.mjs";
3
+ import { n as changedFiles, t as authoredSizes } from "./files-Bc036sJW.mjs";
4
+ import { o as toolingVersions } from "./package-DTxLPNDu.mjs";
5
+ import { t as lintDiagnostics } from "./oxlint-Bltmk8-6.mjs";
6
+ import "./suppression-budget-Bd2GqMYb.mjs";
7
+ import { n as sizeFailure } from "./size-DNtWruCO.mjs";
8
+ import { existsSync, unlinkSync, writeFileSync } from "node:fs";
9
+ import { join } from "node:path";
10
+ import { spawnSync } from "node:child_process";
11
+ //#region src/guardrails/adoption.ts
12
+ /**
13
+ * Each rule the preset turned on after repositories recorded their ratchet,
14
+ * with the first pack release that enables it: the release after the
15
+ * `version` in package.json when the rule lands. `ratchet:update` records
16
+ * today's count of a listed rule once, in a repository whose recorded release
17
+ * predates it; a rule not listed here is never adopted.
18
+ */
19
+ const PACK_NEW_RULES = /* @__PURE__ */ new Map([
20
+ ["antelopejs/no-inherited-key-lookup", "0.2.17"],
21
+ ["antelopejs/no-presence-only-type-guard", "0.2.17"],
22
+ ["typescript/no-unnecessary-type-parameters", "0.2.17"],
23
+ ["typescript/no-unsafe-argument", "0.2.17"],
24
+ ["typescript/no-unsafe-assignment", "0.2.17"],
25
+ ["typescript/no-unsafe-return", "0.2.17"],
26
+ ["typescript/use-unknown-in-catch-callback-variable", "0.2.17"]
27
+ ]);
28
+ function parts(release) {
29
+ return release.split(".").map(Number);
30
+ }
31
+ /** Orders two `major.minor.patch` releases. */
32
+ function compareReleases(a, b) {
33
+ const [left, right] = [parts(a), parts(b)];
34
+ for (let index = 0; index < 3; index += 1) if (left[index] !== right[index]) return left[index] - right[index];
35
+ return 0;
36
+ }
37
+ function latest(releases) {
38
+ let best;
39
+ for (const release of releases) if (release !== void 0 && isPackRelease(release) && (best === void 0 || compareReleases(release, best) > 0)) best = release;
40
+ return best;
41
+ }
42
+ function show(root, revision, path) {
43
+ const result = spawnSync("git", ["show", `${revision}:${path}`], {
44
+ cwd: root,
45
+ encoding: "utf8"
46
+ });
47
+ return result.status === 0 ? result.stdout : void 0;
48
+ }
49
+ const LOCKED = [{
50
+ file: "pnpm-lock.yaml",
51
+ pattern: /^ {6}'@antelopejs\/tooling-configs':\n {8}specifier: [^\n]*\n {8}version: (\d+\.\d+\.\d+)/mu
52
+ }, {
53
+ file: "package-lock.json",
54
+ pattern: /"node_modules\/@antelopejs\/tooling-configs":\s*\{[^{}]*?"version":\s*"(\d+\.\d+\.\d+)"/u
55
+ }];
56
+ /** The pack release the root importer of the pnpm or npm lockfile at `revision` installs. */
57
+ function lockedRelease(root, revision) {
58
+ let release;
59
+ for (const { file, pattern } of LOCKED) {
60
+ const text = show(root, revision, file);
61
+ if (text !== void 0) {
62
+ release = pattern.exec(text)?.[1];
63
+ break;
64
+ }
65
+ }
66
+ return latest([release]);
67
+ }
68
+ /**
69
+ * The release a repository adopted the pack-new rules up to: the later of
70
+ * its ratchet's record and the pack its lockfile at `revision` installs. A
71
+ * repository with neither predates every listed rule.
72
+ */
73
+ function adoptedRelease(root, recorded, revision) {
74
+ return latest([recorded, revision === void 0 ? void 0 : lockedRelease(root, revision)]);
75
+ }
76
+ /** The release that enabled `rule` when it is later than `adopted`, else undefined. */
77
+ function newlyEnabled(rule, adopted) {
78
+ const since = PACK_NEW_RULES.get(rule);
79
+ if (since === void 0) return void 0;
80
+ return adopted === void 0 || compareReleases(since, adopted) > 0 ? since : void 0;
81
+ }
82
+ /** The release an update records: the latest of `adopted`, the installed pack and every listed rule's release, so no listed rule is adopted twice. */
83
+ function recordedRelease(adopted) {
84
+ return latest([
85
+ adopted,
86
+ toolingVersions().pack,
87
+ ...PACK_NEW_RULES.values()
88
+ ]) ?? "0.0.0";
89
+ }
90
+ //#endregion
91
+ //#region src/guardrails/ratchet-raises.ts
92
+ function committed(root, revision, path) {
93
+ const result = spawnSync("git", ["show", `${revision}:${path}`], {
94
+ cwd: root,
95
+ encoding: "utf8"
96
+ });
97
+ return result.status === 0 ? result.stdout : void 0;
98
+ }
99
+ function packFailure(base, ceilings) {
100
+ if (base.pack === void 0) return [];
101
+ if (ceilings.pack === void 0) return [`${CEILINGS_FILE}: drops the recorded pack release ${base.pack} the base has.`];
102
+ return compareReleases(ceilings.pack, base.pack) < 0 ? [`${CEILINGS_FILE}: lowers the recorded pack release from ${base.pack} on the base to ${ceilings.pack}.`] : [];
103
+ }
104
+ function notNewlyEnabled(rule, adopted) {
105
+ const since = PACK_NEW_RULES.get(rule);
106
+ return since === void 0 ? `${CEILINGS_FILE}: adds ${rule}, which the pack did not newly enable.` : `${CEILINGS_FILE}: adds ${rule}, which the pack enabled in ${since}, not after this repository's ${adopted ?? since}.`;
107
+ }
108
+ function ruleFailures$1(base, ceilings, measured, adopted) {
109
+ const failures = [];
110
+ for (const [rule, limit] of Object.entries(ceilings.rules)) {
111
+ const before = base.rules[rule];
112
+ const count = measured.rules[rule] ?? 0;
113
+ if (before !== void 0) {
114
+ if (limit > before) failures.push(`${CEILINGS_FILE}: raises ${rule} from ${before} on the base to ${limit}.`);
115
+ } else if (newlyEnabled(rule, adopted) === void 0) failures.push(notNewlyEnabled(rule, adopted));
116
+ else if (limit > count) failures.push(`${CEILINGS_FILE}: adds ${rule} at ${limit}, above its ${count} findings.`);
117
+ }
118
+ return failures;
119
+ }
120
+ function oversizeFailures(base, ceilings, renames) {
121
+ const failures = [];
122
+ for (const [file, limit] of Object.entries(ceilings.oversizeFiles)) {
123
+ const before = base.oversizeFiles[file] ?? base.oversizeFiles[renames.get(file) ?? file];
124
+ if (before === void 0) failures.push(`${CEILINGS_FILE}: adds an oversize allowance for ${file}.`);
125
+ else if (limit > before) failures.push(`${CEILINGS_FILE}: raises the oversize allowance of ${file} from ${before} bytes on the base to ${limit}.`);
126
+ }
127
+ return failures;
128
+ }
129
+ /**
130
+ * Fails each ceiling of `ceilings` added or raised against the ratchet file
131
+ * at `revision`, except a rule the pack enabled after the base's adopted
132
+ * release, recorded at no more than its `measured` count; and a recorded pack
133
+ * release dropped or lowered. Renamed files keep their allowance. A base with
134
+ * neither a ratchet file nor a suppression budget, a first adoption, passes.
135
+ */
136
+ function raisedRatchet(root, revision, ceilings, measured) {
137
+ const text = committed(root, revision, CEILINGS_FILE);
138
+ if (text === void 0 && committed(root, revision, "guardrails.suppressions.json") === void 0) return [];
139
+ const base = text === void 0 ? {
140
+ rules: {},
141
+ oversizeFiles: {}
142
+ } : parseCeilings(text, `${revision.slice(0, 12)}:${CEILINGS_FILE}`);
143
+ const failures = [
144
+ ...packFailure(base, ceilings),
145
+ ...ruleFailures$1(base, ceilings, measured, adoptedRelease(root, base.pack, revision)),
146
+ ...oversizeFailures(base, ceilings, renamedPaths(root, false, [revision]))
147
+ ];
148
+ return failures.length ? [...failures, "Ceilings only go down: ratchet:update lowers them and records only the rules the pack newly enabled. Fix the code; raising a ceiling needs the operator's approval through the ruleset bypass."] : [];
149
+ }
150
+ //#endregion
151
+ //#region src/guardrails/ratchet.ts
152
+ function baseline(root, diagnostics) {
153
+ const rules = /* @__PURE__ */ new Map();
154
+ const oversizeFiles = {};
155
+ const sizes = authoredSizes(root);
156
+ for (const diagnostic of diagnostics) if (diagnostic.rule === "eslint/max-lines") {
157
+ const size = sizes.get(diagnostic.file);
158
+ if (size !== void 0) oversizeFiles[diagnostic.file] = size;
159
+ } else rules.set(diagnostic.rule, (rules.get(diagnostic.rule) ?? 0) + 1);
160
+ for (const [file, size] of sizes) if (size > 2e4) oversizeFiles[file] = size;
161
+ return {
162
+ rules: Object.fromEntries(rules),
163
+ oversizeFiles
164
+ };
165
+ }
166
+ function measureBaseline(root, config) {
167
+ return baseline(root, lintDiagnostics(root, config));
168
+ }
169
+ function lowerCeilings(ceilings, current) {
170
+ const lowered = [];
171
+ for (const [rule, limit] of Object.entries(ceilings.rules)) {
172
+ const count = current.rules[rule] ?? 0;
173
+ if (count === 0) delete ceilings.rules[rule];
174
+ else if (count < limit) ceilings.rules[rule] = count;
175
+ if (count < limit) lowered.push(`${rule}: ${limit} -> ${count}`);
176
+ }
177
+ for (const [file, limit] of Object.entries(ceilings.oversizeFiles)) if (current.oversizeFiles[file] === void 0) {
178
+ delete ceilings.oversizeFiles[file];
179
+ lowered.push(`${file}: removed oversize allowance`);
180
+ } else if (current.oversizeFiles[file] < limit) {
181
+ ceilings.oversizeFiles[file] = current.oversizeFiles[file];
182
+ lowered.push(`${file}: ${limit} -> ${current.oversizeFiles[file]} bytes`);
183
+ }
184
+ return lowered;
185
+ }
186
+ /** Records today's count of each rule without a ceiling that the pack enabled after `adopted`. */
187
+ function adopt(ceilings, current, adopted) {
188
+ const adoptions = [];
189
+ for (const [rule, count] of Object.entries(current.rules)) {
190
+ if (Object.hasOwn(ceilings.rules, rule)) continue;
191
+ const since = newlyEnabled(rule, adopted);
192
+ if (since === void 0) continue;
193
+ ceilings.rules[rule] = count;
194
+ adoptions.push(`${rule}: ${count}, enabled by the pack in ${since}.`);
195
+ }
196
+ return adoptions;
197
+ }
198
+ function adoptionHint(rule, ceilings, adopted) {
199
+ const since = Object.hasOwn(ceilings.rules, rule) ? void 0 : newlyEnabled(rule, adopted);
200
+ if (since === void 0) return "";
201
+ return ` The pack enabled this rule in ${since}${adopted === void 0 ? "" : `, after this repository's ${adopted}`}; run ratchet:update to record today's count.`;
202
+ }
203
+ function ruleFailures(ceilings, current, diagnostics, changed, adopted) {
204
+ const failures = [];
205
+ for (const [rule, count] of Object.entries(current.rules)) {
206
+ const limit = ceilings.rules[rule] ?? 0;
207
+ if (count <= limit) continue;
208
+ failures.push(`${rule}: ${count} diagnostics exceeds ceiling ${limit}.${adoptionHint(rule, ceilings, adopted)}`);
209
+ const matches = diagnostics.filter((diagnostic) => diagnostic.rule === rule);
210
+ const inChanged = matches.filter(({ file }) => changed.has(file));
211
+ const shown = inChanged.length > 0 ? inChanged : matches;
212
+ for (const diagnostic of shown) failures.push(` ${diagnostic.location}: ${diagnostic.message}`);
213
+ if (shown.length < matches.length) failures.push(` ...and ${matches.length - shown.length} recorded in files this change does not touch.`);
214
+ }
215
+ return failures;
216
+ }
217
+ function sizeFailures(root, ceilings, current) {
218
+ const failures = [];
219
+ for (const [file, size] of Object.entries(current.oversizeFiles)) if (ceilings.oversizeFiles[file] === void 0) failures.push(size > 2e4 ? sizeFailure(file, size, MAX_FILE_BYTES) : `${file}: ${size} bytes and an eslint/max-lines diagnostic; this file has no oversize allowance. Split by responsibility into sibling modules, or split tests by behaviour under test, one file per describe.`);
220
+ const sizes = authoredSizes(root, Object.keys(ceilings.oversizeFiles));
221
+ for (const [file, limit] of Object.entries(ceilings.oversizeFiles)) {
222
+ const size = sizes.get(file);
223
+ if (size !== void 0 && size > limit) failures.push(sizeFailure(file, size, limit));
224
+ }
225
+ return failures;
226
+ }
227
+ /** Writes `ceilings`, or deletes the file once no debt is left; a clean repository gets a file only when it adopted a rule. */
228
+ function persist(root, ceilings, create) {
229
+ const path = join(root, CEILINGS_FILE);
230
+ const present = existsSync(path);
231
+ const retired = present && isRetired(ceilings);
232
+ if (retired) unlinkSync(path);
233
+ else if (present || create) writeFileSync(path, formatCeilings(ceilings));
234
+ return {
235
+ retired,
236
+ created: !present && create
237
+ };
238
+ }
239
+ /**
240
+ * Fails each rule above its ceiling and each file above its allowance. With
241
+ * `update`, first records today's count of each rule the pack enabled after
242
+ * the repository's adopted release (creating the file in a clean
243
+ * repository), then lowers the other ceilings and moves the recorded release
244
+ * forward. With `pullBase`, also fails each entry added or raised against
245
+ * that revision that is not such an adoption.
246
+ */
247
+ function ratchet(root, update = false, base = "HEAD", pullBase) {
248
+ if (!update && !existsSync(join(root, "guardrails.ratchet.json"))) throw new Error(`${CEILINGS_FILE} is missing. Run antelopejs-sync first.`);
249
+ const carried = readCarriedCeilings(root, false, [base]);
250
+ const ceilings = {
251
+ ...carried,
252
+ rules: { ...carried.rules }
253
+ };
254
+ const adopted = adoptedRelease(root, ceilings.pack, pullBase ?? "HEAD");
255
+ const diagnostics = lintDiagnostics(root);
256
+ const current = baseline(root, diagnostics);
257
+ const adoptions = update ? adopt(ceilings, current, adopted) : [];
258
+ const failures = [...ruleFailures(ceilings, current, diagnostics, changedFiles(root), adopted), ...sizeFailures(root, ceilings, current)];
259
+ const lowered = update ? lowerCeilings(ceilings, current) : [];
260
+ if (update) ceilings.pack = recordedRelease(adopted);
261
+ if (pullBase !== void 0) failures.push(...raisedRatchet(root, pullBase, ceilings, current));
262
+ const { retired, created } = update ? persist(root, ceilings, adoptions.length > 0) : {
263
+ retired: false,
264
+ created: false
265
+ };
266
+ return {
267
+ failures,
268
+ lowered,
269
+ adoptions,
270
+ retired,
271
+ created
272
+ };
273
+ }
274
+ //#endregion
275
+ export { ratchet as n, recordedRelease as r, measureBaseline as t };
@@ -1,4 +1,4 @@
1
- import { s as readCeilings } from "./ceilings-BSw9p4YB.mjs";
1
+ import { l as readCeilings } from "./ceilings-B7KayYIG.mjs";
2
2
  import { spawnSync } from "node:child_process";
3
3
  //#region src/guardrails/renames.ts
4
4
  /**
@@ -45,7 +45,7 @@ function carryAllowances(ceilings, renames) {
45
45
  }
46
46
  for (const [file, allowance] of moved) oversizeFiles[file] = allowance;
47
47
  return {
48
- rules: ceilings.rules,
48
+ ...ceilings,
49
49
  oversizeFiles
50
50
  };
51
51
  }
@@ -0,0 +1,73 @@
1
+ //#region src/verify/kinds.ts
2
+ /** The repository kinds whose verification skill is synced from this pack. */
3
+ const VERIFY_KINDS = [
4
+ "interface",
5
+ "module",
6
+ "template"
7
+ ];
8
+ /** Whether `value` names a shared verification kind. */
9
+ function isVerifyKind(value) {
10
+ return VERIFY_KINDS.some((kind) => kind === value);
11
+ }
12
+ /** The skill folder of a kind, relative to the repository root. */
13
+ function skillFolder(kind) {
14
+ return `.agents/skills/verify-${kind}`;
15
+ }
16
+ /** The `.claude/skills` link that exposes a kind's skill folder to Claude Code. */
17
+ function claudeLink(kind) {
18
+ return `.claude/skills/verify-${kind}`;
19
+ }
20
+ /** Where the link points, relative to the link's own folder. */
21
+ function claudeLinkTarget(kind) {
22
+ return `../../${skillFolder(kind)}`;
23
+ }
24
+ /** The files `antelopejs-sync` writes into a shared skill folder; everything else there is the repository's own. */
25
+ const SYNCED_SKILL_FILES = [
26
+ "SKILL.md",
27
+ "package.json",
28
+ "tsconfig.json"
29
+ ];
30
+ /**
31
+ * Every path under the agent directories that `antelopejs-sync` writes for the shared skills:
32
+ * each kind's synced files and its `.claude/skills` link, which shows the whole folder, repository files included, a second time.
33
+ */
34
+ function syncedAgentPaths() {
35
+ return VERIFY_KINDS.flatMap((kind) => [...SYNCED_SKILL_FILES.map((file) => `${skillFolder(kind)}/${file}`), claudeLink(kind)]);
36
+ }
37
+ //#endregion
38
+ //#region src/oxc/shared.ts
39
+ /**
40
+ * Paths every AntelopeJS project generates or vendors, and that no linter should read.
41
+ * `.github/ISSUE_TEMPLATE/**` holds GitHub's legacy issue templates: Markdown with
42
+ * YAML frontmatter saved under a .yml extension, which a YAML formatter cannot parse.
43
+ * `build/**` and `output/**` match only at the repository root: a directory with
44
+ * either name under `src/` or another authored root is source, not build output.
45
+ */
46
+ const IGNORE_PATTERNS = [
47
+ "**/node_modules/**",
48
+ "**/dist/**",
49
+ "**/coverage/**",
50
+ "**/.antelope/**",
51
+ "**/.nuxt/**",
52
+ "**/.output/**",
53
+ "build/**",
54
+ "output/**",
55
+ "**/i18n-registry.generated.ts",
56
+ ".github/ISSUE_TEMPLATE/**"
57
+ ];
58
+ /** Agent tooling directories: assets we install, not source we own. */
59
+ const AGENT_IGNORE_PATTERNS = [
60
+ ".agent/**",
61
+ ".agents/**",
62
+ ".amp/**",
63
+ ".claude/**",
64
+ ".codex/**",
65
+ ".cursor/**",
66
+ ".gemini/**",
67
+ ".opencode/**",
68
+ ".windsurf/**"
69
+ ];
70
+ /** What `antelopejs-sync` writes under the agent directories, from the list it syncs; the repository's own files there stay linted. */
71
+ const SYNCED_AGENT_PATTERNS = syncedAgentPaths().flatMap((path) => [path, `${path}/**`]);
72
+ //#endregion
73
+ export { VERIFY_KINDS as a, isVerifyKind as c, SYNCED_SKILL_FILES as i, skillFolder as l, IGNORE_PATTERNS as n, claudeLink as o, SYNCED_AGENT_PATTERNS as r, claudeLinkTarget as s, AGENT_IGNORE_PATTERNS as t };
@@ -1,6 +1,6 @@
1
- import "./ceilings-BSw9p4YB.mjs";
2
- import { t as readCarriedCeilings } from "./renames-BGO4dWJ8.mjs";
3
- import { t as authoredSizes } from "./files-2FikHZ9F.mjs";
1
+ import "./ceilings-B7KayYIG.mjs";
2
+ import { t as readCarriedCeilings } from "./renames-L2owF5GD.mjs";
3
+ import { t as authoredSizes } from "./files-Bc036sJW.mjs";
4
4
  //#region src/guardrails/size.ts
5
5
  function sizeFailure(file, size, limit) {
6
6
  return `${file}: ${size} bytes, ${size - limit} bytes over the ${limit}-byte ceiling. Split by responsibility into sibling modules, one cohesive group of exports each; keep the original path re-exporting only if it is a public entry point. Split a test file by behaviour under test, one file per describe. Do not minify, strip whitespace, or move code under an excluded path to pass.`;
@@ -0,0 +1,95 @@
1
+ import { s as resolveRevision } from "./files-Bc036sJW.mjs";
2
+ import { a as parseBudget, n as SUPPRESSIONS_FILE, o as safetyCeiling, p as coveredLimits } from "./suppression-budget-Bd2GqMYb.mjs";
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { spawnSync } from "node:child_process";
6
+ //#region src/guardrails/suppression-base.ts
7
+ function verified(root, ref) {
8
+ const result = spawnSync("git", [
9
+ "rev-parse",
10
+ "--verify",
11
+ "--quiet",
12
+ "--end-of-options",
13
+ `${ref}^{commit}`
14
+ ], {
15
+ cwd: root,
16
+ encoding: "utf8"
17
+ });
18
+ return result.status === 0 ? result.stdout.trim() : void 0;
19
+ }
20
+ function fetchBase(root, branch, remote) {
21
+ const result = spawnSync("git", [
22
+ "fetch",
23
+ "--quiet",
24
+ "--no-tags",
25
+ "--depth=1",
26
+ "origin",
27
+ `+refs/heads/${branch}:${remote}`
28
+ ], {
29
+ cwd: root,
30
+ encoding: "utf8",
31
+ env: {
32
+ ...process.env,
33
+ GIT_TERMINAL_PROMPT: "0"
34
+ },
35
+ stdio: [
36
+ "ignore",
37
+ "ignore",
38
+ "pipe"
39
+ ]
40
+ });
41
+ if (result.status === 0) return;
42
+ const detail = result.error?.message ?? result.stderr.trim();
43
+ 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.`);
44
+ }
45
+ /**
46
+ * The commit a pull request merges into: `base` when given; in CI the
47
+ * `GITHUB_BASE_REF` branch, taken from the local `origin/<branch>` ref when
48
+ * present and otherwise fetched from `origin`, an error naming the missing ref
49
+ * when the fetch fails; otherwise `origin/HEAD`, the remote's default branch.
50
+ * A requested base that cannot be resolved is an error; without one, a
51
+ * repository with no `origin/HEAD` has no base.
52
+ */
53
+ function suppressionBase(root, base) {
54
+ if (base !== void 0) return resolveRevision(root, base);
55
+ const branch = process.env.GITHUB_BASE_REF;
56
+ if (branch) {
57
+ const remote = `refs/remotes/origin/${branch}`;
58
+ if (verified(root, remote) === void 0) fetchBase(root, branch, remote);
59
+ return resolveRevision(root, remote);
60
+ }
61
+ return verified(root, "refs/remotes/origin/HEAD");
62
+ }
63
+ /**
64
+ * Fails each ceiling of the working-tree budget that is higher than on
65
+ * `revision`, and each rule that `revision` lists but the working tree
66
+ * dropped, config rule-offs included once the base has their ceilings; a
67
+ * config ceiling may rise by what a containing scope of its rule falls. The
68
+ * safety ceiling may rise by what the SAFETY rule's own ceiling falls. A
69
+ * base without a budget, a first adoption, passes.
70
+ */
71
+ function raisedCeilings(root, revision) {
72
+ const committed = spawnSync("git", ["show", `${revision}:${SUPPRESSIONS_FILE}`], {
73
+ cwd: root,
74
+ encoding: "utf8"
75
+ });
76
+ if (committed.status !== 0) return [];
77
+ const label = `${revision.slice(0, 12)}:${SUPPRESSIONS_FILE}`;
78
+ const base = parseBudget(committed.stdout, label);
79
+ const current = parseBudget(readFileSync(join(root, SUPPRESSIONS_FILE), "utf8"), SUPPRESSIONS_FILE);
80
+ const failures = [];
81
+ const compare = (key, before, after) => {
82
+ 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.`);
83
+ else if (after > before) failures.push(`${SUPPRESSIONS_FILE}: raises ${key} from ${before} on the base to ${after}.`);
84
+ };
85
+ 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);
86
+ const baseConfig = base.config ?? {};
87
+ const covered = coveredLimits(baseConfig, current.config ?? {});
88
+ 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);
89
+ compare("`@ts-expect-error`", base.tsExpectError, current.tsExpectError);
90
+ compare("`@ts-ignore`", base.tsIgnore, current.tsIgnore);
91
+ compare("`SAFETY:` comments", safetyCeiling(base, current.rules["anti-slop/require-safety-comment-for-type-assertion"] ?? 0), current.safety);
92
+ 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."] : [];
93
+ }
94
+ //#endregion
95
+ export { suppressionBase as n, raisedCeilings as t };