@antelopejs/tooling-configs 0.2.16 → 0.2.18
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 +101 -52
- package/dist/bin/api-diff.mjs +430 -107
- package/dist/bin/body-check.d.mts +1 -0
- package/dist/bin/body-check.mjs +344 -0
- package/dist/bin/capture.d.mts +1 -0
- package/dist/bin/capture.mjs +559 -0
- package/dist/bin/check-size.mjs +3 -3
- package/dist/bin/checks.mjs +3 -3
- package/dist/bin/comment-proof.mjs +4 -3
- package/dist/bin/garden.mjs +6 -6
- package/dist/bin/ratchet.mjs +316 -10
- package/dist/bin/suppressions.mjs +118 -80
- package/dist/bin/sync.mjs +554 -153
- package/dist/bin/verify.mjs +240 -127
- package/dist/capture/index.d.mts +50 -0
- package/dist/capture/index.mjs +2 -0
- package/dist/{ceilings-BSw9p4YB.mjs → ceilings-B7KayYIG.mjs} +11 -3
- package/dist/{checks-BlWDFYio.mjs → checks-CxkSu2E6.mjs} +1 -1
- package/dist/{ci-workflow-DIsoEgMd.mjs → ci-workflow-ChW4He0r.mjs} +84 -3
- package/dist/{files-2FikHZ9F.mjs → files-DJ0TeaTU.mjs} +11 -5
- package/dist/formal/index.d.mts +40 -0
- package/dist/formal/index.mjs +205 -0
- package/dist/{json-BqvuCkqr.mjs → json-CG2L7YFl.mjs} +12 -8
- package/dist/oxc/anti-slop/index.mjs +869 -21
- package/dist/oxc/fmt.mjs +1 -1
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +736 -4
- package/dist/oxc/lint.d.mts +20 -3
- package/dist/oxc/lint.mjs +34 -10
- package/dist/oxlint-DIV-lLSS.mjs +98 -0
- package/dist/{package-Dtjt_lSa.mjs → package-BRTjkzt5.mjs} +29 -3
- package/dist/proof-stamp-DDDC0J6l.mjs +279 -0
- package/dist/ratchet-BAcLRYuM.mjs +448 -0
- package/dist/{renames-BGO4dWJ8.mjs → renames-L2owF5GD.mjs} +2 -2
- package/dist/scenes-DZVXkcxS.mjs +104 -0
- package/dist/shared-igPpEDpS.mjs +622 -0
- package/dist/{size-BVgNbLO6.mjs → size-DBatLT-F.mjs} +4 -4
- package/dist/suppression-base-9L8dlMQK.mjs +120 -0
- package/dist/suppression-budget-C0SkPO5R.mjs +535 -0
- package/dist/{suppressions-BJAngUxo.mjs → suppressions-DM60NkvL.mjs} +180 -18
- package/dist/templates-CypDm-j9.mjs +121 -0
- package/dist/typescript-CM0LrVP7.mjs +222 -0
- package/dist/verify/index.d.mts +6 -1
- package/dist/verify/index.mjs +1 -1
- package/package.json +31 -5
- package/dist/kinds-Bzyyi9yk.mjs +0 -25
- package/dist/ratchet-DRdIYwmv.mjs +0 -80
- package/dist/shared-CsXIMK3I.mjs +0 -34
- package/dist/staged-ratchet-CjoRfZaM.mjs +0 -236
- package/dist/suppression-budget-Yyf5_J5l.mjs +0 -283
- package/dist/typescript-C54ONh9m.mjs +0 -433
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/tooling-configs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"description": "Shared tooling presets for AntelopeJS repositories: oxlint (with the vendored anti-slop rules), oxfmt, ESLint for Nuxt layers, Knip, and an interface range check",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"bin": {
|
|
24
24
|
"antelopejs-api-diff": "./dist/bin/api-diff.mjs",
|
|
25
|
+
"antelopejs-body-check": "./dist/bin/body-check.mjs",
|
|
26
|
+
"antelopejs-capture": "./dist/bin/capture.mjs",
|
|
25
27
|
"antelopejs-check-interface-ranges": "./dist/bin/check-interface-ranges.mjs",
|
|
26
28
|
"antelopejs-check-size": "./dist/bin/check-size.mjs",
|
|
27
29
|
"antelopejs-checks": "./dist/bin/checks.mjs",
|
|
@@ -43,7 +45,9 @@
|
|
|
43
45
|
"./oxc/guardrails": "./dist/oxc/guardrails/index.mjs",
|
|
44
46
|
"./knip": "./dist/knip.mjs",
|
|
45
47
|
"./eslint": "./dist/eslint.mjs",
|
|
46
|
-
"./verify": "./dist/verify/index.mjs"
|
|
48
|
+
"./verify": "./dist/verify/index.mjs",
|
|
49
|
+
"./formal": "./dist/formal/index.mjs",
|
|
50
|
+
"./capture": "./dist/capture/index.mjs"
|
|
47
51
|
},
|
|
48
52
|
"publishConfig": {
|
|
49
53
|
"access": "public",
|
|
@@ -66,7 +70,8 @@
|
|
|
66
70
|
"sync:check": "node src/bin/sync.ts --check",
|
|
67
71
|
"knip": "knip",
|
|
68
72
|
"suppressions": "node src/bin/suppressions.ts",
|
|
69
|
-
"suppressions:update": "node src/bin/suppressions.ts --update"
|
|
73
|
+
"suppressions:update": "node src/bin/suppressions.ts --update",
|
|
74
|
+
"docs:generate": "node src/docs/generate.ts"
|
|
70
75
|
},
|
|
71
76
|
"dependencies": {
|
|
72
77
|
"@oxlint/plugins": "1.81.0",
|
|
@@ -80,19 +85,28 @@
|
|
|
80
85
|
"eslint-plugin-perfectionist": "^5.11.0",
|
|
81
86
|
"knip": "^6.34.0",
|
|
82
87
|
"lefthook": "^2.2.2",
|
|
88
|
+
"mongodb-memory-server": "^11.3.0",
|
|
83
89
|
"oxfmt": "^0.66.0",
|
|
84
90
|
"oxlint": "1.81.0",
|
|
85
91
|
"oxlint-tsgolint": "^7.0.2001",
|
|
92
|
+
"pixelmatch": "^8.0.0",
|
|
93
|
+
"playwright-core": "^1.56.1",
|
|
86
94
|
"release-it": "^19.2.4",
|
|
87
95
|
"release-it-changelogen": "^0.1.0",
|
|
88
|
-
"
|
|
96
|
+
"sharp": "^0.35.5",
|
|
97
|
+
"tsdown": "^0.22.14",
|
|
98
|
+
"vite": "^8.3.4"
|
|
89
99
|
},
|
|
90
100
|
"peerDependencies": {
|
|
91
101
|
"@nuxt/eslint-config": ">=1.2.0",
|
|
92
102
|
"eslint-plugin-perfectionist": ">=5.0.0",
|
|
93
103
|
"knip": ">=6.0.0",
|
|
104
|
+
"mongodb-memory-server": ">=10.0.0",
|
|
94
105
|
"oxfmt": "^0.66.0",
|
|
95
|
-
"oxlint": "1.81.0"
|
|
106
|
+
"oxlint": "1.81.0",
|
|
107
|
+
"pixelmatch": ">=7.0.0",
|
|
108
|
+
"playwright-core": ">=1.56.0",
|
|
109
|
+
"sharp": ">=0.34.0"
|
|
96
110
|
},
|
|
97
111
|
"peerDependenciesMeta": {
|
|
98
112
|
"knip": {
|
|
@@ -109,6 +123,18 @@
|
|
|
109
123
|
},
|
|
110
124
|
"eslint-plugin-perfectionist": {
|
|
111
125
|
"optional": true
|
|
126
|
+
},
|
|
127
|
+
"mongodb-memory-server": {
|
|
128
|
+
"optional": true
|
|
129
|
+
},
|
|
130
|
+
"pixelmatch": {
|
|
131
|
+
"optional": true
|
|
132
|
+
},
|
|
133
|
+
"playwright-core": {
|
|
134
|
+
"optional": true
|
|
135
|
+
},
|
|
136
|
+
"sharp": {
|
|
137
|
+
"optional": true
|
|
112
138
|
}
|
|
113
139
|
},
|
|
114
140
|
"engines": {
|
package/dist/kinds-Bzyyi9yk.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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,80 +0,0 @@
|
|
|
1
|
-
import { a as formatCeilings, n as MAX_FILE_BYTES, o as isRetired, t as CEILINGS_FILE } from "./ceilings-BSw9p4YB.mjs";
|
|
2
|
-
import { t as readCarriedCeilings } from "./renames-BGO4dWJ8.mjs";
|
|
3
|
-
import { n as changedFiles, t as authoredSizes } from "./files-2FikHZ9F.mjs";
|
|
4
|
-
import { r as lintDiagnostics } from "./staged-ratchet-CjoRfZaM.mjs";
|
|
5
|
-
import { n as sizeFailure } from "./size-BVgNbLO6.mjs";
|
|
6
|
-
import { existsSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
//#region src/guardrails/ratchet.ts
|
|
9
|
-
function baseline(root, diagnostics) {
|
|
10
|
-
const rules = {};
|
|
11
|
-
const oversizeFiles = {};
|
|
12
|
-
const sizes = authoredSizes(root);
|
|
13
|
-
for (const diagnostic of diagnostics) if (diagnostic.rule === "eslint/max-lines") {
|
|
14
|
-
const size = sizes.get(diagnostic.file);
|
|
15
|
-
if (size !== void 0) oversizeFiles[diagnostic.file] = size;
|
|
16
|
-
} else rules[diagnostic.rule] = (rules[diagnostic.rule] ?? 0) + 1;
|
|
17
|
-
for (const [file, size] of sizes) if (size > 2e4) oversizeFiles[file] = size;
|
|
18
|
-
return {
|
|
19
|
-
rules,
|
|
20
|
-
oversizeFiles
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function measureBaseline(root, config) {
|
|
24
|
-
return baseline(root, lintDiagnostics(root, config));
|
|
25
|
-
}
|
|
26
|
-
function lowerCeilings(ceilings, current) {
|
|
27
|
-
const lowered = [];
|
|
28
|
-
for (const [rule, limit] of Object.entries(ceilings.rules)) {
|
|
29
|
-
const count = current.rules[rule] ?? 0;
|
|
30
|
-
if (count === 0) delete ceilings.rules[rule];
|
|
31
|
-
else if (count < limit) ceilings.rules[rule] = count;
|
|
32
|
-
if (count < limit) lowered.push(`${rule}: ${limit} -> ${count}`);
|
|
33
|
-
}
|
|
34
|
-
for (const [file, limit] of Object.entries(ceilings.oversizeFiles)) if (current.oversizeFiles[file] === void 0) {
|
|
35
|
-
delete ceilings.oversizeFiles[file];
|
|
36
|
-
lowered.push(`${file}: removed oversize allowance`);
|
|
37
|
-
} else if (current.oversizeFiles[file] < limit) {
|
|
38
|
-
ceilings.oversizeFiles[file] = current.oversizeFiles[file];
|
|
39
|
-
lowered.push(`${file}: ${limit} -> ${current.oversizeFiles[file]} bytes`);
|
|
40
|
-
}
|
|
41
|
-
return lowered;
|
|
42
|
-
}
|
|
43
|
-
function ratchet(root, update = false, base = "HEAD") {
|
|
44
|
-
if (!existsSync(join(root, "guardrails.ratchet.json"))) throw new Error(`${CEILINGS_FILE} is missing. Run antelopejs-sync first.`);
|
|
45
|
-
const ceilings = readCarriedCeilings(root, false, [base]);
|
|
46
|
-
const diagnostics = lintDiagnostics(root);
|
|
47
|
-
const current = baseline(root, diagnostics);
|
|
48
|
-
const changed = changedFiles(root);
|
|
49
|
-
const failures = [];
|
|
50
|
-
for (const [rule, count] of Object.entries(current.rules)) {
|
|
51
|
-
const limit = ceilings.rules[rule] ?? 0;
|
|
52
|
-
if (count <= limit) continue;
|
|
53
|
-
failures.push(`${rule}: ${count} diagnostics exceeds ceiling ${limit}.`);
|
|
54
|
-
const matches = diagnostics.filter((diagnostic) => diagnostic.rule === rule);
|
|
55
|
-
const inChanged = matches.filter(({ file }) => changed.has(file));
|
|
56
|
-
const shown = inChanged.length > 0 ? inChanged : matches;
|
|
57
|
-
for (const diagnostic of shown) failures.push(` ${diagnostic.location}: ${diagnostic.message}`);
|
|
58
|
-
if (shown.length < matches.length) failures.push(` ...and ${matches.length - shown.length} recorded in files this change does not touch.`);
|
|
59
|
-
}
|
|
60
|
-
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.`);
|
|
61
|
-
const sizes = authoredSizes(root, Object.keys(ceilings.oversizeFiles));
|
|
62
|
-
for (const [file, limit] of Object.entries(ceilings.oversizeFiles)) {
|
|
63
|
-
const size = sizes.get(file);
|
|
64
|
-
if (size !== void 0 && size > limit) failures.push(sizeFailure(file, size, limit));
|
|
65
|
-
}
|
|
66
|
-
const lowered = update ? lowerCeilings(ceilings, current) : [];
|
|
67
|
-
const retired = update && isRetired(ceilings);
|
|
68
|
-
if (update) {
|
|
69
|
-
const path = join(root, CEILINGS_FILE);
|
|
70
|
-
if (retired) unlinkSync(path);
|
|
71
|
-
else writeFileSync(path, formatCeilings(ceilings));
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
failures,
|
|
75
|
-
lowered,
|
|
76
|
-
retired
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
export { ratchet as n, measureBaseline as t };
|
package/dist/shared-CsXIMK3I.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
//#region src/oxc/shared.ts
|
|
2
|
-
/**
|
|
3
|
-
* Paths every AntelopeJS project generates or vendors, and that no linter should read.
|
|
4
|
-
* `.github/ISSUE_TEMPLATE/**` holds GitHub's legacy issue templates: Markdown with
|
|
5
|
-
* YAML frontmatter saved under a .yml extension, which a YAML formatter cannot parse.
|
|
6
|
-
* `build/**` and `output/**` match only at the repository root: a directory with
|
|
7
|
-
* either name under `src/` or another authored root is source, not build output.
|
|
8
|
-
*/
|
|
9
|
-
const IGNORE_PATTERNS = [
|
|
10
|
-
"**/node_modules/**",
|
|
11
|
-
"**/dist/**",
|
|
12
|
-
"**/coverage/**",
|
|
13
|
-
"**/.antelope/**",
|
|
14
|
-
"**/.nuxt/**",
|
|
15
|
-
"**/.output/**",
|
|
16
|
-
"build/**",
|
|
17
|
-
"output/**",
|
|
18
|
-
"**/i18n-registry.generated.ts",
|
|
19
|
-
".github/ISSUE_TEMPLATE/**"
|
|
20
|
-
];
|
|
21
|
-
/** Agent tooling directories: assets we install, not source we own. */
|
|
22
|
-
const AGENT_IGNORE_PATTERNS = [
|
|
23
|
-
".agent/**",
|
|
24
|
-
".agents/**",
|
|
25
|
-
".amp/**",
|
|
26
|
-
".claude/**",
|
|
27
|
-
".codex/**",
|
|
28
|
-
".cursor/**",
|
|
29
|
-
".gemini/**",
|
|
30
|
-
".opencode/**",
|
|
31
|
-
".windsurf/**"
|
|
32
|
-
];
|
|
33
|
-
//#endregion
|
|
34
|
-
export { IGNORE_PATTERNS as n, AGENT_IGNORE_PATTERNS as t };
|
|
@@ -1,236 +0,0 @@
|
|
|
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 };
|