@antelopejs/tooling-configs 0.2.10 → 0.2.12

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.
@@ -0,0 +1,94 @@
1
+ import { i as isObject } from "./json-BqvuCkqr.mjs";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ //#region src/verify/checks.ts
4
+ function excerpt(text) {
5
+ const flat = text.replace(/\s+/g, " ").trim();
6
+ return flat.length > 300 ? `${flat.slice(0, 300)}…` : flat;
7
+ }
8
+ /** The process exited with `code`. */
9
+ function exitIs(result, code) {
10
+ return {
11
+ name: `exit code ${code}`,
12
+ pass: result.exitCode === code,
13
+ detail: `exit code ${result.exitCode}`
14
+ };
15
+ }
16
+ /** The process ended on SIGINT, by exit code 130 or by the signal itself. */
17
+ function interrupted(result) {
18
+ return {
19
+ name: "ended by SIGINT (exit 130)",
20
+ pass: result.exitCode === 130 || result.signal === "SIGINT",
21
+ detail: `exit code ${result.exitCode}, signal ${result.signal}`
22
+ };
23
+ }
24
+ /** `text` matches `pattern`; `label` names the stream. */
25
+ function has(label, text, pattern) {
26
+ return {
27
+ name: `${label} matches ${pattern}`,
28
+ pass: pattern.test(text),
29
+ detail: excerpt(text)
30
+ };
31
+ }
32
+ /** `text` does not match `pattern`. */
33
+ function lacks(label, text, pattern) {
34
+ return {
35
+ name: `${label} does not match ${pattern}`,
36
+ pass: !pattern.test(text),
37
+ detail: excerpt(text)
38
+ };
39
+ }
40
+ /** A file or folder exists at `file`. */
41
+ function exists(file) {
42
+ const present = existsSync(file);
43
+ return {
44
+ name: `${file} exists`,
45
+ pass: present,
46
+ detail: present ? "present" : "missing"
47
+ };
48
+ }
49
+ /** The file at `file` matches `pattern`. */
50
+ function fileHas(file, pattern) {
51
+ const text = existsSync(file) ? readFileSync(file, "utf8") : "";
52
+ return {
53
+ name: `${file} matches ${pattern}`,
54
+ pass: pattern.test(text),
55
+ detail: excerpt(text)
56
+ };
57
+ }
58
+ /** Two values are deeply equal once serialized. */
59
+ function equal(name, actual, expected) {
60
+ const left = JSON.stringify(actual);
61
+ const right = JSON.stringify(expected);
62
+ return {
63
+ name,
64
+ pass: left === right,
65
+ detail: `expected ${right}, got ${left}`
66
+ };
67
+ }
68
+ /** The request answered `status` (200 by default). */
69
+ function answered(result, status = 200) {
70
+ return {
71
+ name: `${result.url} answers ${status}`,
72
+ pass: result.status === status,
73
+ detail: result.error ?? `status ${result.status}, body ${excerpt(result.body)}`
74
+ };
75
+ }
76
+ /** The request answered 200 with JSON whose `key` is `expected`. */
77
+ function answers(result, key, expected) {
78
+ const actual = result.json !== void 0 && isObject(result.json) ? result.json[key] : void 0;
79
+ return {
80
+ name: `${result.url} answers 200 with ${key} ${JSON.stringify(expected)}`,
81
+ pass: result.status === 200 && JSON.stringify(actual) === JSON.stringify(expected),
82
+ detail: result.error ?? `status ${result.status}, body ${excerpt(result.body)}`
83
+ };
84
+ }
85
+ /** Nothing answered the request. */
86
+ function refused(result) {
87
+ return {
88
+ name: `${result.url} is refused`,
89
+ pass: result.status === null,
90
+ detail: result.error ?? `status ${result.status}`
91
+ };
92
+ }
93
+ //#endregion
94
+ export { exitIs as a, interrupted as c, exists as i, lacks as l, answers as n, fileHas as o, equal as r, has as s, answered as t, refused as u };
@@ -0,0 +1,67 @@
1
+ //#region src/garden/json.ts
2
+ /** Raised when an API payload lacks a field the Gardener relies on. */
3
+ var DecodeError = class extends Error {};
4
+ function isString(value) {
5
+ return String(value) === value;
6
+ }
7
+ function isNumber(value) {
8
+ return Number.isFinite(value);
9
+ }
10
+ function isObject(value) {
11
+ return Object(value) === value && !Array.isArray(value);
12
+ }
13
+ function parseJson(text) {
14
+ return JSON.parse(text);
15
+ }
16
+ function object(value, path) {
17
+ if (!isObject(value)) throw new DecodeError(`${path}: expected an object`);
18
+ return value;
19
+ }
20
+ function list(value, path) {
21
+ if (!Array.isArray(value)) throw new DecodeError(`${path}: expected a list`);
22
+ return value;
23
+ }
24
+ function str(source, key) {
25
+ const value = source[key];
26
+ if (value === void 0 || !isString(value)) throw new DecodeError(`${key}: expected a string`);
27
+ return value;
28
+ }
29
+ function optStr(source, key) {
30
+ const value = source[key];
31
+ return value !== void 0 && isString(value) ? value : void 0;
32
+ }
33
+ function num(source, key) {
34
+ const value = source[key];
35
+ if (value === void 0 || !isNumber(value)) throw new DecodeError(`${key}: expected a number`);
36
+ return value;
37
+ }
38
+ function optNum(source, key) {
39
+ const value = source[key];
40
+ return value !== void 0 && isNumber(value) ? value : void 0;
41
+ }
42
+ function flag(source, key) {
43
+ return source[key] === true;
44
+ }
45
+ function child(source, key) {
46
+ const value = source[key];
47
+ return value === void 0 ? {} : object(value, key);
48
+ }
49
+ function children(source, key) {
50
+ const value = source[key];
51
+ return value === void 0 ? [] : list(value, key).map((entry) => object(entry, key));
52
+ }
53
+ function strings(source, key) {
54
+ const value = source[key];
55
+ return value === void 0 ? [] : list(value, key).filter((entry) => isString(entry));
56
+ }
57
+ function time(source, key) {
58
+ const value = Date.parse(str(source, key));
59
+ if (Number.isNaN(value)) throw new DecodeError(`${key}: expected a date`);
60
+ return value;
61
+ }
62
+ function optTime(source, key) {
63
+ const value = optStr(source, key);
64
+ return value === void 0 ? void 0 : Date.parse(value);
65
+ }
66
+ //#endregion
67
+ export { isString as a, object as c, optTime as d, parseJson as f, time as h, isObject as i, optNum as l, strings as m, children as n, list as o, str as p, flag as r, num as s, child as t, optStr as u };
@@ -0,0 +1,25 @@
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
+ //#endregion
25
+ export { skillFolder as a, isVerifyKind as i, claudeLink as n, claudeLinkTarget as r, VERIFY_KINDS as t };
@@ -1,4 +1,6 @@
1
1
  import { a as matcherChain, i as isAssertion, n as TEST_FILE_GLOBS, o as memberName, r as callName, s as testCallback, t as ASSERTION_FUNCTION_NAMES } from "../../shared-WC0z3y9F.mjs";
2
+ import { lstatSync, readFileSync, realpathSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
2
4
  import { defineRule, eslintCompatPlugin } from "@oxlint/plugins";
3
5
  //#region src/oxc/guardrails/rules/no-comments.ts
4
6
  const allowedCommentForms = [
@@ -191,6 +193,122 @@ const noFsReadInTestsRule = defineRule({
191
193
  }
192
194
  });
193
195
  //#endregion
196
+ //#region src/oxc/guardrails/self-package.ts
197
+ function isObject(value) {
198
+ return typeof value === "object" && value !== null && !Array.isArray(value);
199
+ }
200
+ function isText(value) {
201
+ return typeof value === "string";
202
+ }
203
+ function readManifest(directory) {
204
+ let parsed;
205
+ try {
206
+ parsed = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
207
+ } catch {
208
+ return;
209
+ }
210
+ if (!isObject(parsed) || !isText(parsed.name)) return void 0;
211
+ return {
212
+ name: parsed.name,
213
+ exports: parsed.exports
214
+ };
215
+ }
216
+ /** The nearest enclosing package that has a name, with the directory holding its manifest. */
217
+ function enclosingPackage(file) {
218
+ let directory = dirname(file);
219
+ for (;;) {
220
+ const manifest = readManifest(directory);
221
+ if (manifest !== void 0) return {
222
+ directory,
223
+ manifest
224
+ };
225
+ const parent = dirname(directory);
226
+ if (parent === directory) return void 0;
227
+ directory = parent;
228
+ }
229
+ }
230
+ /** The subpath of `specifier` inside package `name` (`.` for the root), or undefined when it names another package. */
231
+ function selfSubpath(name, specifier) {
232
+ if (specifier === name) return ".";
233
+ return specifier.startsWith(`${name}/`) ? `./${specifier.slice(name.length + 1)}` : void 0;
234
+ }
235
+ function exportKeys(exportsField) {
236
+ if (!isObject(exportsField)) return ["."];
237
+ const keys = Object.keys(exportsField);
238
+ return keys.some((key) => key.startsWith(".")) ? keys : ["."];
239
+ }
240
+ function patternMatches(key, subpath) {
241
+ const star = key.indexOf("*");
242
+ if (star === -1) return key === subpath;
243
+ const prefix = key.slice(0, star);
244
+ const suffix = key.slice(star + 1);
245
+ return subpath.length >= key.length - 1 && subpath.startsWith(prefix) && subpath.endsWith(suffix);
246
+ }
247
+ /** Whether the package `exports` map publishes `subpath`, so Node can resolve a self-import to it. */
248
+ function exportsCover(exportsField, subpath) {
249
+ if (exportsField === void 0 || exportsField === null) return false;
250
+ return exportKeys(exportsField).some((key) => patternMatches(key, subpath));
251
+ }
252
+ /** Whether `node_modules/<name>` is a link back to the package itself, as a workspace self-link makes it. */
253
+ function isSelfLinked(directory, name) {
254
+ const installed = join(directory, "node_modules", ...name.split("/"));
255
+ try {
256
+ return lstatSync(installed).isSymbolicLink() && realpathSync(installed) === realpathSync(directory);
257
+ } catch {
258
+ return false;
259
+ }
260
+ }
261
+ //#endregion
262
+ //#region src/oxc/guardrails/rules/no-self-import-in-tests.ts
263
+ /** A test that imports its own package name must reach local code: the `exports` map publishes the subpath and `node_modules` links the package to itself. */
264
+ const noSelfImportInTestsRule = defineRule({
265
+ meta: {
266
+ type: "problem",
267
+ docs: { description: "Tests import the module under test from local source, never their own published package name." },
268
+ messages: { selfImport: "This test imports its own package `{{ name }}`, which resolves to the installed published copy, so it never exercises the local code. Import the module under test by relative path, or make the self-import local: publish `{{ subpath }}` in package.json `exports` and link the package to itself (`link:.` in devDependencies)." }
269
+ },
270
+ createOnce(context) {
271
+ function check(node, specifier) {
272
+ const owner = enclosingPackage(context.filename);
273
+ if (owner === void 0) return;
274
+ const { directory, manifest } = owner;
275
+ const subpath = selfSubpath(manifest.name, specifier);
276
+ if (subpath === void 0 || exportsCover(manifest.exports, subpath) && isSelfLinked(directory, manifest.name)) return;
277
+ context.report({
278
+ node,
279
+ messageId: "selfImport",
280
+ data: {
281
+ name: manifest.name,
282
+ subpath
283
+ }
284
+ });
285
+ }
286
+ return {
287
+ ImportDeclaration(node) {
288
+ if (node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every((specifier) => specifier.type === "ImportSpecifier" && specifier.importKind === "type")) return;
289
+ check(node, node.source.value);
290
+ },
291
+ ExportNamedDeclaration(node) {
292
+ if (node.source && node.exportKind !== "type") check(node, node.source.value);
293
+ },
294
+ ExportAllDeclaration(node) {
295
+ if (node.exportKind !== "type") check(node, node.source.value);
296
+ },
297
+ ImportExpression(node) {
298
+ if (node.source.type === "Literal" && !("regex" in node.source)) check(node, String(node.source.value));
299
+ },
300
+ TSImportEqualsDeclaration(node) {
301
+ const reference = node.moduleReference;
302
+ if (node.importKind !== "type" && reference.type === "TSExternalModuleReference") check(node, reference.expression.value);
303
+ },
304
+ CallExpression(node) {
305
+ const [argument] = node.arguments;
306
+ if (node.callee.type === "Identifier" && node.callee.name === "require" && argument?.type === "Literal" && !("regex" in argument)) check(node, String(argument.value));
307
+ }
308
+ };
309
+ }
310
+ });
311
+ //#endregion
194
312
  //#region src/oxc/guardrails/rules/no-typeof-function-only-test.ts
195
313
  const functionMatchers = /* @__PURE__ */ new Set([
196
314
  "toBeTypeOf",
@@ -310,6 +428,7 @@ const guardrailsPlugin = eslintCompatPlugin({
310
428
  "no-comments": noCommentsRule,
311
429
  "no-fs-read-in-tests": noFsReadInTestsRule,
312
430
  "no-constant-value-assertion": noConstantValueAssertionRule,
431
+ "no-self-import-in-tests": noSelfImportInTestsRule,
313
432
  "no-typeof-function-only-test": noTypeofFunctionOnlyTestRule,
314
433
  "require-assertion": requireAssertionRule
315
434
  }
@@ -81,6 +81,7 @@ declare function guardrailsRules(): {
81
81
  rules: {
82
82
  "antelopejs/no-fs-read-in-tests": "error";
83
83
  "antelopejs/no-constant-value-assertion": "error";
84
+ "antelopejs/no-self-import-in-tests": "error";
84
85
  "antelopejs/no-typeof-function-only-test": "error";
85
86
  "antelopejs/require-assertion": "error";
86
87
  };
@@ -89,6 +90,7 @@ declare function guardrailsRules(): {
89
90
  rules: {
90
91
  "antelopejs/no-fs-read-in-tests": "off";
91
92
  "antelopejs/no-constant-value-assertion"?: undefined;
93
+ "antelopejs/no-self-import-in-tests"?: undefined;
92
94
  "antelopejs/no-typeof-function-only-test"?: undefined;
93
95
  "antelopejs/require-assertion"?: undefined;
94
96
  };
@@ -165,6 +167,7 @@ declare function antelopePreset(options?: AntelopePresetOptions): {
165
167
  rules: {
166
168
  "antelopejs/no-fs-read-in-tests": "error";
167
169
  "antelopejs/no-constant-value-assertion": "error";
170
+ "antelopejs/no-self-import-in-tests": "error";
168
171
  "antelopejs/no-typeof-function-only-test": "error";
169
172
  "antelopejs/require-assertion": "error";
170
173
  };
@@ -173,6 +176,7 @@ declare function antelopePreset(options?: AntelopePresetOptions): {
173
176
  rules: {
174
177
  "antelopejs/no-fs-read-in-tests": "off";
175
178
  "antelopejs/no-constant-value-assertion"?: undefined;
179
+ "antelopejs/no-self-import-in-tests"?: undefined;
176
180
  "antelopejs/no-typeof-function-only-test"?: undefined;
177
181
  "antelopejs/require-assertion"?: undefined;
178
182
  };
package/dist/oxc/lint.mjs CHANGED
@@ -114,6 +114,7 @@ function guardrailsRules() {
114
114
  rules: {
115
115
  "antelopejs/no-fs-read-in-tests": "error",
116
116
  "antelopejs/no-constant-value-assertion": "error",
117
+ "antelopejs/no-self-import-in-tests": "error",
117
118
  "antelopejs/no-typeof-function-only-test": "error",
118
119
  "antelopejs/require-assertion": "error"
119
120
  }
@@ -1,7 +1,7 @@
1
1
  import { a as formatCeilings, n as MAX_FILE_BYTES, o as isRetired, t as CEILINGS_FILE } from "./ceilings-BSw9p4YB.mjs";
2
2
  import { t as readCarriedCeilings } from "./renames-BGO4dWJ8.mjs";
3
3
  import { n as changedFiles, t as authoredSizes } from "./files-2FikHZ9F.mjs";
4
- import { r as lintDiagnostics } from "./staged-ratchet-BNfjcbih.mjs";
4
+ import { r as lintDiagnostics } from "./staged-ratchet-CjoRfZaM.mjs";
5
5
  import { n as sizeFailure } from "./size-BVgNbLO6.mjs";
6
6
  import { existsSync, unlinkSync, writeFileSync } from "node:fs";
7
7
  import { join } from "node:path";
@@ -0,0 +1,236 @@
1
+ import { r as MEASURE_ENV, s as readCeilings } from "./ceilings-BSw9p4YB.mjs";
2
+ import { n as renamedPaths } from "./renames-BGO4dWJ8.mjs";
3
+ import { a as repositoryPath } from "./files-2FikHZ9F.mjs";
4
+ import { createRequire } from "node:module";
5
+ import { copyFileSync, existsSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
6
+ import { basename, dirname, join } from "node:path";
7
+ import { execFileSync, spawnSync } from "node:child_process";
8
+ import { tmpdir } from "node:os";
9
+ //#region src/guardrails/oxlint.ts
10
+ function resolveOxlint(root) {
11
+ try {
12
+ const require = createRequire(join(root, "package.json"));
13
+ return join(dirname(require.resolve("oxlint/package.json")), "bin/oxlint");
14
+ } catch {
15
+ throw new Error("oxlint is not installed in this repository. Install dependencies first.");
16
+ }
17
+ }
18
+ function ruleId(code) {
19
+ const match = /^([^()]+)\(([^()]+)\)$/.exec(code);
20
+ if (!match) throw new Error(`Cannot measure oxlint diagnostic code ${JSON.stringify(code)}. Fix parser or configuration errors before recording a baseline.`);
21
+ const [, plugin, rule] = match;
22
+ return `${plugin === "typescript-eslint" ? "typescript" : plugin}/${rule}`;
23
+ }
24
+ function parseDiagnostics(text, root) {
25
+ const report = JSON.parse(text);
26
+ if (!Array.isArray(report?.diagnostics)) throw new Error("oxlint did not return a JSON diagnostics array.");
27
+ return report.diagnostics.map((item) => {
28
+ const file = repositoryPath(root, item.filename);
29
+ const span = item.labels?.[0]?.span;
30
+ return {
31
+ rule: ruleId(item.code),
32
+ file,
33
+ location: span ? `${file}:${span.line}:${span.column}` : file,
34
+ message: item.message,
35
+ line: span?.line,
36
+ help: item.help
37
+ };
38
+ });
39
+ }
40
+ function lintDiagnostics(root, config, files) {
41
+ const binary = resolveOxlint(root);
42
+ const temporary = config === void 0 ? void 0 : mkdtempSync(join(root, ".antelopejs-measure.generated."));
43
+ try {
44
+ const args = [
45
+ binary,
46
+ "-f",
47
+ "json"
48
+ ];
49
+ if (temporary) {
50
+ const path = join(temporary, "oxlint.config.ts");
51
+ writeFileSync(path, config ?? "");
52
+ args.push("--config", path, "--ignore-pattern", `${basename(temporary)}/**`);
53
+ }
54
+ if (files) args.push("--no-error-on-unmatched-pattern", "--", ...files);
55
+ const result = spawnSync(process.execPath, args, {
56
+ cwd: root,
57
+ encoding: "utf8",
58
+ env: {
59
+ ...process.env,
60
+ [MEASURE_ENV]: "1"
61
+ },
62
+ maxBuffer: 67108864
63
+ });
64
+ if (result.error) throw result.error;
65
+ if (result.status !== 0 && result.status !== 1) throw new Error(`oxlint failed (${result.status ?? result.signal}): ${result.stderr || result.stdout}`);
66
+ const diagnostics = parseDiagnostics(result.stdout, root);
67
+ if (result.status !== 0 && diagnostics.length === 0) throw new Error(`oxlint failed without diagnostics: ${result.stderr || result.stdout}`);
68
+ return diagnostics;
69
+ } finally {
70
+ if (temporary) rmSync(temporary, {
71
+ recursive: true,
72
+ force: true
73
+ });
74
+ }
75
+ }
76
+ //#endregion
77
+ //#region src/guardrails/previous-tree.ts
78
+ function git(root, args, env, input = "") {
79
+ return execFileSync("git", args, {
80
+ cwd: root,
81
+ encoding: "utf8",
82
+ env: {
83
+ ...process.env,
84
+ ...env
85
+ },
86
+ input,
87
+ maxBuffer: 268435456
88
+ });
89
+ }
90
+ function headEntries(root) {
91
+ const entries = /* @__PURE__ */ new Map();
92
+ for (const entry of git(root, [
93
+ "ls-tree",
94
+ "-r",
95
+ "-z",
96
+ "HEAD"
97
+ ], {}).split("\0")) {
98
+ const tab = entry.indexOf(" ");
99
+ if (tab > 0) entries.set(entry.slice(tab + 1), entry.slice(0, tab));
100
+ }
101
+ return entries;
102
+ }
103
+ /**
104
+ * Runs `use` on a checkout of the index in which each of `paths` holds its
105
+ * HEAD content, or is absent when HEAD does not have it, so the files are
106
+ * linted under the staged configuration. The checkout is deleted afterwards.
107
+ */
108
+ function withPreviousTree(root, paths, use) {
109
+ const scratch = mkdtempSync(join(tmpdir(), "antelopejs-previous."));
110
+ try {
111
+ const hasHead = spawnSync("git", [
112
+ "rev-parse",
113
+ "--verify",
114
+ "HEAD"
115
+ ], {
116
+ cwd: root,
117
+ stdio: "ignore"
118
+ }).status === 0;
119
+ const index = join(scratch, "index");
120
+ copyFileSync(git(root, [
121
+ "rev-parse",
122
+ "--path-format=absolute",
123
+ "--git-path",
124
+ "index"
125
+ ], {}).trim(), index);
126
+ const env = { GIT_INDEX_FILE: index };
127
+ const head = hasHead ? headEntries(root) : /* @__PURE__ */ new Map();
128
+ const restored = paths.filter((path) => head.has(path));
129
+ const removed = paths.filter((path) => !head.has(path));
130
+ if (restored.length) git(root, [
131
+ "update-index",
132
+ "-z",
133
+ "--index-info"
134
+ ], env, restored.map((path) => `${head.get(path)}\t${path}\0`).join(""));
135
+ if (removed.length) git(root, [
136
+ "update-index",
137
+ "-z",
138
+ "--force-remove",
139
+ "--stdin"
140
+ ], env, removed.map((path) => `${path}\0`).join(""));
141
+ const tree = join(scratch, "tree");
142
+ git(root, [
143
+ "checkout-index",
144
+ "-a",
145
+ "-f",
146
+ `--prefix=${tree}/`
147
+ ], env);
148
+ if (existsSync(join(root, "node_modules"))) symlinkSync(join(root, "node_modules"), join(tree, "node_modules"), "dir");
149
+ return use(tree);
150
+ } finally {
151
+ rmSync(scratch, {
152
+ recursive: true,
153
+ force: true
154
+ });
155
+ }
156
+ }
157
+ //#endregion
158
+ //#region src/guardrails/staged-ratchet.ts
159
+ /** The line ranges each staged file adds against HEAD, following renames. */
160
+ function stagedAdditions(root, targets) {
161
+ const renames = renamedPaths(root, true);
162
+ const additions = /* @__PURE__ */ new Map();
163
+ for (const file of targets) {
164
+ const diff = execFileSync("git", [
165
+ "diff",
166
+ "--cached",
167
+ "--no-ext-diff",
168
+ "--no-color",
169
+ "--unified=0",
170
+ "--find-renames",
171
+ "--",
172
+ ...[renames.get(file), file].filter((path) => path !== void 0)
173
+ ], {
174
+ cwd: root,
175
+ encoding: "utf8"
176
+ });
177
+ additions.set(file, Array.from(diff.matchAll(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/gm), ([, line, count]) => ({
178
+ start: Number(line),
179
+ end: Number(line) + Number(count ?? 1) - 1
180
+ })));
181
+ }
182
+ return additions;
183
+ }
184
+ function stagedNames(root, filter) {
185
+ return execFileSync("git", [
186
+ "diff",
187
+ "--cached",
188
+ "--name-only",
189
+ `--diff-filter=${filter}`,
190
+ "-z"
191
+ ], {
192
+ cwd: root,
193
+ encoding: "utf8"
194
+ }).split("\0").filter(Boolean);
195
+ }
196
+ function countByRule(diagnostics) {
197
+ const counts = /* @__PURE__ */ new Map();
198
+ for (const { rule } of diagnostics) counts.set(rule, (counts.get(rule) ?? 0) + 1);
199
+ return counts;
200
+ }
201
+ const LINT_CONFIG = /(?:^|\/)(?:oxlint\.config\.[cm]?[jt]s|\.oxlintrc\.jsonc?)$/u;
202
+ function headCounts(root, targets) {
203
+ const renames = renamedPaths(root, true);
204
+ const previous = [.../* @__PURE__ */ new Set([...targets.map((file) => renames.get(file) ?? file), ...stagedNames(root, "D")])];
205
+ return countByRule(withPreviousTree(root, previous.filter((file) => !LINT_CONFIG.test(file)), (tree) => {
206
+ const existing = previous.filter((file) => existsSync(join(tree, file)));
207
+ return existing.length ? lintDiagnostics(tree, void 0, existing) : [];
208
+ }));
209
+ }
210
+ /**
211
+ * Fails each ceilinged rule whose findings in the staged files outnumber those
212
+ * the same files, rename sources and deleted files had at HEAD. The count is
213
+ * net across the staged files, so a block moved between them, or a legacy line
214
+ * that is reformatted, passes; any net rise fails, and lists the findings on
215
+ * the lines the commit adds.
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 before = headCounts(root, targets);
224
+ const additions = stagedAdditions(root, targets);
225
+ const failures = [];
226
+ for (const [rule, total] of countByRule(after)) {
227
+ const rise = total - (before.get(rule) ?? 0);
228
+ if (rise <= 0) continue;
229
+ const matches = after.filter((diagnostic) => diagnostic.rule === rule);
230
+ const added = matches.filter(({ file, line }) => line !== void 0 && additions.get(file)?.some(({ start, end }) => line >= start && line <= end));
231
+ failures.push(`${rule}: this commit adds ${rise} to the staged files (${before.get(rule) ?? 0} at HEAD, ${total} staged); the ceiling covers only legacy findings.`, ...(added.length ? added : matches).map((diagnostic) => ` ${diagnostic.location}: ${diagnostic.message}\n Fix: ${diagnostic.help ?? "Resolve this finding; moving or reformatting a legacy finding is allowed, adding one is not."}`));
232
+ }
233
+ return failures;
234
+ }
235
+ //#endregion
236
+ export { stagedRatchet as n, lintDiagnostics as r, stagedAdditions as t };
@@ -1,6 +1,6 @@
1
1
  import { n as renamedPaths } from "./renames-BGO4dWJ8.mjs";
2
2
  import { n as changedFiles } from "./files-2FikHZ9F.mjs";
3
- import { t as stagedAdditions } from "./staged-ratchet-BNfjcbih.mjs";
3
+ import { t as stagedAdditions } from "./staged-ratchet-CjoRfZaM.mjs";
4
4
  import { a as revisionSuppressions, i as openDisablesIn, n as countSuppressions, o as worktreeSuppressions, r as inWorktree, t as atRevision } from "./suppressions-BJAngUxo.mjs";
5
5
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
6
6
  import { join } from "node:path";
@@ -12,6 +12,7 @@ const NEVER_SUPPRESSED = /* @__PURE__ */ new Map([
12
12
  ["antelopejs/no-comments", "say it in code, move a public contract into TSDoc, or delete the comment"],
13
13
  ["antelopejs/no-constant-value-assertion", "assert on a value the code under test computes, or delete the test"],
14
14
  ["antelopejs/no-fs-read-in-tests", "drive the behaviour through the public interface, or read from fixtures/"],
15
+ ["antelopejs/no-self-import-in-tests", "import the module under test by relative path, or publish the subpath in exports and link the package to itself"],
15
16
  ["antelopejs/no-typeof-function-only-test", "assert on what the function returns or does, or delete the test"],
16
17
  ["antelopejs/require-assertion", "assert on the behaviour, or delete the test"],
17
18
  ["typescript/ban-ts-comment", "use `@ts-expect-error <reason>`"]