@antelopejs/tooling-configs 0.2.10 → 0.2.11
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 +13 -9
- package/dist/bin/api-diff.mjs +74 -41
- package/dist/bin/ratchet.mjs +2 -2
- package/dist/bin/suppressions.mjs +1 -1
- package/dist/bin/sync.mjs +3 -2
- package/dist/oxc/guardrails/index.mjs +119 -0
- package/dist/oxc/lint.d.mts +4 -0
- package/dist/oxc/lint.mjs +1 -0
- package/dist/{ratchet-B2qYUs51.mjs → ratchet-DRdIYwmv.mjs} +1 -1
- package/dist/staged-ratchet-CjoRfZaM.mjs +236 -0
- package/dist/{suppression-budget-Bq30tJDS.mjs → suppression-budget-Yyf5_J5l.mjs} +2 -1
- package/package.json +1 -1
- package/dist/staged-ratchet-BNfjcbih.mjs +0 -119
package/README.md
CHANGED
|
@@ -98,20 +98,21 @@ export default defineConfig({
|
|
|
98
98
|
| Type-aware | `typescript/no-floating-promises` and eight more type-aware rules | error |
|
|
99
99
|
| Complexity | `max-params` 5, `max-lines-per-function` 120, `max-lines` 500, `max-depth` 4, `complexity` 20 | error |
|
|
100
100
|
| Anti-slop | all 15 vendored rules; `no-runtime-typeof` with `allowInTypeGuards`, so a `typeof` inside a type predicate or assertion function passes | error |
|
|
101
|
-
| Guardrails | `antelopejs/no-comments`; in test files `antelopejs/no-fs-read-in-tests`, `antelopejs/no-constant-value-assertion`, `antelopejs/no-typeof-function-only-test` and `antelopejs/require-assertion`
|
|
101
|
+
| Guardrails | `antelopejs/no-comments`; in test files `antelopejs/no-fs-read-in-tests`, `antelopejs/no-self-import-in-tests`, `antelopejs/no-constant-value-assertion`, `antelopejs/no-typeof-function-only-test` and `antelopejs/require-assertion` | error |
|
|
102
102
|
| Import sorting | `perfectionist/sort-imports`, autofixed by `oxlint --fix` | off |
|
|
103
103
|
|
|
104
104
|
No rule warns. oxlint reports `correctness` as warnings by default, and warnings never fail the command, so the preset raises it to error. A repository with existing findings records them in `guardrails.ratchet.json` instead of lowering a severity (see [Guardrail pack](#guardrail-pack)).
|
|
105
105
|
|
|
106
106
|
The guardrail rules:
|
|
107
107
|
|
|
108
|
-
| Rule | Fails on
|
|
109
|
-
| ----------------------------------------- |
|
|
110
|
-
| `antelopejs/no-comments` | `//` and `/* */` comments. Allowed: TSDoc `/** */`, `SAFETY: <reason>` (one block, or a run of `//` lines), `/*!` license headers, `@ts-expect-error <reason>`, oxlint/eslint directives that name their rules, `/// <reference />`, `#__PURE__`/`@__PURE__`, `@vite-ignore` and webpack magic comments, `prettier-ignore`/`oxfmt-ignore`
|
|
111
|
-
| `antelopejs/no-fs-read-in-tests` | `readFileSync` or `readdirSync` from `fs` in a test file. Files under `fixtures/`, `helpers/` and `locales/` may read
|
|
112
|
-
| `antelopejs/
|
|
113
|
-
| `antelopejs/
|
|
114
|
-
| `antelopejs/no-
|
|
108
|
+
| Rule | Fails on |
|
|
109
|
+
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
110
|
+
| `antelopejs/no-comments` | `//` and `/* */` comments. Allowed: TSDoc `/** */`, `SAFETY: <reason>` (one block, or a run of `//` lines), `/*!` license headers, `@ts-expect-error <reason>`, oxlint/eslint directives that name their rules, `/// <reference />`, `#__PURE__`/`@__PURE__`, `@vite-ignore` and webpack magic comments, `prettier-ignore`/`oxfmt-ignore` |
|
|
111
|
+
| `antelopejs/no-fs-read-in-tests` | `readFileSync` or `readdirSync` from `fs` in a test file. Files under `fixtures/`, `helpers/` and `locales/` may read |
|
|
112
|
+
| `antelopejs/no-self-import-in-tests` | a test file that imports its own package name (`@antelopejs/<self>`, a subpath, `require`, dynamic `import()` or a re-export; `import type` is fine) unless that resolves to local code: the `exports` map publishes the subpath and `node_modules/<name>` is a link back to the package (a workspace self-link such as `link:.`). Otherwise the import resolves to the installed published copy and the test never runs local code. Import the module by relative path instead |
|
|
113
|
+
| `antelopejs/require-assertion` | a test with no assertion. Counts: calls named `expect*` or `assert*`, `sinon.assert.*`, supertest `.expect(...)`, and should-style `x.should…` or `should(x)` |
|
|
114
|
+
| `antelopejs/no-constant-value-assertion` | `expect(X).toBe(literal)` where the root of `X` is an UPPER_SNAKE constant (`MAX_ITEMS`, `NAMES.if`, not `process.env.NODE_ENV`); also `.toEqual`, `.to.equal`, `.to.eq`, `.eql` and synonyms |
|
|
115
|
+
| `antelopejs/no-typeof-function-only-test` | a test whose only assertions are `toBeTypeOf("function")`, `to.be.a("function")` or equivalents |
|
|
115
116
|
|
|
116
117
|
Test files are `*.test.*`, `*.spec.*`, and files under `test/`, `tests/` and `__tests__/`, whatever the framework. The preset keeps four framework-neutral Jest-plugin rules: `no-disabled-tests`, `no-focused-tests`, `valid-describe-callback` and `valid-title`.
|
|
117
118
|
|
|
@@ -187,6 +188,7 @@ pnpm install
|
|
|
187
188
|
|
|
188
189
|
- A rule listed under `rules` is off for `oxlint`, so editors, hooks and `lint` stay green. `antelopejs-ratchet` counts it with every rule on, and fails when a count rises. It prints the findings in the files the change touched.
|
|
189
190
|
- A file listed under `oversizeFiles` may exceed 20,000 bytes and `max-lines`, up to its recorded size. Any other file over either limit fails. When git sees a listed file renamed (`git mv`, or a staged delete and add), the allowance moves to the new path and never exceeds the old one; a copy or a new file inherits nothing. `antelopejs-ratchet --base <ref>` detects renames against that revision instead of `HEAD`, for a rename that was committed before the file was updated.
|
|
191
|
+
- The pre-commit hook runs `antelopejs-ratchet --staged`: for each rule under `rules` it compares the findings in the staged files with those files at HEAD (rename sources and deleted files included, linted under the staged configuration) and fails a rule whose net count rises. Code moved between staged files, or a legacy line that is reformatted or edited, nets out; a new finding does not, even next to a moved block.
|
|
190
192
|
- `antelopejs-ratchet --update` lowers each number to the current count and removes what reached zero. It never raises a number or adds an entry. Commit the lowered file.
|
|
191
193
|
|
|
192
194
|
When every rule count is zero and `oversizeFiles` is empty, the ratchet is retired. `antelopejs-ratchet --update` deletes the file and asks you to run `antelopejs-sync`. Sync then removes `ratchet`, `ratchet:update`, the ratchet hook and the Debt instructions. Commit those changes together. An empty baseline on first adoption creates no file. Later syncs never recreate it because the `sync:check` script marks adoption.
|
|
@@ -213,7 +215,7 @@ When every rule count is zero and `oversizeFiles` is empty, the ratchet is retir
|
|
|
213
215
|
- `antelopejs-suppressions` also compares the budget with the one on the pull request base: `--base <ref>` when given, else the `GITHUB_BASE_REF` branch in CI (fetched from `origin` into a shallow checkout), else `origin/HEAD`. It fails when a ceiling is higher than on the base or a rule the base lists is removed, so a raise merges only through the operator's ruleset bypass. A base without a budget, a first adoption, passes. Without a base the comparison is skipped.
|
|
214
216
|
- The pre-commit hook runs `antelopejs-suppressions --staged`: it compares the suppressions in the staged files with those files at HEAD, following renames and counting deleted files, and fails a kind that rises by more than the staged budget raises its ceiling. A suppression moved between staged files nets out.
|
|
215
217
|
- `@ts-ignore` is also a lint error (`typescript/ban-ts-comment`); `@ts-expect-error` fails once its error is gone.
|
|
216
|
-
- Both modes also judge what the change adds, whatever the budget allows: the full check against the same base (HEAD when there is none), the staged check against HEAD. A suppression counts as added when its kind, rule and reason occur more often than on the base, so one moved to another file with its reason is not added, and one whose reason a comment pass rewrote or stripped is. An added directive fails when it names a rule no directive may name (`anti-slop/require-safety-comment-for-type-assertion`, `antelopejs/no-comments`, the
|
|
218
|
+
- Both modes also judge what the change adds, whatever the budget allows: the full check against the same base (HEAD when there is none), the staged check against HEAD. A suppression counts as added when its kind, rule and reason occur more often than on the base, so one moved to another file with its reason is not added, and one whose reason a comment pass rewrote or stripped is. An added directive fails when it names a rule no directive may name (`anti-slop/require-safety-comment-for-type-assertion`, `antelopejs/no-comments`, the five `antelopejs` test rules, `typescript/ban-ts-comment`); the failure names what to do instead. An added directive naming its rules, `@ts-expect-error` or `SAFETY:` comment fails when its reason has fewer than three words, or only words like "safe", "intentional", "legacy" and the rule's own name. A block `oxlint-disable` or `eslint-disable` that no `-enable` closes before the end of its file fails when the change adds it. Suppressions already on the base stay under the budget until a burn-down removes them.
|
|
217
219
|
|
|
218
220
|
### Size
|
|
219
221
|
|
|
@@ -227,6 +229,8 @@ A behaviour-preserving cleanup PR shows `antelopejs-api-diff <base-ref>` passing
|
|
|
227
229
|
|
|
228
230
|
A comment-only PR shows `antelopejs-comment-proof <base-ref>` passing instead of a verifier. It includes private packages, ignores type diagnostics and compares comment-free JavaScript emit byte for byte. Both commands exclude test sources, fail on added or removed outputs, and print unified diffs for changes.
|
|
229
231
|
|
|
232
|
+
Test-helper entries are outside both halves. A published entry whose built file is test output relative to `outDir` (under `test/`, `tests/` or `__tests__/`, or named `*.test.*` or `*.spec.*`) is neither bundled nor loaded, because helpers such as `./tests/*` import a test runner that the proof does not run. This applies the same way to the declaration and the runtime half, to wildcard and plain targets, and to files a general wildcard such as `./*` matches. Each half prints `API: skipped test-helper entry <target> in <directory>` or `Runtime API: skipped test-helper entry <target> in <directory>`; a package whose only wildcard export is `./tests/*` still has its other entries compared in both halves.
|
|
233
|
+
|
|
230
234
|
Pass `--allow-added <glob>` (repeatable) to `antelopejs-api-diff` when a refactor adds helper files that a wildcard export publishes, such as an `internal/` directory under `"./*"`. An added entry passes, in both the declaration and the runtime half, when its published subpath matches a glob (for example `--allow-added '**/internal/**'`, matched against `base/table-view/internal/helper` for `./base/table-view/internal/helper`) and its source module is marked `@internal`: a leading `/** @internal @packageDocumentation */` comment on the module (`@module` and `@fileoverview` also qualify), or an `@internal` tag on every exported declaration. Allowed entries are printed under `Added (allowed): <count>`; nothing is printed when no entry was added. An added entry that matches but is not marked `@internal` fails with the file and the fix. Added entries matching no glob, removed entries and changed entries still fail, matching or not. Without the flag nothing changes.
|
|
231
235
|
|
|
232
236
|
```bash
|
package/dist/bin/api-diff.mjs
CHANGED
|
@@ -178,6 +178,12 @@ function normalizeBundle(compiler, text) {
|
|
|
178
178
|
}).printFile(normalized);
|
|
179
179
|
}
|
|
180
180
|
//#endregion
|
|
181
|
+
//#region src/guardrails/test-entries.ts
|
|
182
|
+
/** The line a proof half prints for a published test-helper entry it leaves out, so a skip is reported rather than silent. */
|
|
183
|
+
function testEntryNotice(half, directory, target) {
|
|
184
|
+
return `${half}: skipped test-helper entry ${target} in ${directory}; test helpers need a test runner and are outside both proof halves.\n`;
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
181
187
|
//#region src/guardrails/runtime-diff.ts
|
|
182
188
|
const DESCRIBE = `
|
|
183
189
|
const { readFileSync, existsSync } = require("node:fs");
|
|
@@ -242,35 +248,45 @@ function builtEntries(directory, manifest) {
|
|
|
242
248
|
subpath: "main"
|
|
243
249
|
});
|
|
244
250
|
if (!targets.length) throw new Error(`${directory}: no published runtime entry.`);
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
251
|
+
const output = outputRoot(directory);
|
|
252
|
+
const skipped = [];
|
|
253
|
+
return {
|
|
254
|
+
entries: targets.filter(({ target }) => !target.endsWith(".json")).filter(({ target }) => {
|
|
255
|
+
if (!isTestSource(output, resolve(directory, target))) return true;
|
|
256
|
+
skipped.push(target);
|
|
257
|
+
return false;
|
|
258
|
+
}).flatMap(({ entry, target, subpath }) => {
|
|
259
|
+
if (!target.includes("*")) {
|
|
260
|
+
const file = resolve(directory, target);
|
|
261
|
+
if (!existsSync(file)) throw new Error(`${directory}: missing built runtime entry ${target}.`);
|
|
262
|
+
return [{
|
|
263
|
+
entry,
|
|
264
|
+
file,
|
|
265
|
+
subpath
|
|
266
|
+
}];
|
|
267
|
+
}
|
|
268
|
+
const prefix = resolve(directory, target.slice(0, target.indexOf("*")));
|
|
269
|
+
const parent = dirname(prefix);
|
|
270
|
+
const pattern = new RegExp(`^${resolve(directory, target).split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join("(.*)")}$`, "u");
|
|
271
|
+
if (!existsSync(parent)) throw new Error(`${directory}: missing build output for ${target}.`);
|
|
272
|
+
const found = readdirSync(parent, {
|
|
273
|
+
recursive: true,
|
|
274
|
+
withFileTypes: true
|
|
275
|
+
}).filter((file) => file.isFile()).map((file) => join(file.parentPath, file.name)).filter((file) => pattern.test(file));
|
|
276
|
+
if (!found.length) throw new Error(`${directory}: missing built runtime entry ${target}.`);
|
|
277
|
+
const matches = found.filter((file) => !isTestSource(output, file));
|
|
278
|
+
if (matches.length < found.length) skipped.push(target);
|
|
279
|
+
return matches.sort().map((file) => {
|
|
280
|
+
const capture = pattern.exec(file)?.[1] ?? relative(directory, file);
|
|
281
|
+
return {
|
|
282
|
+
entry: entry.replaceAll("*", capture),
|
|
283
|
+
file,
|
|
284
|
+
subpath: fillStars(subpath, [capture])
|
|
285
|
+
};
|
|
286
|
+
});
|
|
287
|
+
}),
|
|
288
|
+
skipped
|
|
289
|
+
};
|
|
274
290
|
}
|
|
275
291
|
function childJson(args, cwd) {
|
|
276
292
|
const result = spawnSync(process.execPath, args, {
|
|
@@ -305,13 +321,14 @@ function buildPackage(directory, output, manifest) {
|
|
|
305
321
|
"pipe"
|
|
306
322
|
]
|
|
307
323
|
});
|
|
308
|
-
let
|
|
324
|
+
let built;
|
|
309
325
|
try {
|
|
310
|
-
|
|
326
|
+
built = builtEntries(directory, manifest);
|
|
311
327
|
} catch (error) {
|
|
312
328
|
if (buildManifest.scripts?.build) throw error;
|
|
313
329
|
return;
|
|
314
330
|
}
|
|
331
|
+
const { entries, skipped } = built;
|
|
315
332
|
for (const { entry, file } of entries) {
|
|
316
333
|
const destination = join(output, `${encodeURIComponent(entry)}.json`);
|
|
317
334
|
const metadata = childJson([
|
|
@@ -324,7 +341,8 @@ function buildPackage(directory, output, manifest) {
|
|
|
324
341
|
}
|
|
325
342
|
return {
|
|
326
343
|
count: entries.length,
|
|
327
|
-
entries
|
|
344
|
+
entries,
|
|
345
|
+
skipped
|
|
328
346
|
};
|
|
329
347
|
}
|
|
330
348
|
/** Builds both committed revisions and compares published runtime metadata and one captured optional probe. */
|
|
@@ -332,6 +350,7 @@ function runtimeDiff(root, baseRef, probe, policy) {
|
|
|
332
350
|
const errors = [];
|
|
333
351
|
const failedPackages = /* @__PURE__ */ new Set();
|
|
334
352
|
const skippedPackages = /* @__PURE__ */ new Set();
|
|
353
|
+
const skippedTests = /* @__PURE__ */ new Set();
|
|
335
354
|
const result = compareRevisions(root, baseRef, "Runtime API", (worktree, output, scratch) => {
|
|
336
355
|
const packages = packagesAt(worktree, true);
|
|
337
356
|
const published = [];
|
|
@@ -343,6 +362,7 @@ function runtimeDiff(root, baseRef, probe, policy) {
|
|
|
343
362
|
if (built === void 0) skippedPackages.add(directory);
|
|
344
363
|
else {
|
|
345
364
|
entries += built.count;
|
|
365
|
+
for (const target of built.skipped) skippedTests.add(testEntryNotice("Runtime API", directory, target));
|
|
346
366
|
published.push(...built.entries.map(({ entry, subpath }) => ({
|
|
347
367
|
path: `${folder}/${encodeURIComponent(entry)}.json`,
|
|
348
368
|
directory,
|
|
@@ -372,7 +392,7 @@ function runtimeDiff(root, baseRef, probe, policy) {
|
|
|
372
392
|
}, policy);
|
|
373
393
|
return {
|
|
374
394
|
different: result.different || errors.length > 0,
|
|
375
|
-
output: (errors.length && !result.different ? result.output.replace(/^Runtime API:[^\n]*\n/u, "Runtime API: comparison incomplete due to execution errors.\n") : result.output) + [...skippedPackages].map((directory) => `Runtime API: skipped ${directory}, which has no build script and no committed runtime entry.\n`).join("") + errors.join("")
|
|
395
|
+
output: (errors.length && !result.different ? result.output.replace(/^Runtime API:[^\n]*\n/u, "Runtime API: comparison incomplete due to execution errors.\n") : result.output) + [...skippedPackages].map((directory) => `Runtime API: skipped ${directory}, which has no build script and no committed runtime entry.\n`).join("") + [...skippedTests].sort().join("") + errors.join("")
|
|
376
396
|
};
|
|
377
397
|
}
|
|
378
398
|
//#endregion
|
|
@@ -435,12 +455,18 @@ function publishedEntries(directory, manifest, emitted, scratch) {
|
|
|
435
455
|
const outputRoot = resolve(directory, emitted.options.outDir ?? ".");
|
|
436
456
|
const files = emitted.files.map((file) => relative(scratch, file).split("\\").join("/"));
|
|
437
457
|
const entries = [];
|
|
458
|
+
const skipped = [];
|
|
438
459
|
for (const { entry, target, subpath } of entryPatterns(manifest)) {
|
|
439
|
-
if (isTestSource(outputRoot, resolve(directory, target)))
|
|
460
|
+
if (isTestSource(outputRoot, resolve(directory, target))) {
|
|
461
|
+
skipped.push(target);
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
440
464
|
const path = relative(outputRoot, resolve(directory, target)).split("\\").join("/");
|
|
441
465
|
const pattern = targetPattern(path);
|
|
442
|
-
const
|
|
443
|
-
if (!
|
|
466
|
+
const found = files.filter((file) => pattern.test(file));
|
|
467
|
+
if (!found.length && !path.includes("*")) throw new Error(`${directory}: published target ${target} has no emitted declaration.`);
|
|
468
|
+
const matches = found.filter((file) => !isTestSource(outputRoot, join(outputRoot, file)));
|
|
469
|
+
if (matches.length < found.length) skipped.push(target);
|
|
444
470
|
for (const file of matches) {
|
|
445
471
|
const captures = pattern.exec(file)?.slice(1) ?? [];
|
|
446
472
|
const name = entry.includes("*") ? fillStars(entry, captures, entrySegment) : `${entry}${captures.length ? `/file/${entrySegment(file)}` : ""}`;
|
|
@@ -451,7 +477,10 @@ function publishedEntries(directory, manifest, emitted, scratch) {
|
|
|
451
477
|
});
|
|
452
478
|
}
|
|
453
479
|
}
|
|
454
|
-
return
|
|
480
|
+
return {
|
|
481
|
+
entries: entries.sort((a, b) => a.entry.localeCompare(b.entry)),
|
|
482
|
+
skipped
|
|
483
|
+
};
|
|
455
484
|
}
|
|
456
485
|
function bundleDependencies(directory, scratch) {
|
|
457
486
|
let current = directory;
|
|
@@ -472,10 +501,11 @@ function bundlePackage(paths, manifest, policy, notices) {
|
|
|
472
501
|
const { directory, output, scratch } = paths;
|
|
473
502
|
const emitted = emitPackage(directory, scratch, true);
|
|
474
503
|
if (emitted.notice !== void 0) notices?.add(emitted.notice);
|
|
475
|
-
const entries = publishedEntries(directory, manifest, emitted, scratch);
|
|
504
|
+
const { entries, skipped } = publishedEntries(directory, manifest, emitted, scratch);
|
|
476
505
|
if (!entries.length) return {
|
|
477
506
|
count: 0,
|
|
478
|
-
published: []
|
|
507
|
+
published: [],
|
|
508
|
+
skipped
|
|
479
509
|
};
|
|
480
510
|
bundleDependencies(directory, scratch);
|
|
481
511
|
writeFileSync(join(scratch, "package.json"), readFileSync(join(directory, "package.json")));
|
|
@@ -521,7 +551,8 @@ function bundlePackage(paths, manifest, policy, notices) {
|
|
|
521
551
|
path: `${paths.name === "." ? "_root" : paths.name}/${entry}`,
|
|
522
552
|
directory: paths.name,
|
|
523
553
|
subpath
|
|
524
|
-
}))
|
|
554
|
+
})),
|
|
555
|
+
skipped
|
|
525
556
|
};
|
|
526
557
|
}
|
|
527
558
|
function declarationDiff(root, baseRef, policy) {
|
|
@@ -529,6 +560,7 @@ function declarationDiff(root, baseRef, policy) {
|
|
|
529
560
|
const notices = /* @__PURE__ */ new Set();
|
|
530
561
|
const failedPackages = /* @__PURE__ */ new Set();
|
|
531
562
|
const unpublished = /* @__PURE__ */ new Map();
|
|
563
|
+
const skippedTests = /* @__PURE__ */ new Set();
|
|
532
564
|
const result = compareRevisions(root, baseRef, "API", (worktree, output, scratch) => {
|
|
533
565
|
const packages = packagesAt(worktree, true);
|
|
534
566
|
for (const { directory, reason } of unpublishedAt(worktree)) unpublished.set(directory, reason);
|
|
@@ -545,6 +577,7 @@ function declarationDiff(root, baseRef, policy) {
|
|
|
545
577
|
scratch: join(scratch, key)
|
|
546
578
|
}, manifest, policy, notices);
|
|
547
579
|
entries += bundled.count;
|
|
580
|
+
for (const target of bundled.skipped) skippedTests.add(testEntryNotice("API", directory, target));
|
|
548
581
|
published.push(...bundled.published);
|
|
549
582
|
} catch (error) {
|
|
550
583
|
failedPackages.add(directory);
|
|
@@ -563,7 +596,7 @@ function declarationDiff(root, baseRef, policy) {
|
|
|
563
596
|
}, policy);
|
|
564
597
|
return {
|
|
565
598
|
different: result.different || errors.size > 0,
|
|
566
|
-
output: (errors.size > 0 && !result.different ? result.output.replace(/^API:[^\n]*\n/u, "API: comparison incomplete due to execution errors.\n") : result.output) + [...unpublished].sort(([a], [b]) => a.localeCompare(b)).map(([directory, reason]) => `API: skipped ${directory}, ${reason}.\n`).join("") + [...notices].sort().join("") + [...errors].join("")
|
|
599
|
+
output: (errors.size > 0 && !result.different ? result.output.replace(/^API:[^\n]*\n/u, "API: comparison incomplete due to execution errors.\n") : result.output) + [...unpublished].sort(([a], [b]) => a.localeCompare(b)).map(([directory, reason]) => `API: skipped ${directory}, ${reason}.\n`).join("") + [...skippedTests].sort().join("") + [...notices].sort().join("") + [...errors].join("")
|
|
567
600
|
};
|
|
568
601
|
}
|
|
569
602
|
/** Compares declarations and built runtime exports, with an optional behavioral probe captured before either build. Added entries whose subpath matches an `allowAdded` glob pass when their module is `@internal`. */
|
package/dist/bin/ratchet.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { t as CEILINGS_FILE } from "../ceilings-BSw9p4YB.mjs";
|
|
3
3
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
4
4
|
import { a as repositoryPath, o as repositoryRoot, s as resolveRevision } from "../files-2FikHZ9F.mjs";
|
|
5
|
-
import { n as stagedRatchet } from "../staged-ratchet-
|
|
6
|
-
import { n as ratchet } from "../ratchet-
|
|
5
|
+
import { n as stagedRatchet } from "../staged-ratchet-CjoRfZaM.mjs";
|
|
6
|
+
import { n as ratchet } from "../ratchet-DRdIYwmv.mjs";
|
|
7
7
|
import { resolve } from "node:path";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
//#region src/bin/ratchet.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
3
3
|
import { o as repositoryRoot, s as resolveRevision } from "../files-2FikHZ9F.mjs";
|
|
4
|
-
import { a as parseBudget, c as checkPolicy, i as checkSuppressions, n as SUPPRESSIONS_FILE, o as safetyCeiling, s as stagedSuppressions } from "../suppression-budget-
|
|
4
|
+
import { a as parseBudget, c as checkPolicy, i as checkSuppressions, n as SUPPRESSIONS_FILE, o as safetyCeiling, s as stagedSuppressions } from "../suppression-budget-Yyf5_J5l.mjs";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { execFileSync, spawnSync } from "node:child_process";
|
package/dist/bin/sync.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { a as formatCeilings, o as isRetired, s as readCeilings, t as CEILINGS_F
|
|
|
3
3
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
4
4
|
import { o as repositoryRoot } from "../files-2FikHZ9F.mjs";
|
|
5
5
|
import { a as repositoryTools, i as parseManifest, n as managedPackage, o as toolingVersions, r as packageManager, t as execCommand } from "../package-Dtjt_lSa.mjs";
|
|
6
|
-
import { t as measureBaseline } from "../ratchet-
|
|
7
|
-
import { n as SUPPRESSIONS_FILE, r as adoptedBudget } from "../suppression-budget-
|
|
6
|
+
import { t as measureBaseline } from "../ratchet-DRdIYwmv.mjs";
|
|
7
|
+
import { n as SUPPRESSIONS_FILE, r as adoptedBudget } from "../suppression-budget-Yyf5_J5l.mjs";
|
|
8
8
|
import { a as ciWorkflow, c as ciNodeCallers, i as MUTATION_PATH, l as hasChecksWorkflow, o as mutationCaller, r as CI_PATH, s as MISSING_CHECKS_WORKFLOW } from "../ci-workflow-BDy6hQJ6.mjs";
|
|
9
9
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
10
10
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -50,6 +50,7 @@ const SHARED_RULES = [
|
|
|
50
50
|
["Comments are TSDoc, directives, or `SAFETY:` only", "`antelopejs/no-comments`"],
|
|
51
51
|
["Every test asserts", "`antelopejs/require-assertion`"],
|
|
52
52
|
["Tests read no files outside fixtures, helpers, locales", "`antelopejs/no-fs-read-in-tests`"],
|
|
53
|
+
["Tests import the code under test from local source, not their own package name", "`antelopejs/no-self-import-in-tests`"],
|
|
53
54
|
["No assertion that restates a constant", "`antelopejs/no-constant-value-assertion`"],
|
|
54
55
|
["No test whose only check is \"is a function\"", "`antelopejs/no-typeof-function-only-test`"],
|
|
55
56
|
["Params ≤ 5, function ≤ 120 lines, file ≤ 500 lines, depth ≤ 4, complexity ≤ 20", "`eslint/max-*`, `eslint/complexity`"],
|
|
@@ -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
|
}
|
package/dist/oxc/lint.d.mts
CHANGED
|
@@ -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-
|
|
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-
|
|
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>`"]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/tooling-configs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
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",
|
|
@@ -1,119 +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 { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
-
import { basename, dirname, join } from "node:path";
|
|
7
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
8
|
-
//#region src/guardrails/oxlint.ts
|
|
9
|
-
function resolveOxlint(root) {
|
|
10
|
-
try {
|
|
11
|
-
const require = createRequire(join(root, "package.json"));
|
|
12
|
-
return join(dirname(require.resolve("oxlint/package.json")), "bin/oxlint");
|
|
13
|
-
} catch {
|
|
14
|
-
throw new Error("oxlint is not installed in this repository. Install dependencies first.");
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function ruleId(code) {
|
|
18
|
-
const match = /^([^()]+)\(([^()]+)\)$/.exec(code);
|
|
19
|
-
if (!match) throw new Error(`Cannot measure oxlint diagnostic code ${JSON.stringify(code)}. Fix parser or configuration errors before recording a baseline.`);
|
|
20
|
-
const [, plugin, rule] = match;
|
|
21
|
-
return `${plugin === "typescript-eslint" ? "typescript" : plugin}/${rule}`;
|
|
22
|
-
}
|
|
23
|
-
function parseDiagnostics(text, root) {
|
|
24
|
-
const report = JSON.parse(text);
|
|
25
|
-
if (!Array.isArray(report?.diagnostics)) throw new Error("oxlint did not return a JSON diagnostics array.");
|
|
26
|
-
return report.diagnostics.map((item) => {
|
|
27
|
-
const file = repositoryPath(root, item.filename);
|
|
28
|
-
const span = item.labels?.[0]?.span;
|
|
29
|
-
return {
|
|
30
|
-
rule: ruleId(item.code),
|
|
31
|
-
file,
|
|
32
|
-
location: span ? `${file}:${span.line}:${span.column}` : file,
|
|
33
|
-
message: item.message,
|
|
34
|
-
line: span?.line,
|
|
35
|
-
help: item.help
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function lintDiagnostics(root, config, files) {
|
|
40
|
-
const binary = resolveOxlint(root);
|
|
41
|
-
const temporary = config === void 0 ? void 0 : mkdtempSync(join(root, ".antelopejs-measure.generated."));
|
|
42
|
-
try {
|
|
43
|
-
const args = [
|
|
44
|
-
binary,
|
|
45
|
-
"-f",
|
|
46
|
-
"json"
|
|
47
|
-
];
|
|
48
|
-
if (temporary) {
|
|
49
|
-
const path = join(temporary, "oxlint.config.ts");
|
|
50
|
-
writeFileSync(path, config ?? "");
|
|
51
|
-
args.push("--config", path, "--ignore-pattern", `${basename(temporary)}/**`);
|
|
52
|
-
}
|
|
53
|
-
if (files) args.push("--no-error-on-unmatched-pattern", "--", ...files);
|
|
54
|
-
const result = spawnSync(process.execPath, args, {
|
|
55
|
-
cwd: root,
|
|
56
|
-
encoding: "utf8",
|
|
57
|
-
env: {
|
|
58
|
-
...process.env,
|
|
59
|
-
[MEASURE_ENV]: "1"
|
|
60
|
-
},
|
|
61
|
-
maxBuffer: 67108864
|
|
62
|
-
});
|
|
63
|
-
if (result.error) throw result.error;
|
|
64
|
-
if (result.status !== 0 && result.status !== 1) throw new Error(`oxlint failed (${result.status ?? result.signal}): ${result.stderr || result.stdout}`);
|
|
65
|
-
const diagnostics = parseDiagnostics(result.stdout, root);
|
|
66
|
-
if (result.status !== 0 && diagnostics.length === 0) throw new Error(`oxlint failed without diagnostics: ${result.stderr || result.stdout}`);
|
|
67
|
-
return diagnostics;
|
|
68
|
-
} finally {
|
|
69
|
-
if (temporary) rmSync(temporary, {
|
|
70
|
-
recursive: true,
|
|
71
|
-
force: true
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/guardrails/staged-ratchet.ts
|
|
77
|
-
/** The line ranges each staged file adds against HEAD, following renames. */
|
|
78
|
-
function stagedAdditions(root, targets) {
|
|
79
|
-
const renames = renamedPaths(root, true);
|
|
80
|
-
const additions = /* @__PURE__ */ new Map();
|
|
81
|
-
for (const file of targets) {
|
|
82
|
-
const diff = execFileSync("git", [
|
|
83
|
-
"diff",
|
|
84
|
-
"--cached",
|
|
85
|
-
"--no-ext-diff",
|
|
86
|
-
"--no-color",
|
|
87
|
-
"--unified=0",
|
|
88
|
-
"--find-renames",
|
|
89
|
-
"--",
|
|
90
|
-
...[renames.get(file), file].filter((path) => path !== void 0)
|
|
91
|
-
], {
|
|
92
|
-
cwd: root,
|
|
93
|
-
encoding: "utf8"
|
|
94
|
-
});
|
|
95
|
-
additions.set(file, Array.from(diff.matchAll(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/gm), ([, line, count]) => ({
|
|
96
|
-
start: Number(line),
|
|
97
|
-
end: Number(line) + Number(count ?? 1) - 1
|
|
98
|
-
})));
|
|
99
|
-
}
|
|
100
|
-
return additions;
|
|
101
|
-
}
|
|
102
|
-
function stagedRatchet(root, files) {
|
|
103
|
-
const targets = files ?? execFileSync("git", [
|
|
104
|
-
"diff",
|
|
105
|
-
"--cached",
|
|
106
|
-
"--name-only",
|
|
107
|
-
"--diff-filter=ACMR",
|
|
108
|
-
"-z"
|
|
109
|
-
], {
|
|
110
|
-
cwd: root,
|
|
111
|
-
encoding: "utf8"
|
|
112
|
-
}).split("\0").filter(Boolean);
|
|
113
|
-
if (!targets.length) return [];
|
|
114
|
-
const additions = stagedAdditions(root, targets);
|
|
115
|
-
const ceilings = readCeilings(root);
|
|
116
|
-
return lintDiagnostics(root, void 0, targets).filter(({ rule, file, line }) => Object.hasOwn(ceilings.rules, rule) && line !== void 0 && additions.get(file)?.some(({ start, end }) => line >= start && line <= end)).map((diagnostic) => `${diagnostic.location}: ${diagnostic.message} [${diagnostic.rule}]\n Fix: ${diagnostic.help ?? "Resolve this finding on the added line; the ceiling covers only legacy findings on untouched lines."}`);
|
|
117
|
-
}
|
|
118
|
-
//#endregion
|
|
119
|
-
export { stagedRatchet as n, lintDiagnostics as r, stagedAdditions as t };
|