@antelopejs/tooling-configs 0.2.6 → 0.2.8
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 +64 -38
- package/dist/bin/api-diff.mjs +15 -9
- package/dist/bin/check-size.mjs +6 -30
- package/dist/bin/checks.mjs +3 -2
- package/dist/bin/comment-proof.mjs +2 -2
- package/dist/bin/ratchet.mjs +4 -43
- package/dist/bin/suppressions.d.mts +1 -0
- package/dist/bin/suppressions.mjs +106 -0
- package/dist/bin/sync.mjs +37 -8
- package/dist/files-BMxKg5IR.mjs +192 -0
- package/dist/oxc/anti-slop/index.mjs +3 -83
- package/dist/oxc/lint.d.mts +6 -0
- package/dist/oxc/lint.mjs +8 -2
- package/dist/{package-Ckd7e4tA.mjs → package-Dtjt_lSa.mjs} +3 -0
- package/dist/{ratchet-EwpOUzaZ.mjs → ratchet-zzo2tT74.mjs} +7 -105
- package/dist/require-safety-comment-for-type-assertion-BBQ669kj.mjs +83 -0
- package/dist/{size-tl9vdWs0.mjs → size-Fp3aWSkN.mjs} +1 -1
- package/dist/staged-ratchet-CJHjp2kx.mjs +119 -0
- package/dist/suppression-budget-Cu0wOmFO.mjs +282 -0
- package/dist/suppressions-C3AE6_I-.mjs +270 -0
- package/dist/typescript-YufoJnck.mjs +433 -0
- package/package.json +7 -4
- package/dist/files-BOpSsyuD.mjs +0 -376
- package/dist/typescript-C8XKk2Ml.mjs +0 -169
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import "./ceilings-BSw9p4YB.mjs";
|
|
2
|
+
import { n as IGNORE_PATTERNS, t as AGENT_IGNORE_PATTERNS } from "./shared-CsXIMK3I.mjs";
|
|
3
|
+
import { closeSync, existsSync, lstatSync, openSync, readSync } from "node:fs";
|
|
4
|
+
import { dirname, join, matchesGlob, relative, resolve } from "node:path";
|
|
5
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
6
|
+
//#region src/guardrails/cli.ts
|
|
7
|
+
function runCli(main) {
|
|
8
|
+
try {
|
|
9
|
+
process.exitCode = main();
|
|
10
|
+
} catch (error) {
|
|
11
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/guardrails/files.ts
|
|
17
|
+
const SIZE_EXCLUSIONS = [
|
|
18
|
+
{
|
|
19
|
+
kind: "generated",
|
|
20
|
+
patterns: [
|
|
21
|
+
...IGNORE_PATTERNS,
|
|
22
|
+
...AGENT_IGNORE_PATTERNS,
|
|
23
|
+
"**/*.generated.*",
|
|
24
|
+
"**/generated/**",
|
|
25
|
+
"**/__snapshots__/**"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
kind: "fixtures",
|
|
30
|
+
patterns: ["**/fixtures/**", "**/__fixtures__/**"]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
kind: "data",
|
|
34
|
+
patterns: ["**/*.{json,jsonc,json5}"]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
kind: "lockfiles",
|
|
38
|
+
patterns: [
|
|
39
|
+
"**/{pnpm-lock.yaml,package-lock.json,npm-shrinkwrap.json,yarn.lock,bun.lock,bun.lockb,Cargo.lock,poetry.lock,uv.lock,Gemfile.lock,composer.lock,go.sum}",
|
|
40
|
+
"**/*.lock",
|
|
41
|
+
"**/*.lockb"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
kind: "documentation",
|
|
46
|
+
patterns: ["**/CHANGELOG.md", "**/*.{md,mdx,markdown,MD}"]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
kind: "assets",
|
|
50
|
+
patterns: ["**/*.{png,jpg,jpeg,gif,webp,avif,ico,svg,bmp,tiff,pdf,mp3,wav,ogg,flac,mp4,webm,mov,avi,woff,woff2,ttf,otf,eot,zip,gz,tgz,bz2,xz,7z,tar,rar,wasm,bin,exe,dll,so,dylib,db,sqlite,sqlite3,icns}"]
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
function trackedManifests(root) {
|
|
54
|
+
return execFileSync("git", ["ls-files", "-z"], {
|
|
55
|
+
cwd: root,
|
|
56
|
+
encoding: "utf8"
|
|
57
|
+
}).split("\0").filter((file) => file === "package.json" || file.endsWith("/package.json"));
|
|
58
|
+
}
|
|
59
|
+
function gitFiles(root) {
|
|
60
|
+
return [...new Set(execFileSync("git", [
|
|
61
|
+
"ls-files",
|
|
62
|
+
"--cached",
|
|
63
|
+
"--others",
|
|
64
|
+
"--exclude-standard",
|
|
65
|
+
"-z"
|
|
66
|
+
], {
|
|
67
|
+
cwd: root,
|
|
68
|
+
encoding: "utf8"
|
|
69
|
+
}).split("\0").filter(Boolean))];
|
|
70
|
+
}
|
|
71
|
+
/** Files that differ from HEAD in the working tree, untracked ones included; every file before the first commit. */
|
|
72
|
+
function changedFiles(root) {
|
|
73
|
+
if (spawnSync("git", [
|
|
74
|
+
"rev-parse",
|
|
75
|
+
"--verify",
|
|
76
|
+
"HEAD"
|
|
77
|
+
], {
|
|
78
|
+
cwd: root,
|
|
79
|
+
stdio: "ignore"
|
|
80
|
+
}).status !== 0) return new Set(gitFiles(root));
|
|
81
|
+
const tracked = execFileSync("git", [
|
|
82
|
+
"diff",
|
|
83
|
+
"HEAD",
|
|
84
|
+
"--name-only",
|
|
85
|
+
"-z"
|
|
86
|
+
], {
|
|
87
|
+
cwd: root,
|
|
88
|
+
encoding: "utf8"
|
|
89
|
+
});
|
|
90
|
+
const untracked = execFileSync("git", [
|
|
91
|
+
"ls-files",
|
|
92
|
+
"--others",
|
|
93
|
+
"--exclude-standard",
|
|
94
|
+
"-z"
|
|
95
|
+
], {
|
|
96
|
+
cwd: root,
|
|
97
|
+
encoding: "utf8"
|
|
98
|
+
});
|
|
99
|
+
return new Set(`${tracked}${untracked}`.split("\0").filter(Boolean));
|
|
100
|
+
}
|
|
101
|
+
function repositoryRoot(cwd = process.cwd()) {
|
|
102
|
+
return execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
103
|
+
cwd,
|
|
104
|
+
encoding: "utf8"
|
|
105
|
+
}).trim();
|
|
106
|
+
}
|
|
107
|
+
/** Resolves a user-supplied revision to a commit id, so it can never read as an option. */
|
|
108
|
+
function resolveRevision(root, revision) {
|
|
109
|
+
return execFileSync("git", [
|
|
110
|
+
"rev-parse",
|
|
111
|
+
"--verify",
|
|
112
|
+
"--end-of-options",
|
|
113
|
+
`${revision}^{commit}`
|
|
114
|
+
], {
|
|
115
|
+
cwd: root,
|
|
116
|
+
encoding: "utf8",
|
|
117
|
+
stdio: [
|
|
118
|
+
"ignore",
|
|
119
|
+
"pipe",
|
|
120
|
+
"pipe"
|
|
121
|
+
]
|
|
122
|
+
}).trim();
|
|
123
|
+
}
|
|
124
|
+
function repositoryPath(root, file) {
|
|
125
|
+
return relative(root, resolve(root, file)).split("\\").join("/");
|
|
126
|
+
}
|
|
127
|
+
function fileBytes(root, file, staged = false) {
|
|
128
|
+
if (staged) {
|
|
129
|
+
const result = spawnSync("git", [
|
|
130
|
+
"cat-file",
|
|
131
|
+
"-s",
|
|
132
|
+
`:${file}`
|
|
133
|
+
], {
|
|
134
|
+
cwd: root,
|
|
135
|
+
encoding: "utf8"
|
|
136
|
+
});
|
|
137
|
+
if (result.error) throw result.error;
|
|
138
|
+
return result.status === 0 ? Number(result.stdout.trim()) : void 0;
|
|
139
|
+
}
|
|
140
|
+
const path = join(root, file);
|
|
141
|
+
if (!existsSync(path)) return void 0;
|
|
142
|
+
const stat = lstatSync(path);
|
|
143
|
+
return stat.isFile() ? stat.size : void 0;
|
|
144
|
+
}
|
|
145
|
+
/** A package root is the directory of a tracked manifest outside every `src` directory; its top-level `build` and `output` are generated output. */
|
|
146
|
+
function packageOutputPatterns(root) {
|
|
147
|
+
return trackedManifests(root).flatMap((manifest) => {
|
|
148
|
+
const directory = dirname(manifest);
|
|
149
|
+
if (directory === "." || directory.split("/").includes("src")) return [];
|
|
150
|
+
return [`${directory}/build/**`, `${directory}/output/**`];
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** `path.matchesGlob` never lets `*` or `**` cross a segment starting with a dot, so each path is also tried with those dots removed. */
|
|
154
|
+
function isExcluded(file, packageOutputs, exclusions = SIZE_EXCLUSIONS) {
|
|
155
|
+
const undotted = file.replace(/(^|\/)\./gu, "$1");
|
|
156
|
+
const matches = (pattern) => matchesGlob(file, pattern) || matchesGlob(undotted, pattern);
|
|
157
|
+
return exclusions.some(({ patterns }) => patterns.some(matches)) || packageOutputs.some(matches);
|
|
158
|
+
}
|
|
159
|
+
function isBinary(root, file, staged) {
|
|
160
|
+
if (staged) return execFileSync("git", ["show", `:${file}`], {
|
|
161
|
+
cwd: root,
|
|
162
|
+
maxBuffer: fileBytes(root, file, true)
|
|
163
|
+
}).subarray(0, 8e3).includes(0);
|
|
164
|
+
const descriptor = openSync(join(root, file), "r");
|
|
165
|
+
try {
|
|
166
|
+
const prefix = Buffer.alloc(8e3);
|
|
167
|
+
const length = readSync(descriptor, prefix, 0, prefix.length, 0);
|
|
168
|
+
return prefix.subarray(0, length).includes(0);
|
|
169
|
+
} finally {
|
|
170
|
+
closeSync(descriptor);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** Whether a repository path is generated output the size guard skips: `dist`, `.nuxt`, agent tooling, `*.generated.*`, snapshots, and package-root `build` or `output`. */
|
|
174
|
+
function generatedOutput(root) {
|
|
175
|
+
const packageOutputs = packageOutputPatterns(root);
|
|
176
|
+
const generated = SIZE_EXCLUSIONS.filter(({ kind }) => kind === "generated");
|
|
177
|
+
return (file) => isExcluded(file, packageOutputs, generated);
|
|
178
|
+
}
|
|
179
|
+
function authoredSizes(root, files = gitFiles(root), staged = false) {
|
|
180
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
181
|
+
const packageOutputs = packageOutputPatterns(root);
|
|
182
|
+
for (const input of files) {
|
|
183
|
+
const file = repositoryPath(root, input);
|
|
184
|
+
if (isExcluded(file, packageOutputs)) continue;
|
|
185
|
+
const size = fileBytes(root, file, staged);
|
|
186
|
+
if (size !== void 0 && size > 2e4 && isBinary(root, file, staged)) continue;
|
|
187
|
+
if (size !== void 0) sizes.set(file, size);
|
|
188
|
+
}
|
|
189
|
+
return sizes;
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
export { repositoryPath as a, trackedManifests as c, gitFiles as i, runCli as l, changedFiles as n, repositoryRoot as o, generatedOutput as r, resolveRevision as s, authoredSizes as t };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { r as requireSafetyCommentForTypeAssertionRule } from "../../require-safety-comment-for-type-assertion-BBQ669kj.mjs";
|
|
1
2
|
import { defineRule, eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
3
|
//#region src/oxc/anti-slop/rules/no-chained-type-assertions.ts
|
|
3
4
|
function isTypeAssertionExpression(node) {
|
|
@@ -8,7 +9,7 @@ function unwrapParenthesizedExpression(expression) {
|
|
|
8
9
|
while (current.type === "ParenthesizedExpression") current = current.expression;
|
|
9
10
|
return current;
|
|
10
11
|
}
|
|
11
|
-
function isConstAssertion
|
|
12
|
+
function isConstAssertion(node) {
|
|
12
13
|
const { typeAnnotation } = node;
|
|
13
14
|
return typeAnnotation.type === "TSTypeReference" && typeAnnotation.typeName.type === "Identifier" && typeAnnotation.typeName.name === "const";
|
|
14
15
|
}
|
|
@@ -27,7 +28,7 @@ function isForbiddenAssertionChain(node) {
|
|
|
27
28
|
let current = node;
|
|
28
29
|
while (isTypeAssertionExpression(current)) {
|
|
29
30
|
assertionCount += 1;
|
|
30
|
-
hasNonConstAssertion ||= !isConstAssertion
|
|
31
|
+
hasNonConstAssertion ||= !isConstAssertion(current);
|
|
31
32
|
current = unwrapParenthesizedExpression(current.expression);
|
|
32
33
|
}
|
|
33
34
|
return assertionCount > 1 && hasNonConstAssertion;
|
|
@@ -1417,87 +1418,6 @@ const noWidenThenAssertRule = defineRule({
|
|
|
1417
1418
|
}
|
|
1418
1419
|
});
|
|
1419
1420
|
//#endregion
|
|
1420
|
-
//#region src/oxc/anti-slop/rules/require-safety-comment-for-type-assertion.ts
|
|
1421
|
-
const DEFAULT_SAFETY_MARKERS = ["SAFETY"];
|
|
1422
|
-
const commentOwnerKinds = /* @__PURE__ */ new Set([
|
|
1423
|
-
"ExpressionStatement",
|
|
1424
|
-
"PropertyDefinition",
|
|
1425
|
-
"ReturnStatement",
|
|
1426
|
-
"ThrowStatement",
|
|
1427
|
-
"VariableDeclaration"
|
|
1428
|
-
]);
|
|
1429
|
-
function isConstAssertion(node) {
|
|
1430
|
-
return node.typeAnnotation.type === "TSTypeReference" && node.typeAnnotation.typeName.type === "Identifier" && node.typeAnnotation.typeName.name === "const";
|
|
1431
|
-
}
|
|
1432
|
-
function configuredSafetyMarkers(option) {
|
|
1433
|
-
if (typeof option !== "object" || option === null || !("markers" in option)) return DEFAULT_SAFETY_MARKERS;
|
|
1434
|
-
const configured = option.markers;
|
|
1435
|
-
if (!Array.isArray(configured)) return DEFAULT_SAFETY_MARKERS;
|
|
1436
|
-
const markers = configured.flatMap((marker) => typeof marker === "string" && marker.trim().length > 0 ? [marker.trim()] : []);
|
|
1437
|
-
return markers.length > 0 ? markers : DEFAULT_SAFETY_MARKERS;
|
|
1438
|
-
}
|
|
1439
|
-
function markerPattern(markers) {
|
|
1440
|
-
const alternation = markers.map((marker) => marker.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`)).join("|");
|
|
1441
|
-
return new RegExp(String.raw`(?:^|[^\p{L}\p{N}_])(?:${alternation})\s*:\s*\S`, "u");
|
|
1442
|
-
}
|
|
1443
|
-
function hasSafetyJustificationBefore(sourceCode, owner, assertion, pattern) {
|
|
1444
|
-
return sourceCode.getCommentsBefore(owner).some((comment) => comment.end <= assertion.start && pattern.test(comment.value));
|
|
1445
|
-
}
|
|
1446
|
-
function hasSafetyComment(sourceCode, node, pattern) {
|
|
1447
|
-
let current = node;
|
|
1448
|
-
while (true) {
|
|
1449
|
-
if (hasSafetyJustificationBefore(sourceCode, current, node, pattern)) return true;
|
|
1450
|
-
if (commentOwnerKinds.has(current.type)) {
|
|
1451
|
-
const exportDeclaration = current.parent;
|
|
1452
|
-
return exportDeclaration.type === "ExportNamedDeclaration" && exportDeclaration.declaration === current && hasSafetyJustificationBefore(sourceCode, exportDeclaration, node, pattern);
|
|
1453
|
-
}
|
|
1454
|
-
if (current.parent.type === "Program") return false;
|
|
1455
|
-
current = current.parent;
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
/** Require every non-const type assertion to state the invariant TypeScript cannot express. */
|
|
1459
|
-
const requireSafetyCommentForTypeAssertionRule = defineRule({
|
|
1460
|
-
meta: {
|
|
1461
|
-
type: "problem",
|
|
1462
|
-
docs: { description: "Require a nearby SAFETY comment for every TypeScript type assertion except const assertions." },
|
|
1463
|
-
messages: { missingSafetyComment: "This type assertion has no `{{marker}}:` justification. State the checked invariant immediately before the assertion or its containing statement." },
|
|
1464
|
-
schema: [{
|
|
1465
|
-
type: "object",
|
|
1466
|
-
properties: { markers: {
|
|
1467
|
-
type: "array",
|
|
1468
|
-
items: {
|
|
1469
|
-
type: "string",
|
|
1470
|
-
minLength: 1
|
|
1471
|
-
},
|
|
1472
|
-
minItems: 1,
|
|
1473
|
-
uniqueItems: true
|
|
1474
|
-
} },
|
|
1475
|
-
additionalProperties: false
|
|
1476
|
-
}],
|
|
1477
|
-
defaultOptions: [{ markers: ["SAFETY"] }]
|
|
1478
|
-
},
|
|
1479
|
-
createOnce(context) {
|
|
1480
|
-
const patterns = /* @__PURE__ */ new Map();
|
|
1481
|
-
const checkAssertion = (node) => {
|
|
1482
|
-
if (isConstAssertion(node)) return;
|
|
1483
|
-
const markers = configuredSafetyMarkers(context.options?.[0]);
|
|
1484
|
-
const patternKey = markers.join("\0");
|
|
1485
|
-
const pattern = patterns.get(patternKey) ?? markerPattern(markers);
|
|
1486
|
-
patterns.set(patternKey, pattern);
|
|
1487
|
-
if (hasSafetyComment(context.sourceCode, node, pattern)) return;
|
|
1488
|
-
context.report({
|
|
1489
|
-
node,
|
|
1490
|
-
messageId: "missingSafetyComment",
|
|
1491
|
-
data: { marker: markers[0] ?? DEFAULT_SAFETY_MARKERS[0] }
|
|
1492
|
-
});
|
|
1493
|
-
};
|
|
1494
|
-
return {
|
|
1495
|
-
TSAsExpression: checkAssertion,
|
|
1496
|
-
TSTypeAssertion: checkAssertion
|
|
1497
|
-
};
|
|
1498
|
-
}
|
|
1499
|
-
});
|
|
1500
|
-
//#endregion
|
|
1501
1421
|
//#region src/oxc/anti-slop/index.ts
|
|
1502
1422
|
/** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
|
|
1503
1423
|
const antiSlopPlugin = eslintCompatPlugin({
|
package/dist/oxc/lint.d.mts
CHANGED
|
@@ -109,6 +109,12 @@ declare function antelopePreset(options?: AntelopePresetOptions): {
|
|
|
109
109
|
"import/no-cycle": "off" | "error";
|
|
110
110
|
"import/no-self-import": "error";
|
|
111
111
|
"import/no-duplicates": "error";
|
|
112
|
+
"typescript/ban-ts-comment": ["error", {
|
|
113
|
+
"ts-check": false;
|
|
114
|
+
"ts-expect-error": false;
|
|
115
|
+
"ts-ignore": true;
|
|
116
|
+
"ts-nocheck": false;
|
|
117
|
+
}];
|
|
112
118
|
};
|
|
113
119
|
} | {
|
|
114
120
|
rules: {
|
package/dist/oxc/lint.mjs
CHANGED
|
@@ -34,7 +34,7 @@ const ANTI_SLOP_RULES = [
|
|
|
34
34
|
"no-widen-then-assert",
|
|
35
35
|
"require-safety-comment-for-type-assertion"
|
|
36
36
|
];
|
|
37
|
-
/** Correctness must fail CI; underscore bindings and omitted rest siblings are intentional. */
|
|
37
|
+
/** Correctness must fail CI; underscore bindings and omitted rest siblings are intentional; `@ts-ignore` is banned because `@ts-expect-error` fails once the error is gone. */
|
|
38
38
|
function basePreset(importCycles) {
|
|
39
39
|
return defineConfig({
|
|
40
40
|
categories: { correctness: "error" },
|
|
@@ -63,7 +63,13 @@ function basePreset(importCycles) {
|
|
|
63
63
|
"eslint/prefer-regex-literals": "error",
|
|
64
64
|
"import/no-cycle": importCycles ? "error" : "off",
|
|
65
65
|
"import/no-self-import": "error",
|
|
66
|
-
"import/no-duplicates": "error"
|
|
66
|
+
"import/no-duplicates": "error",
|
|
67
|
+
"typescript/ban-ts-comment": ["error", {
|
|
68
|
+
"ts-check": false,
|
|
69
|
+
"ts-expect-error": false,
|
|
70
|
+
"ts-ignore": true,
|
|
71
|
+
"ts-nocheck": false
|
|
72
|
+
}]
|
|
67
73
|
}
|
|
68
74
|
});
|
|
69
75
|
}
|
|
@@ -52,6 +52,7 @@ function repositoryTools(manifest) {
|
|
|
52
52
|
checks: "antelopejs-checks",
|
|
53
53
|
size: "antelopejs-check-size",
|
|
54
54
|
ratchet: "antelopejs-ratchet",
|
|
55
|
+
suppressions: "antelopejs-suppressions",
|
|
55
56
|
sync: "antelopejs-sync"
|
|
56
57
|
},
|
|
57
58
|
presets: {
|
|
@@ -66,6 +67,7 @@ function repositoryTools(manifest) {
|
|
|
66
67
|
checks: "node src/bin/checks.ts",
|
|
67
68
|
size: "node src/bin/check-size.ts",
|
|
68
69
|
ratchet: "node src/bin/ratchet.ts",
|
|
70
|
+
suppressions: "node src/bin/suppressions.ts",
|
|
69
71
|
sync: "node src/bin/sync.ts"
|
|
70
72
|
},
|
|
71
73
|
presets: {
|
|
@@ -99,6 +101,7 @@ function managedPackage(current, versions, options = {}) {
|
|
|
99
101
|
const tools = repositoryTools(manifest);
|
|
100
102
|
Object.assign(scripts, tools.commands, {
|
|
101
103
|
"ratchet:update": `${tools.commands.ratchet} --update`,
|
|
104
|
+
"suppressions:update": `${tools.commands.suppressions} --update`,
|
|
102
105
|
"sync:check": `${tools.commands.sync} --check`
|
|
103
106
|
});
|
|
104
107
|
if (options.ratchet === false) {
|
|
@@ -1,79 +1,10 @@
|
|
|
1
|
-
import { a as formatCeilings, n as MAX_FILE_BYTES, o as isRetired,
|
|
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
|
-
import { n as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { existsSync,
|
|
7
|
-
import {
|
|
8
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
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
|
|
3
|
+
import { n as changedFiles, t as authoredSizes } from "./files-BMxKg5IR.mjs";
|
|
4
|
+
import { r as lintDiagnostics } from "./staged-ratchet-CJHjp2kx.mjs";
|
|
5
|
+
import { n as sizeFailure } from "./size-Fp3aWSkN.mjs";
|
|
6
|
+
import { existsSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
77
8
|
//#region src/guardrails/ratchet.ts
|
|
78
9
|
function baseline(root, diagnostics) {
|
|
79
10
|
const rules = {};
|
|
@@ -92,35 +23,6 @@ function baseline(root, diagnostics) {
|
|
|
92
23
|
function measureBaseline(root, config) {
|
|
93
24
|
return baseline(root, lintDiagnostics(root, config));
|
|
94
25
|
}
|
|
95
|
-
function changedFiles(root) {
|
|
96
|
-
if (spawnSync("git", [
|
|
97
|
-
"rev-parse",
|
|
98
|
-
"--verify",
|
|
99
|
-
"HEAD"
|
|
100
|
-
], {
|
|
101
|
-
cwd: root,
|
|
102
|
-
stdio: "ignore"
|
|
103
|
-
}).status !== 0) return new Set(gitFiles(root));
|
|
104
|
-
const tracked = execFileSync("git", [
|
|
105
|
-
"diff",
|
|
106
|
-
"HEAD",
|
|
107
|
-
"--name-only",
|
|
108
|
-
"-z"
|
|
109
|
-
], {
|
|
110
|
-
cwd: root,
|
|
111
|
-
encoding: "utf8"
|
|
112
|
-
});
|
|
113
|
-
const untracked = execFileSync("git", [
|
|
114
|
-
"ls-files",
|
|
115
|
-
"--others",
|
|
116
|
-
"--exclude-standard",
|
|
117
|
-
"-z"
|
|
118
|
-
], {
|
|
119
|
-
cwd: root,
|
|
120
|
-
encoding: "utf8"
|
|
121
|
-
});
|
|
122
|
-
return new Set(`${tracked}${untracked}`.split("\0").filter(Boolean));
|
|
123
|
-
}
|
|
124
26
|
function lowerCeilings(ceilings, current) {
|
|
125
27
|
const lowered = [];
|
|
126
28
|
for (const [rule, limit] of Object.entries(ceilings.rules)) {
|
|
@@ -175,4 +77,4 @@ function ratchet(root, update = false, base = "HEAD") {
|
|
|
175
77
|
};
|
|
176
78
|
}
|
|
177
79
|
//#endregion
|
|
178
|
-
export { ratchet as n,
|
|
80
|
+
export { ratchet as n, measureBaseline as t };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
//#region src/oxc/anti-slop/rules/require-safety-comment-for-type-assertion.ts
|
|
3
|
+
const DEFAULT_SAFETY_MARKERS = ["SAFETY"];
|
|
4
|
+
const commentOwnerKinds = /* @__PURE__ */ new Set([
|
|
5
|
+
"ExpressionStatement",
|
|
6
|
+
"PropertyDefinition",
|
|
7
|
+
"ReturnStatement",
|
|
8
|
+
"ThrowStatement",
|
|
9
|
+
"VariableDeclaration"
|
|
10
|
+
]);
|
|
11
|
+
function isConstAssertion(node) {
|
|
12
|
+
return node.typeAnnotation.type === "TSTypeReference" && node.typeAnnotation.typeName.type === "Identifier" && node.typeAnnotation.typeName.name === "const";
|
|
13
|
+
}
|
|
14
|
+
function configuredSafetyMarkers(option) {
|
|
15
|
+
if (typeof option !== "object" || option === null || !("markers" in option)) return DEFAULT_SAFETY_MARKERS;
|
|
16
|
+
const configured = option.markers;
|
|
17
|
+
if (!Array.isArray(configured)) return DEFAULT_SAFETY_MARKERS;
|
|
18
|
+
const markers = configured.flatMap((marker) => typeof marker === "string" && marker.trim().length > 0 ? [marker.trim()] : []);
|
|
19
|
+
return markers.length > 0 ? markers : DEFAULT_SAFETY_MARKERS;
|
|
20
|
+
}
|
|
21
|
+
function markerPattern(markers) {
|
|
22
|
+
const alternation = markers.map((marker) => marker.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`)).join("|");
|
|
23
|
+
return new RegExp(String.raw`(?:^|[^\p{L}\p{N}_])(?:${alternation})\s*:\s*\S`, "u");
|
|
24
|
+
}
|
|
25
|
+
function hasSafetyJustificationBefore(sourceCode, owner, assertion, pattern) {
|
|
26
|
+
return sourceCode.getCommentsBefore(owner).some((comment) => comment.end <= assertion.start && pattern.test(comment.value));
|
|
27
|
+
}
|
|
28
|
+
function hasSafetyComment(sourceCode, node, pattern) {
|
|
29
|
+
let current = node;
|
|
30
|
+
while (true) {
|
|
31
|
+
if (hasSafetyJustificationBefore(sourceCode, current, node, pattern)) return true;
|
|
32
|
+
if (commentOwnerKinds.has(current.type)) {
|
|
33
|
+
const exportDeclaration = current.parent;
|
|
34
|
+
return exportDeclaration.type === "ExportNamedDeclaration" && exportDeclaration.declaration === current && hasSafetyJustificationBefore(sourceCode, exportDeclaration, node, pattern);
|
|
35
|
+
}
|
|
36
|
+
if (current.parent.type === "Program") return false;
|
|
37
|
+
current = current.parent;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Require every non-const type assertion to state the invariant TypeScript cannot express. */
|
|
41
|
+
const requireSafetyCommentForTypeAssertionRule = defineRule({
|
|
42
|
+
meta: {
|
|
43
|
+
type: "problem",
|
|
44
|
+
docs: { description: "Require a nearby SAFETY comment for every TypeScript type assertion except const assertions." },
|
|
45
|
+
messages: { missingSafetyComment: "This type assertion has no `{{marker}}:` justification. State the checked invariant immediately before the assertion or its containing statement." },
|
|
46
|
+
schema: [{
|
|
47
|
+
type: "object",
|
|
48
|
+
properties: { markers: {
|
|
49
|
+
type: "array",
|
|
50
|
+
items: {
|
|
51
|
+
type: "string",
|
|
52
|
+
minLength: 1
|
|
53
|
+
},
|
|
54
|
+
minItems: 1,
|
|
55
|
+
uniqueItems: true
|
|
56
|
+
} },
|
|
57
|
+
additionalProperties: false
|
|
58
|
+
}],
|
|
59
|
+
defaultOptions: [{ markers: ["SAFETY"] }]
|
|
60
|
+
},
|
|
61
|
+
createOnce(context) {
|
|
62
|
+
const patterns = /* @__PURE__ */ new Map();
|
|
63
|
+
const checkAssertion = (node) => {
|
|
64
|
+
if (isConstAssertion(node)) return;
|
|
65
|
+
const markers = configuredSafetyMarkers(context.options?.[0]);
|
|
66
|
+
const patternKey = markers.join("\0");
|
|
67
|
+
const pattern = patterns.get(patternKey) ?? markerPattern(markers);
|
|
68
|
+
patterns.set(patternKey, pattern);
|
|
69
|
+
if (hasSafetyComment(context.sourceCode, node, pattern)) return;
|
|
70
|
+
context.report({
|
|
71
|
+
node,
|
|
72
|
+
messageId: "missingSafetyComment",
|
|
73
|
+
data: { marker: markers[0] ?? DEFAULT_SAFETY_MARKERS[0] }
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
TSAsExpression: checkAssertion,
|
|
78
|
+
TSTypeAssertion: checkAssertion
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
//#endregion
|
|
83
|
+
export { markerPattern as n, requireSafetyCommentForTypeAssertionRule as r, DEFAULT_SAFETY_MARKERS as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./ceilings-BSw9p4YB.mjs";
|
|
2
2
|
import { t as readCarriedCeilings } from "./renames-BGO4dWJ8.mjs";
|
|
3
|
-
import { t as authoredSizes } from "./files-
|
|
3
|
+
import { t as authoredSizes } from "./files-BMxKg5IR.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.`;
|