lintmax 0.1.105 → 0.1.107
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 +1 -1
- package/dist/cli.mjs +625 -499
- package/dist/eslint.d.mts +1 -3
- package/dist/eslint.mjs +64 -38
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +1 -1
- package/dist/{lintmax-types-yjUuaLkM.d.mts → lintmax-types-Dj_XPbID.d.mts} +0 -2
- package/dist/{project-files-C4cvEhY7.mjs → project-files-BJWR09gY.mjs} +145 -92
- package/dist/{src-DDkinCyR.mjs → src-C2vei_sO.mjs} +203 -121
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { B as
|
|
3
|
-
import { r as sync } from "./src-
|
|
2
|
+
import { B as ESLINT_TEST_FILE_PATTERNS, C as joinPath, O as isRecord, U as PARSE_DIALECTS, V as OXLINT_CLI_ALLOW, _ as run, a as PRETTIER_MD_ARGS, b as dirnamePath, c as decodeText, d as lintmaxRoot, f as pathExists, g as resolveBin, h as readVersion, i as CliExitError, l as ensureDirectory, m as readRequiredJson, n as listProjectFiles, o as cacheDir, p as readJson, r as matchesGlob, s as cwd, t as escapeGlobPath, u as envValue, v as runCapture, x as fromFileUrl, y as usage, z as DEFAULT_SHARED_IGNORE_PATTERNS } from "./project-files-BJWR09gY.mjs";
|
|
3
|
+
import { r as sync } from "./src-C2vei_sO.mjs";
|
|
4
4
|
import { $, Glob, env, file, write } from "bun";
|
|
5
5
|
import { lstat, unlink } from "node:fs/promises";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { homedir, platform, tmpdir } from "node:os";
|
|
8
8
|
import { Buffer } from "node:buffer";
|
|
9
|
-
import {
|
|
9
|
+
import { parse } from "oxc-parser";
|
|
10
10
|
import { ESLint } from "eslint";
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
|
-
|
|
12
|
+
// src/rule-equivalence.ts
|
|
13
13
|
const equivalenceGroups = [
|
|
14
14
|
[
|
|
15
15
|
"lint/suspicious/noExplicitAny",
|
|
@@ -113,8 +113,7 @@ for (const group of equivalenceGroups) {
|
|
|
113
113
|
for (const rule of group) ruleToCanonical.set(rule, canonical);
|
|
114
114
|
}
|
|
115
115
|
const getCanonicalRule = (rule) => ruleToCanonical.get(rule) ?? rule;
|
|
116
|
-
|
|
117
|
-
//#region src/aggregate.ts
|
|
116
|
+
// src/aggregate.ts
|
|
118
117
|
const LINTER_PRIORITY = {
|
|
119
118
|
biome: 0,
|
|
120
119
|
eslint: 2,
|
|
@@ -127,16 +126,9 @@ const normalizePath = (filePath) => {
|
|
|
127
126
|
if (filePath.startsWith(cwdPrefix)) return filePath.slice(cwdPrefix.length);
|
|
128
127
|
return filePath;
|
|
129
128
|
};
|
|
130
|
-
const
|
|
131
|
-
let parsed;
|
|
132
|
-
try {
|
|
133
|
-
parsed = readRequiredJson(stdout);
|
|
134
|
-
} catch {
|
|
135
|
-
return [];
|
|
136
|
-
}
|
|
137
|
-
if (!Array.isArray(parsed.diagnostics)) return [];
|
|
129
|
+
const biomeEntries = (diagnostics) => {
|
|
138
130
|
const results = [];
|
|
139
|
-
for (const d of
|
|
131
|
+
for (const d of diagnostics) {
|
|
140
132
|
const filePath = d.location?.path;
|
|
141
133
|
const { category } = d;
|
|
142
134
|
if (filePath && category) {
|
|
@@ -151,7 +143,7 @@ const parseBiomeDiagnostics = ({ stdout }) => {
|
|
|
151
143
|
}
|
|
152
144
|
return results;
|
|
153
145
|
};
|
|
154
|
-
const
|
|
146
|
+
const parseBiomeDiagnostics = ({ stdout }) => {
|
|
155
147
|
let parsed;
|
|
156
148
|
try {
|
|
157
149
|
parsed = readRequiredJson(stdout);
|
|
@@ -159,8 +151,11 @@ const parseOxlintDiagnostics = ({ stdout }) => {
|
|
|
159
151
|
return [];
|
|
160
152
|
}
|
|
161
153
|
if (!Array.isArray(parsed.diagnostics)) return [];
|
|
154
|
+
return biomeEntries(parsed.diagnostics);
|
|
155
|
+
};
|
|
156
|
+
const oxlintEntries = (diagnostics) => {
|
|
162
157
|
const results = [];
|
|
163
|
-
for (const d of
|
|
158
|
+
for (const d of diagnostics) {
|
|
164
159
|
const filePath = d.filename ?? "";
|
|
165
160
|
const rule = d.code;
|
|
166
161
|
if (rule) {
|
|
@@ -175,7 +170,17 @@ const parseOxlintDiagnostics = ({ stdout }) => {
|
|
|
175
170
|
}
|
|
176
171
|
return results;
|
|
177
172
|
};
|
|
178
|
-
const
|
|
173
|
+
const parseOxlintDiagnostics = ({ stdout }) => {
|
|
174
|
+
let parsed;
|
|
175
|
+
try {
|
|
176
|
+
parsed = readRequiredJson(stdout);
|
|
177
|
+
} catch {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
if (!Array.isArray(parsed.diagnostics)) return [];
|
|
181
|
+
return oxlintEntries(parsed.diagnostics);
|
|
182
|
+
};
|
|
183
|
+
const eslintRuleOf = (msg) => msg.ruleId ?? (msg.severity === 2 || msg.fatal ? `parse-error: ${msg.message?.slice(0, 80) ?? "unknown"}` : void 0);
|
|
179
184
|
const eslintDiagnosticsForFile = (fileEntry) => {
|
|
180
185
|
const { filePath } = fileEntry;
|
|
181
186
|
if (!(filePath && Array.isArray(fileEntry.messages))) return [];
|
|
@@ -246,50 +251,57 @@ const dedup = (diagnostics) => {
|
|
|
246
251
|
return [...seen.values()];
|
|
247
252
|
};
|
|
248
253
|
const linterSort = (a, b) => (LINTER_PRIORITY[a] ?? 99) - (LINTER_PRIORITY[b] ?? 99);
|
|
249
|
-
const
|
|
254
|
+
const getOrCreate = (map, key, create) => {
|
|
255
|
+
const existing = map.get(key);
|
|
256
|
+
if (existing !== void 0) return existing;
|
|
257
|
+
const value = create();
|
|
258
|
+
map.set(key, value);
|
|
259
|
+
return value;
|
|
260
|
+
};
|
|
261
|
+
const appendDiagnostic = (fileMap, d) => {
|
|
262
|
+
const linterMap = getOrCreate(fileMap, d.file, () => /* @__PURE__ */ new Map());
|
|
263
|
+
const ruleMap = getOrCreate(linterMap, d.linter, () => /* @__PURE__ */ new Map());
|
|
264
|
+
const lines = getOrCreate(ruleMap, d.rule, () => []);
|
|
265
|
+
if (d.line > 0) lines.push(d.line);
|
|
266
|
+
};
|
|
267
|
+
const groupDiagnostics = (diagnostics) => {
|
|
250
268
|
const deduped = dedup(diagnostics);
|
|
251
269
|
const fileMap = /* @__PURE__ */ new Map();
|
|
252
|
-
for (const d of deduped)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
lines = [];
|
|
266
|
-
ruleMap.set(d.rule, lines);
|
|
267
|
-
}
|
|
268
|
-
if (d.line > 0) lines.push(d.line);
|
|
270
|
+
for (const d of deduped) appendDiagnostic(fileMap, d);
|
|
271
|
+
return fileMap;
|
|
272
|
+
};
|
|
273
|
+
const sortedGroupedRules = (ruleMap) => {
|
|
274
|
+
const rules = [];
|
|
275
|
+
const sortedRules = [...ruleMap.keys()].toSorted((a, b) => a.localeCompare(b));
|
|
276
|
+
for (const ruleName of sortedRules) {
|
|
277
|
+
const lines = ruleMap.get(ruleName) ?? [];
|
|
278
|
+
const uniqueLines = [...new Set(lines)].toSorted((a, b) => a - b);
|
|
279
|
+
rules.push({
|
|
280
|
+
lines: uniqueLines,
|
|
281
|
+
rule: ruleName
|
|
282
|
+
});
|
|
269
283
|
}
|
|
284
|
+
return rules;
|
|
285
|
+
};
|
|
286
|
+
const sortedGroupedLinters = (linterMap) => {
|
|
287
|
+
const linters = [];
|
|
288
|
+
const sortedLinters = [...linterMap.keys()].toSorted(linterSort);
|
|
289
|
+
for (const linterName of sortedLinters) {
|
|
290
|
+
const ruleMap = linterMap.get(linterName) ?? /* @__PURE__ */ new Map();
|
|
291
|
+
const rules = sortedGroupedRules(ruleMap);
|
|
292
|
+
linters.push({
|
|
293
|
+
linter: linterName,
|
|
294
|
+
rules
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return linters;
|
|
298
|
+
};
|
|
299
|
+
const aggregate = ({ diagnostics }) => {
|
|
300
|
+
const fileMap = groupDiagnostics(diagnostics);
|
|
270
301
|
const files = [];
|
|
271
302
|
const sortedFiles = [...fileMap.keys()].toSorted((a, b) => a.localeCompare(b));
|
|
272
303
|
for (const filePath of sortedFiles) {
|
|
273
|
-
const
|
|
274
|
-
const linters = [];
|
|
275
|
-
const sortedLinters = [...linterMap.keys()].toSorted(linterSort);
|
|
276
|
-
for (const linterName of sortedLinters) {
|
|
277
|
-
const ruleMap = linterMap.get(linterName) ?? /* @__PURE__ */ new Map();
|
|
278
|
-
const rules = [];
|
|
279
|
-
const sortedRules = [...ruleMap.keys()].toSorted((a, b) => a.localeCompare(b));
|
|
280
|
-
for (const ruleName of sortedRules) {
|
|
281
|
-
const lines = ruleMap.get(ruleName) ?? [];
|
|
282
|
-
const uniqueLines = [...new Set(lines)].toSorted((a, b) => a - b);
|
|
283
|
-
rules.push({
|
|
284
|
-
lines: uniqueLines,
|
|
285
|
-
rule: ruleName
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
linters.push({
|
|
289
|
-
linter: linterName,
|
|
290
|
-
rules
|
|
291
|
-
});
|
|
292
|
-
}
|
|
304
|
+
const linters = sortedGroupedLinters(fileMap.get(filePath) ?? /* @__PURE__ */ new Map());
|
|
293
305
|
files.push({
|
|
294
306
|
file: filePath,
|
|
295
307
|
linters
|
|
@@ -297,20 +309,18 @@ const aggregate = ({ diagnostics }) => {
|
|
|
297
309
|
}
|
|
298
310
|
return files;
|
|
299
311
|
};
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const parseAnyDialect = ({ label, sourceText }) => {
|
|
312
|
+
// src/parse-source.ts
|
|
313
|
+
const parseAnyDialect = async ({ label, sourceText }) => {
|
|
303
314
|
let firstError;
|
|
304
|
-
|
|
305
|
-
|
|
315
|
+
const results = await Promise.all(PARSE_DIALECTS.map(async (dialect) => parse(dialect, sourceText)));
|
|
316
|
+
for (const parsed of results) {
|
|
306
317
|
const [parseError] = parsed.errors;
|
|
307
318
|
if (!parseError) return parsed;
|
|
308
319
|
firstError ??= parseError.message;
|
|
309
320
|
}
|
|
310
321
|
throw new Error(`${label} cannot parse the source: ${firstError ?? "unknown parse failure"}`);
|
|
311
322
|
};
|
|
312
|
-
|
|
313
|
-
//#region src/class-name.ts
|
|
323
|
+
// src/class-name.ts
|
|
314
324
|
const CN_NAMES = /* @__PURE__ */ new Set(["cn"]);
|
|
315
325
|
const BANNED_CALLEE_NAMES = /* @__PURE__ */ new Set([
|
|
316
326
|
"classnames",
|
|
@@ -319,7 +329,7 @@ const BANNED_CALLEE_NAMES = /* @__PURE__ */ new Set([
|
|
|
319
329
|
"twMerge"
|
|
320
330
|
]);
|
|
321
331
|
const asNode = (v) => {
|
|
322
|
-
if (!v || typeof v !== "object" || !("type" in v) || typeof v.type !== "string") return
|
|
332
|
+
if (!v || typeof v !== "object" || !("type" in v) || typeof v.type !== "string") return;
|
|
323
333
|
/** biome-ignore lint/nursery/noUnsafeTypeAssertion: external parser AST node is narrowed only at this boundary */
|
|
324
334
|
return v;
|
|
325
335
|
};
|
|
@@ -341,13 +351,12 @@ const isJoinCall = (n) => {
|
|
|
341
351
|
const isBannedCallee = (n) => n.type === "CallExpression" && n.callee?.type === "Identifier" && BANNED_CALLEE_NAMES.has(strName(n.callee));
|
|
342
352
|
const isStringLiteral = (n) => n.type === "Literal" && typeof n.value === "string" || n.type === "TemplateLiteral" && Array.isArray(n.expressions) && n.expressions.length === 0;
|
|
343
353
|
const classNameExprRule = (expr) => {
|
|
344
|
-
if (isStringLiteral(expr) || isCallToCn(expr)) return
|
|
354
|
+
if (isStringLiteral(expr) || isCallToCn(expr)) return;
|
|
345
355
|
if (expr.type === "TemplateLiteral") return "cn/no-template-literal";
|
|
346
356
|
if (expr.type === "ConditionalExpression") return "cn/no-ternary";
|
|
347
357
|
if (expr.type === "BinaryExpression" && expr.operator === "+") return "cn/no-concatenation";
|
|
348
358
|
if (isBannedCallee(expr)) return "cn/no-banned-callee";
|
|
349
359
|
if (isJoinCall(expr)) return "cn/no-join";
|
|
350
|
-
return null;
|
|
351
360
|
};
|
|
352
361
|
const collectClassNameAttrViolation = (node, sourceText, violations) => {
|
|
353
362
|
const container = node.value;
|
|
@@ -365,8 +374,8 @@ const collectBannedCalleeViolation = ({ grand, node, parent, sourceText, violati
|
|
|
365
374
|
rule: "cn/no-banned-callee"
|
|
366
375
|
});
|
|
367
376
|
};
|
|
368
|
-
const findClassNameViolations = ({ sourceText }) => {
|
|
369
|
-
const { program } = parseAnyDialect({
|
|
377
|
+
const findClassNameViolations = async ({ sourceText }) => {
|
|
378
|
+
const { program } = await parseAnyDialect({
|
|
370
379
|
label: "className check",
|
|
371
380
|
sourceText
|
|
372
381
|
});
|
|
@@ -391,7 +400,7 @@ const findClassNameViolations = ({ sourceText }) => {
|
|
|
391
400
|
});
|
|
392
401
|
for (const key of Object.keys(node)) if (key !== "type") visit(node[key], node, parent);
|
|
393
402
|
};
|
|
394
|
-
visit(program,
|
|
403
|
+
visit(program, void 0, void 0);
|
|
395
404
|
return violations;
|
|
396
405
|
};
|
|
397
406
|
const TSX_EXTENSIONS = /* @__PURE__ */ new Set([".tsx"]);
|
|
@@ -404,7 +413,7 @@ const checkClassNameFile = async (filePath) => {
|
|
|
404
413
|
const f = file(filePath);
|
|
405
414
|
if (!await f.exists()) return [];
|
|
406
415
|
const sourceText = await f.text();
|
|
407
|
-
return findClassNameViolations({ sourceText }).map((v) => ({
|
|
416
|
+
return (await findClassNameViolations({ sourceText })).map((v) => ({
|
|
408
417
|
file: filePath,
|
|
409
418
|
line: v.line,
|
|
410
419
|
linter: "cn",
|
|
@@ -415,8 +424,7 @@ const checkClassName = async ({ root }) => {
|
|
|
415
424
|
const paths = (await listProjectFiles({ root })).filter((path) => isTsxFile(path) && !(path.includes("node_modules") || path.includes("readonly") || path.includes(".next") || path.includes("dist")));
|
|
416
425
|
return (await Promise.all(paths.map(async (path) => checkClassNameFile(joinPath(root, path))))).flat();
|
|
417
426
|
};
|
|
418
|
-
|
|
419
|
-
//#region src/rules.ts
|
|
427
|
+
// src/rules.ts
|
|
420
428
|
const extractBiomeRules = async () => {
|
|
421
429
|
const pkgPath = fromFileUrl(import.meta.resolve("@biomejs/biome/configuration_schema.json"));
|
|
422
430
|
const defs = readRequiredJson(await file(pkgPath).text()).$defs ?? {};
|
|
@@ -442,46 +450,45 @@ const extractBiomeRules = async () => {
|
|
|
442
450
|
}
|
|
443
451
|
return results;
|
|
444
452
|
};
|
|
445
|
-
|
|
446
|
-
const extractOxlintRules = async () => {
|
|
447
|
-
const configPath = joinPath(cwd, "node_modules/.cache/lintmax/.oxlintrc.json");
|
|
448
|
-
const bin = await resolveBin({
|
|
449
|
-
bin: "oxlint",
|
|
450
|
-
pkg: "oxlint"
|
|
451
|
-
});
|
|
452
|
-
const result = await $`bun ${bin} -c ${configPath} --print-config`.cwd(cwd).quiet().nothrow();
|
|
453
|
-
if (result.exitCode !== 0) throw new Error(`oxlint --print-config failed, so its rule set is unknown: ${result.stderr.toString().trim()}`);
|
|
454
|
-
const parsed = JSON.parse(result.stdout.toString());
|
|
455
|
-
if (!isRecord(parsed)) throw new Error("oxlint --print-config returned no document");
|
|
456
|
-
const { rules } = parsed;
|
|
457
|
-
if (!isRecord(rules)) throw new Error("oxlint --print-config returned no rules map");
|
|
453
|
+
const enabledOxlintRules = (rules) => {
|
|
458
454
|
const results = [];
|
|
459
455
|
for (const [rule, value] of Object.entries(rules)) if ((Array.isArray(value) ? value[0] : value) === "deny") results.push({
|
|
460
456
|
fixable: false,
|
|
461
457
|
linter: "oxlint",
|
|
462
458
|
rule
|
|
463
459
|
});
|
|
460
|
+
return results;
|
|
461
|
+
};
|
|
462
|
+
const parseOxlintRules = (stdout) => {
|
|
463
|
+
const parsed = JSON.parse(stdout);
|
|
464
|
+
if (!isRecord(parsed)) throw new Error("oxlint --print-config returned no document");
|
|
465
|
+
const { rules } = parsed;
|
|
466
|
+
if (!isRecord(rules)) throw new Error("oxlint --print-config returned no rules map");
|
|
467
|
+
const results = enabledOxlintRules(rules);
|
|
464
468
|
if (results.length === 0) throw new Error("oxlint reports zero enabled rules — the gate runs it, so that cannot be right");
|
|
465
469
|
return results;
|
|
466
470
|
};
|
|
467
|
-
const
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
|
|
471
|
+
const extractOxlintRules = async () => {
|
|
472
|
+
const configPath = joinPath(cwd, "node_modules/.cache/lintmax/.oxlintrc.json");
|
|
473
|
+
const bin = await resolveBin({
|
|
474
|
+
bin: "oxlint",
|
|
475
|
+
pkg: "oxlint"
|
|
471
476
|
});
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (result.exitCode !== 0) throw new Error(`eslint --print-config failed, so its rule set is unknown: ${result.stderr.toString().trim()}`);
|
|
477
|
+
const result = await $`bun ${bin} -c ${configPath} --print-config`.cwd(cwd).quiet().nothrow();
|
|
478
|
+
if (result.exitCode !== 0) throw new Error(`oxlint --print-config failed, so its rule set is unknown: ${result.stderr.toString().trim()}`);
|
|
479
|
+
return parseOxlintRules(result.stdout.toString());
|
|
480
|
+
};
|
|
481
|
+
const readEslintDocument = (stdout) => {
|
|
478
482
|
let parsed;
|
|
479
483
|
try {
|
|
480
|
-
parsed = readRequiredJson(
|
|
484
|
+
parsed = readRequiredJson(stdout);
|
|
481
485
|
} catch (error) {
|
|
482
486
|
throw new Error(`eslint --print-config returned unreadable JSON: ${error instanceof Error ? error.message : ""}`, { cause: error });
|
|
483
487
|
}
|
|
484
|
-
|
|
488
|
+
return parsed;
|
|
489
|
+
};
|
|
490
|
+
const parseEslintRules = (stdout) => {
|
|
491
|
+
const allRules = readEslintDocument(stdout).rules ?? {};
|
|
485
492
|
const results = [];
|
|
486
493
|
for (const [rule, config] of Object.entries(allRules)) {
|
|
487
494
|
const level = Array.isArray(config) ? config[0] : config;
|
|
@@ -493,6 +500,19 @@ const extractEslintRules = async () => {
|
|
|
493
500
|
}
|
|
494
501
|
return results;
|
|
495
502
|
};
|
|
503
|
+
const extractEslintRules = async () => {
|
|
504
|
+
const eslintBin = await resolveBin({
|
|
505
|
+
bin: "eslint",
|
|
506
|
+
pkg: "eslint"
|
|
507
|
+
});
|
|
508
|
+
const configPath = joinPath(cwd, "node_modules/.cache/lintmax/eslint.generated.mjs");
|
|
509
|
+
const dummyFile = joinPath(cwd, "_lintmax_dummy.ts");
|
|
510
|
+
await write(dummyFile, "export {}\n");
|
|
511
|
+
const result = await $`bun ${eslintBin} --config ${configPath} --print-config ${dummyFile}`.cwd(cwd).quiet().nothrow();
|
|
512
|
+
await unlink(dummyFile).catch(() => void 0);
|
|
513
|
+
if (result.exitCode !== 0) throw new Error(`eslint --print-config failed, so its rule set is unknown: ${result.stderr.toString().trim()}`);
|
|
514
|
+
return parseEslintRules(result.stdout.toString());
|
|
515
|
+
};
|
|
496
516
|
const extractAllRules = async () => {
|
|
497
517
|
const [oxlint, biome, eslint] = await Promise.all([
|
|
498
518
|
extractOxlintRules(),
|
|
@@ -509,6 +529,14 @@ const extractAllRules = async () => {
|
|
|
509
529
|
return a.rule.localeCompare(b.rule);
|
|
510
530
|
});
|
|
511
531
|
};
|
|
532
|
+
const formatLinterRuleGroups = (byLinter) => {
|
|
533
|
+
const parts = [];
|
|
534
|
+
for (const [linter, ruleList] of byLinter) {
|
|
535
|
+
parts.push(`${linter} (${ruleList.length})`);
|
|
536
|
+
for (const rule of ruleList) parts.push(` ${rule}`);
|
|
537
|
+
}
|
|
538
|
+
return parts.join("\n");
|
|
539
|
+
};
|
|
512
540
|
const formatRulesCompact = (rules) => {
|
|
513
541
|
const byLinter = /* @__PURE__ */ new Map();
|
|
514
542
|
for (const r of rules) {
|
|
@@ -519,12 +547,7 @@ const formatRulesCompact = (rules) => {
|
|
|
519
547
|
}
|
|
520
548
|
list.push(r.rule);
|
|
521
549
|
}
|
|
522
|
-
|
|
523
|
-
for (const [linter, ruleList] of byLinter) {
|
|
524
|
-
parts.push(`${linter} (${ruleList.length})`);
|
|
525
|
-
for (const rule of ruleList) parts.push(` ${rule}`);
|
|
526
|
-
}
|
|
527
|
-
return parts.join("\n");
|
|
550
|
+
return formatLinterRuleGroups(byLinter);
|
|
528
551
|
};
|
|
529
552
|
const formatRulesHuman = (rules) => {
|
|
530
553
|
const header = "Linter Rule";
|
|
@@ -534,8 +557,7 @@ const formatRulesHuman = (rules) => {
|
|
|
534
557
|
lines.push(separator, `Total: ${rules.length} rules`);
|
|
535
558
|
return lines.join("\n");
|
|
536
559
|
};
|
|
537
|
-
|
|
538
|
-
//#region src/clean-ignores.ts
|
|
560
|
+
// src/clean-ignores.ts
|
|
539
561
|
const eslintLineRe = /^(?<prefix>\s*(?:\/\/|\/\*)\s*eslint-disable(?:-next-line)?\s+)(?<rules>\S(?:[^*]*[^\s*])?)(?<suffix>\s*\*\/)?$/v;
|
|
540
562
|
const oxlintLineRe = /^(?<prefix>\s*(?:\/\/|\/\*)\s*oxlint-disable(?:-next-line)?\s+)(?<rules>\S(?:[^*]*[^\s*])?)(?<suffix>\s*\*\/)?$/v;
|
|
541
563
|
const biomeLineRe = /^\s*(?:\/\/|\/\*\*)\s*biome-ignore(?:-all)?\s+(?<rule>[\w\/]+)/v;
|
|
@@ -573,29 +595,33 @@ const OXLINT_SEPARATORS = [
|
|
|
573
595
|
"/",
|
|
574
596
|
"\\"
|
|
575
597
|
];
|
|
576
|
-
/** The prefix+separator a rule id starts with, or undefined — a plain-string scan replacing a 27-branch alternation. Order-independent: the separator requirement disambiguates a short prefix from a longer one (`react-hooks/x` never matches `react` because `-` is not a separator). */
|
|
577
598
|
const oxlintPrefixMatch = (rule) => {
|
|
578
599
|
for (const prefix of OXLINT_PREFIXES) for (const sep of OXLINT_SEPARATORS) if (rule.startsWith(`${prefix}${sep}`)) return `${prefix}${sep}`;
|
|
579
600
|
};
|
|
580
601
|
const trailingParenRe = /\)$/v;
|
|
581
602
|
const trailingSepRe = /[(/\\]$/u;
|
|
582
603
|
const eslintPluginPrefixRe = /^eslint-plugin-/v;
|
|
583
|
-
|
|
584
|
-
const buildOxlintVariants = (rule, oxMatch) => {
|
|
585
|
-
const variants = [];
|
|
586
|
-
const bare = rule.slice(oxMatch.length).replace(trailingParenRe, "");
|
|
587
|
-
variants.push(bare);
|
|
588
|
-
const prefix = oxMatch.replace(trailingSepRe, "");
|
|
589
|
-
variants.push(`${prefix}/${bare}`, `${prefix}(${bare})`);
|
|
604
|
+
const appendPluginVariants = ({ bare, prefix, variants }) => {
|
|
590
605
|
if (prefix === "eslint") variants.push(bare);
|
|
591
606
|
if (prefix === "typescript-eslint") variants.push(`@typescript-eslint/${bare}`);
|
|
592
607
|
if (prefix.startsWith("eslint-plugin-")) {
|
|
593
608
|
const short = prefix.replace(eslintPluginPrefixRe, "");
|
|
594
609
|
variants.push(`${short}/${bare}`, `${short}(${bare})`);
|
|
595
610
|
}
|
|
611
|
+
};
|
|
612
|
+
const buildOxlintVariants = (rule, oxMatch) => {
|
|
613
|
+
const variants = [];
|
|
614
|
+
const bare = rule.slice(oxMatch.length).replace(trailingParenRe, "");
|
|
615
|
+
variants.push(bare);
|
|
616
|
+
const prefix = oxMatch.replace(trailingSepRe, "");
|
|
617
|
+
variants.push(`${prefix}/${bare}`, `${prefix}(${bare})`);
|
|
618
|
+
appendPluginVariants({
|
|
619
|
+
bare,
|
|
620
|
+
prefix,
|
|
621
|
+
variants
|
|
622
|
+
});
|
|
596
623
|
return variants;
|
|
597
624
|
};
|
|
598
|
-
/** The underscore↔dash spelling twins of each variant — a `_` id also spelled with `-` and vice versa. */
|
|
599
625
|
const expandUnderscoreDash = (variants) => {
|
|
600
626
|
const extra = [];
|
|
601
627
|
for (const v of variants) {
|
|
@@ -604,17 +630,21 @@ const expandUnderscoreDash = (variants) => {
|
|
|
604
630
|
}
|
|
605
631
|
return extra;
|
|
606
632
|
};
|
|
633
|
+
const appendNamespaceVariants = (rule, variants) => {
|
|
634
|
+
if (rule.startsWith("@typescript-eslint/")) variants.push(`typescript-eslint(${rule.slice(19)})`);
|
|
635
|
+
if (rule.startsWith("@next/next/")) variants.push(`nextjs(${rule.slice(11)})`);
|
|
636
|
+
if (rule.startsWith("@eslint-react/")) variants.push(`react(${rule.slice(14)})`);
|
|
637
|
+
};
|
|
607
638
|
const normalizeRule = (rule) => {
|
|
608
639
|
const variants = [rule];
|
|
609
640
|
const oxMatch = oxlintPrefixMatch(rule);
|
|
610
641
|
if (oxMatch !== void 0) variants.push(...buildOxlintVariants(rule, oxMatch));
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
for (const e of expandUnderscoreDash(variants)) variants.push(e);
|
|
642
|
+
appendNamespaceVariants(rule, variants);
|
|
643
|
+
const expandedVariants = expandUnderscoreDash(variants);
|
|
644
|
+
for (const e of expandedVariants) variants.push(e);
|
|
615
645
|
return variants;
|
|
616
646
|
};
|
|
617
|
-
const
|
|
647
|
+
const readOxlintConfig = async () => {
|
|
618
648
|
const configPath = joinPath(process.cwd(), cacheDir, ".oxlintrc.json");
|
|
619
649
|
if (!await file(configPath).exists()) throw new Error(`clean-ignores: the generated config is absent at ${configPath}, so no rule reads as off and every directive for an off rule would be kept. The stage that writes it did not run.`);
|
|
620
650
|
let config;
|
|
@@ -623,21 +653,28 @@ const loadOxlintOffRules = async () => {
|
|
|
623
653
|
} catch (error) {
|
|
624
654
|
throw new Error(`clean-ignores: the generated config at ${configPath} carries no parseable JSON. Refusing rather than reading it as "no rule is off", which would silently keep every directive.`, { cause: error });
|
|
625
655
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
656
|
+
return config;
|
|
657
|
+
};
|
|
658
|
+
const addRuleVariants = (rule, target) => {
|
|
659
|
+
const variants = normalizeRule(rule);
|
|
660
|
+
for (const variant of variants) target.add(variant);
|
|
661
|
+
};
|
|
662
|
+
const loadOxlintOffRules = async () => {
|
|
663
|
+
const config = await readOxlintConfig();
|
|
664
|
+
const off = new Set(OXLINT_CLI_ALLOW);
|
|
665
|
+
const configuredRules = Object.entries(config.rules ?? {});
|
|
666
|
+
for (const [rule, val] of configuredRules) if ((Array.isArray(val) ? String(val[0]) : val) === "off") {
|
|
632
667
|
off.add(rule);
|
|
633
|
-
|
|
668
|
+
addRuleVariants(rule, off);
|
|
634
669
|
}
|
|
670
|
+
for (const rule of OXLINT_CLI_ALLOW) addRuleVariants(rule, off);
|
|
635
671
|
return off;
|
|
636
672
|
};
|
|
637
673
|
const buildActiveRuleSet = async ({ excludeEslint = false } = {}) => {
|
|
638
674
|
const rules = await extractAllRules();
|
|
639
675
|
const active = /* @__PURE__ */ new Set();
|
|
640
|
-
|
|
676
|
+
const includedRules = rules.filter((rule) => !excludeEslint || rule.linter !== "eslint");
|
|
677
|
+
for (const r of includedRules) {
|
|
641
678
|
active.add(r.rule);
|
|
642
679
|
for (const v of normalizeRule(r.rule)) active.add(v);
|
|
643
680
|
}
|
|
@@ -650,8 +687,7 @@ const isRuleActive = (rule, active, oxlintOff) => {
|
|
|
650
687
|
}
|
|
651
688
|
if (active.has(rule)) return true;
|
|
652
689
|
for (const v of normalizeRule(rule)) if (active.has(v)) return true;
|
|
653
|
-
|
|
654
|
-
return true;
|
|
690
|
+
return Boolean(oxlintOff);
|
|
655
691
|
};
|
|
656
692
|
const splitCsvRules = (ruleList) => ruleList.split(",").map((r) => r.trim()).filter(Boolean);
|
|
657
693
|
const splitDirective = (str) => {
|
|
@@ -670,27 +706,21 @@ const splitDirective = (str) => {
|
|
|
670
706
|
};
|
|
671
707
|
};
|
|
672
708
|
const processMultiRuleLine = ({ active, isOxlint, line, match, oxlintOff, result }) => {
|
|
673
|
-
const
|
|
674
|
-
const rulesStr = match.rules ?? "";
|
|
675
|
-
const suffix = match.suffix ?? "";
|
|
676
|
-
const { reason, rules } = splitDirective(rulesStr);
|
|
709
|
+
const { reason, rules } = splitDirective(match.rules ?? "");
|
|
677
710
|
const kept = rules.filter((r) => isRuleActive(r, active, isOxlint ? oxlintOff : void 0));
|
|
678
711
|
if (kept.length === 0) return rules.length;
|
|
679
712
|
if (kept.length < rules.length) {
|
|
680
|
-
result.push(`${prefix}${kept.join(", ")}${reason}${suffix}`);
|
|
713
|
+
result.push(`${match.prefix ?? ""}${kept.join(", ")}${reason}${match.suffix ?? ""}`);
|
|
681
714
|
return rules.length - kept.length;
|
|
682
715
|
}
|
|
683
716
|
result.push(line);
|
|
684
717
|
return 0;
|
|
685
718
|
};
|
|
686
|
-
|
|
687
|
-
const processIgnoreLine = ({ active, eslintActive, line, oxlintOff, result }) => {
|
|
719
|
+
const processEslintLine = ({ active, line, result }) => {
|
|
688
720
|
eslintLineRe.lastIndex = 0;
|
|
689
|
-
oxlintLineRe.lastIndex = 0;
|
|
690
|
-
biomeLineRe.lastIndex = 0;
|
|
691
721
|
const eslintMatch = eslintLineRe.exec(line);
|
|
692
722
|
if (eslintMatch) return processMultiRuleLine({
|
|
693
|
-
active
|
|
723
|
+
active,
|
|
694
724
|
line,
|
|
695
725
|
match: {
|
|
696
726
|
prefix: eslintMatch.groups?.prefix,
|
|
@@ -699,6 +729,8 @@ const processIgnoreLine = ({ active, eslintActive, line, oxlintOff, result }) =>
|
|
|
699
729
|
},
|
|
700
730
|
result
|
|
701
731
|
});
|
|
732
|
+
};
|
|
733
|
+
const processOxlintLine = ({ active, line, oxlintOff, result }) => {
|
|
702
734
|
const oxlintMatch = oxlintLineRe.exec(line);
|
|
703
735
|
if (oxlintMatch) return processMultiRuleLine({
|
|
704
736
|
active,
|
|
@@ -712,6 +744,19 @@ const processIgnoreLine = ({ active, eslintActive, line, oxlintOff, result }) =>
|
|
|
712
744
|
oxlintOff,
|
|
713
745
|
result
|
|
714
746
|
});
|
|
747
|
+
};
|
|
748
|
+
const processIgnoreLine = ({ active, eslintActive, line, oxlintOff, result }) => {
|
|
749
|
+
const matchedResult = processEslintLine({
|
|
750
|
+
active: eslintActive ?? active,
|
|
751
|
+
line,
|
|
752
|
+
result
|
|
753
|
+
}) ?? processOxlintLine({
|
|
754
|
+
active,
|
|
755
|
+
line,
|
|
756
|
+
oxlintOff,
|
|
757
|
+
result
|
|
758
|
+
});
|
|
759
|
+
if (matchedResult !== void 0) return matchedResult;
|
|
715
760
|
const biomeMatch = biomeLineRe.exec(line);
|
|
716
761
|
if (biomeMatch && !isRuleActive(biomeMatch.groups?.rule ?? "", active)) return 1;
|
|
717
762
|
result.push(line);
|
|
@@ -771,8 +816,7 @@ const cleanIgnores = async (filePaths) => {
|
|
|
771
816
|
files: filePaths.filter((_, index) => (counts[index] ?? 0) > 0)
|
|
772
817
|
};
|
|
773
818
|
};
|
|
774
|
-
|
|
775
|
-
//#region src/comments.ts
|
|
819
|
+
// src/comments.ts
|
|
776
820
|
const lineAt = (sourceText, offset) => {
|
|
777
821
|
let line = 1;
|
|
778
822
|
for (let i = 0; i < offset && i < sourceText.length; i += 1) if (sourceText[i] === "\n") line += 1;
|
|
@@ -803,8 +847,8 @@ const isBlockOnlyComment = (sourceText, comments, c) => {
|
|
|
803
847
|
while (after < sourceText.length && (WS_CHAR.test(sourceText[after] ?? "") || inComment(after))) after += 1;
|
|
804
848
|
return sourceText[before] === "{" && sourceText[after] === "}";
|
|
805
849
|
};
|
|
806
|
-
const findDeletableComments = ({ sourceText }) => {
|
|
807
|
-
const { comments } = parseAnyDialect({
|
|
850
|
+
const findDeletableComments = async ({ sourceText }) => {
|
|
851
|
+
const { comments } = await parseAnyDialect({
|
|
808
852
|
label: "comment strip",
|
|
809
853
|
sourceText
|
|
810
854
|
});
|
|
@@ -820,26 +864,34 @@ const findDeletableComments = ({ sourceText }) => {
|
|
|
820
864
|
deletable.sort((a, b) => a.start - b.start);
|
|
821
865
|
return deletable;
|
|
822
866
|
};
|
|
823
|
-
const
|
|
824
|
-
|
|
867
|
+
const skipLineEnding = (sourceText, end) => {
|
|
868
|
+
if (sourceText[end] === "\n") return end + 1;
|
|
869
|
+
if (sourceText[end] === "\r" && sourceText[end + 1] === "\n") return end + 2;
|
|
870
|
+
return end;
|
|
871
|
+
};
|
|
872
|
+
const appendWithoutComment = ({ comment, cursor, parts, sourceText }) => {
|
|
873
|
+
const beforeChunk = sourceText.slice(cursor, comment.start);
|
|
874
|
+
const lineStart = beforeChunk.lastIndexOf("\n") + 1;
|
|
875
|
+
const indent = beforeChunk.slice(lineStart);
|
|
876
|
+
const afterEnd = skipLineEnding(sourceText, comment.end);
|
|
877
|
+
if (WHITESPACE_ONLY.test(indent) && afterEnd <= sourceText.length) {
|
|
878
|
+
parts.push(beforeChunk.slice(0, lineStart));
|
|
879
|
+
return afterEnd;
|
|
880
|
+
}
|
|
881
|
+
parts.push(beforeChunk);
|
|
882
|
+
return comment.end;
|
|
883
|
+
};
|
|
884
|
+
const deleteComments = async ({ sourceText }) => {
|
|
885
|
+
const comments = await findDeletableComments({ sourceText });
|
|
825
886
|
if (comments.length === 0) return sourceText;
|
|
826
887
|
const parts = [];
|
|
827
888
|
let cursor = 0;
|
|
828
|
-
for (const c of comments) {
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
else if (sourceText[afterEnd] === "\r" && sourceText[afterEnd + 1] === "\n") afterEnd += 2;
|
|
835
|
-
if (WHITESPACE_ONLY.test(indent) && afterEnd <= sourceText.length) {
|
|
836
|
-
parts.push(beforeChunk.slice(0, lineStart));
|
|
837
|
-
cursor = afterEnd;
|
|
838
|
-
} else {
|
|
839
|
-
parts.push(beforeChunk);
|
|
840
|
-
cursor = c.end;
|
|
841
|
-
}
|
|
842
|
-
}
|
|
889
|
+
for (const c of comments) cursor = appendWithoutComment({
|
|
890
|
+
comment: c,
|
|
891
|
+
cursor,
|
|
892
|
+
parts,
|
|
893
|
+
sourceText
|
|
894
|
+
});
|
|
843
895
|
parts.push(sourceText.slice(cursor));
|
|
844
896
|
return parts.join("");
|
|
845
897
|
};
|
|
@@ -854,7 +906,7 @@ const processFile = async (filePath) => {
|
|
|
854
906
|
modified: false
|
|
855
907
|
};
|
|
856
908
|
const sourceText = await f.text();
|
|
857
|
-
const comments = findDeletableComments({ sourceText });
|
|
909
|
+
const comments = await findDeletableComments({ sourceText });
|
|
858
910
|
const diagnostics = [];
|
|
859
911
|
for (const c of comments) diagnostics.push({
|
|
860
912
|
file: filePath,
|
|
@@ -872,7 +924,7 @@ const processFileForFix = async (filePath) => {
|
|
|
872
924
|
const f = file(filePath);
|
|
873
925
|
if (!await f.exists()) return false;
|
|
874
926
|
const sourceText = await f.text();
|
|
875
|
-
const result = deleteComments({ sourceText });
|
|
927
|
+
const result = await deleteComments({ sourceText });
|
|
876
928
|
if (result !== sourceText) {
|
|
877
929
|
await write(filePath, result);
|
|
878
930
|
return true;
|
|
@@ -885,8 +937,7 @@ const checkComments = async ({ files }) => {
|
|
|
885
937
|
const fixComments = async ({ files }) => {
|
|
886
938
|
return (await Promise.all(files.map(async (f) => processFileForFix(f)))).filter(Boolean).length;
|
|
887
939
|
};
|
|
888
|
-
|
|
889
|
-
//#region src/compact.ts
|
|
940
|
+
// src/compact.ts
|
|
890
941
|
const isSymlinkSafe = async (p) => {
|
|
891
942
|
try {
|
|
892
943
|
return (await lstat(p)).isSymbolicLink();
|
|
@@ -933,7 +984,7 @@ const extension = ({ path }) => {
|
|
|
933
984
|
const dotIndex = path.lastIndexOf(".");
|
|
934
985
|
return dotIndex > slashIndex ? path.slice(dotIndex) : "";
|
|
935
986
|
};
|
|
936
|
-
const compactContent = ({ content }) => content.
|
|
987
|
+
const compactContent = ({ content }) => content.replaceAll(COMPACT_REGEX, "\n");
|
|
937
988
|
const isCompactCandidate = ({ relativePath }) => {
|
|
938
989
|
const fileName = basename({ path: relativePath });
|
|
939
990
|
if (compactBasenames.has(fileName)) return true;
|
|
@@ -951,56 +1002,55 @@ const listCompactFiles = async ({ env, root }) => {
|
|
|
951
1002
|
const symlinkFlags = await Promise.all(entries.map(async (e) => isSymlinkSafe(join(root, e))));
|
|
952
1003
|
return entries.filter((_e, index) => !symlinkFlags[index]);
|
|
953
1004
|
};
|
|
954
|
-
const
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1005
|
+
const compactFileContent = async ({ absolutePath, bytes, mode, relativePath }) => {
|
|
1006
|
+
if (isBinary({ bytes })) return {
|
|
1007
|
+
changed: false,
|
|
1008
|
+
relativePath,
|
|
1009
|
+
scanned: true
|
|
1010
|
+
};
|
|
1011
|
+
const content = decodeText(bytes);
|
|
1012
|
+
const compacted = compactContent({ content });
|
|
1013
|
+
if (content === compacted) return {
|
|
1014
|
+
changed: false,
|
|
1015
|
+
relativePath,
|
|
1016
|
+
scanned: true
|
|
1017
|
+
};
|
|
1018
|
+
if (mode === "fix") await write(absolutePath, compacted);
|
|
1019
|
+
return {
|
|
1020
|
+
changed: true,
|
|
1021
|
+
relativePath,
|
|
1022
|
+
scanned: true
|
|
1023
|
+
};
|
|
1024
|
+
};
|
|
1025
|
+
const compactFile = async (relativePath, root, mode) => {
|
|
1026
|
+
if (!isCompactCandidate({ relativePath })) return {
|
|
1027
|
+
changed: false,
|
|
1028
|
+
relativePath,
|
|
1029
|
+
scanned: false
|
|
1030
|
+
};
|
|
1031
|
+
const absolutePath = joinPath(root, relativePath);
|
|
1032
|
+
const source = file(absolutePath);
|
|
1033
|
+
if (!await source.exists()) return {
|
|
1034
|
+
changed: false,
|
|
1035
|
+
relativePath,
|
|
1036
|
+
scanned: false
|
|
1037
|
+
};
|
|
1038
|
+
return compactFileContent({
|
|
1039
|
+
absolutePath,
|
|
1040
|
+
bytes: new Uint8Array(await source.arrayBuffer()),
|
|
1041
|
+
mode,
|
|
1042
|
+
relativePath
|
|
958
1043
|
});
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
const source = file(absolutePath);
|
|
968
|
-
if (!await source.exists()) return {
|
|
969
|
-
changed: false,
|
|
970
|
-
relativePath,
|
|
971
|
-
scanned: false
|
|
972
|
-
};
|
|
973
|
-
const bytes = new Uint8Array(await source.arrayBuffer());
|
|
974
|
-
if (isBinary({ bytes })) return {
|
|
975
|
-
changed: false,
|
|
976
|
-
relativePath,
|
|
977
|
-
scanned: true
|
|
978
|
-
};
|
|
979
|
-
const content = decodeText(bytes);
|
|
980
|
-
const compacted = compactContent({ content });
|
|
981
|
-
if (content === compacted) return {
|
|
982
|
-
changed: false,
|
|
983
|
-
relativePath,
|
|
984
|
-
scanned: true
|
|
985
|
-
};
|
|
986
|
-
if (mode === "fix") await write(absolutePath, compacted);
|
|
987
|
-
return {
|
|
988
|
-
changed: true,
|
|
989
|
-
relativePath,
|
|
990
|
-
scanned: true
|
|
991
|
-
};
|
|
992
|
-
}));
|
|
993
|
-
const changed = [];
|
|
994
|
-
let scanned = 0;
|
|
995
|
-
for (const result of results) {
|
|
996
|
-
if (result.scanned) scanned += 1;
|
|
997
|
-
if (result.changed) changed.push(result.relativePath);
|
|
998
|
-
}
|
|
1044
|
+
};
|
|
1045
|
+
const printCompactCounts = (results, changed) => {
|
|
1046
|
+
const scanned = results.filter((result) => result.scanned).length;
|
|
1047
|
+
process.stdout.write(`[compact] Scanned ${scanned} files\n`);
|
|
1048
|
+
process.stdout.write(`[compact] Updated ${changed.length} files\n`);
|
|
1049
|
+
};
|
|
1050
|
+
const reportCompact = (results, mode, human) => {
|
|
1051
|
+
const changed = results.filter((result) => result.changed).map((result) => result.relativePath);
|
|
999
1052
|
if (mode === "fix") {
|
|
1000
|
-
if (human)
|
|
1001
|
-
process.stdout.write(`[compact] Scanned ${scanned} files\n`);
|
|
1002
|
-
process.stdout.write(`[compact] Updated ${changed.length} files\n`);
|
|
1003
|
-
}
|
|
1053
|
+
if (human) printCompactCounts(results, changed);
|
|
1004
1054
|
return;
|
|
1005
1055
|
}
|
|
1006
1056
|
if (changed.length === 0) return;
|
|
@@ -1011,8 +1061,16 @@ const runCompact = async ({ env, human = false, isIgnored, mode, root }) => {
|
|
|
1011
1061
|
message: `[compact]\nFiles requiring compaction:\n${shown.join("\n")}${suffix}\nRun: lintmax fix`
|
|
1012
1062
|
});
|
|
1013
1063
|
};
|
|
1014
|
-
|
|
1015
|
-
|
|
1064
|
+
const runCompact = async ({ env, human = false, isIgnored, mode, root }) => {
|
|
1065
|
+
const listed = await listCompactFiles({
|
|
1066
|
+
env,
|
|
1067
|
+
root
|
|
1068
|
+
});
|
|
1069
|
+
const files = isIgnored === void 0 ? listed : listed.filter((one) => !isIgnored(one));
|
|
1070
|
+
const results = await Promise.all(files.map(async (relativePath) => compactFile(relativePath, root, mode)));
|
|
1071
|
+
reportCompact(results, mode, human);
|
|
1072
|
+
};
|
|
1073
|
+
// src/extra-coverage.ts
|
|
1016
1074
|
const DOCKERFILE_RE = /(?:^|\/)Dockerfile(?:\.[\w\-.]+)?$/v;
|
|
1017
1075
|
const SHELLCHECK_LINE_RE = /^(?<file>.+?):(?<line>\d+):\d+:\s+(?:error|note|style|warning):\s+(?:\S.*)?\[(?<rule>[^\]\[]+)\]$/v;
|
|
1018
1076
|
const isShell = (filePath) => filePath.endsWith(".sh") || filePath.endsWith(".bash");
|
|
@@ -1027,14 +1085,14 @@ const resolveDprintPluginPath = () => {
|
|
|
1027
1085
|
try {
|
|
1028
1086
|
return import.meta.resolve("@dprint/dockerfile/plugin.wasm").replace("file://", "");
|
|
1029
1087
|
} catch {
|
|
1030
|
-
return
|
|
1088
|
+
return;
|
|
1031
1089
|
}
|
|
1032
1090
|
};
|
|
1033
1091
|
const whichTool = async (env, tool) => {
|
|
1034
1092
|
const result = await $`which ${tool}`.env(env).quiet().nothrow();
|
|
1035
|
-
if (result.exitCode !== 0) return
|
|
1093
|
+
if (result.exitCode !== 0) return;
|
|
1036
1094
|
const path = result.stdout.toString().trim();
|
|
1037
|
-
return path.length > 0 ? path :
|
|
1095
|
+
return path.length > 0 ? path : void 0;
|
|
1038
1096
|
};
|
|
1039
1097
|
const failureDiagnostic = (linter, files) => ({
|
|
1040
1098
|
file: files[0] ?? "",
|
|
@@ -1050,7 +1108,6 @@ const parseShellcheckLine = (line) => {
|
|
|
1050
1108
|
linter: "shellcheck",
|
|
1051
1109
|
rule: groups.rule
|
|
1052
1110
|
};
|
|
1053
|
-
return null;
|
|
1054
1111
|
};
|
|
1055
1112
|
const SHFMT_FLAGS = [
|
|
1056
1113
|
"-s",
|
|
@@ -1105,7 +1162,7 @@ const runShellcheckStep = async ({ bin, env, files }) => {
|
|
|
1105
1162
|
const diagnostics = [];
|
|
1106
1163
|
for (const line of result.stdout.split("\n")) {
|
|
1107
1164
|
const diagnostic = parseShellcheckLine(line);
|
|
1108
|
-
if (diagnostic !==
|
|
1165
|
+
if (diagnostic !== void 0) diagnostics.push(diagnostic);
|
|
1109
1166
|
}
|
|
1110
1167
|
if (result.exitCode !== 0 && diagnostics.length === 0) diagnostics.push(failureDiagnostic("shellcheck", files));
|
|
1111
1168
|
return diagnostics;
|
|
@@ -1118,15 +1175,15 @@ const runShell = async ({ command, env, files }) => {
|
|
|
1118
1175
|
const shellcheck = await whichTool(env, "shellcheck");
|
|
1119
1176
|
const shfmt = await whichTool(env, "shfmt");
|
|
1120
1177
|
const notes = [];
|
|
1121
|
-
if (shellcheck ===
|
|
1178
|
+
if (shellcheck === void 0 || shfmt === void 0) notes.push("shellcheck/shfmt not on PATH — shell files unchecked (install: brew install shellcheck shfmt)");
|
|
1122
1179
|
const diagnostics = [];
|
|
1123
|
-
if (shfmt !==
|
|
1180
|
+
if (shfmt !== void 0) diagnostics.push(...await runShfmtStep({
|
|
1124
1181
|
bin: shfmt,
|
|
1125
1182
|
command,
|
|
1126
1183
|
env,
|
|
1127
1184
|
files
|
|
1128
1185
|
}));
|
|
1129
|
-
if (shellcheck !==
|
|
1186
|
+
if (shellcheck !== void 0) diagnostics.push(...await runShellcheckStep({
|
|
1130
1187
|
bin: shellcheck,
|
|
1131
1188
|
env,
|
|
1132
1189
|
files
|
|
@@ -1173,7 +1230,7 @@ const runTombi = async ({ bin, command, env, files }) => {
|
|
|
1173
1230
|
return [failureDiagnostic("tombi", files)];
|
|
1174
1231
|
};
|
|
1175
1232
|
const runDprintDockerfile = async ({ bin, command, env, files, pluginPath }) => {
|
|
1176
|
-
if (files.length === 0 || pluginPath ===
|
|
1233
|
+
if (files.length === 0 || pluginPath === void 0) return [];
|
|
1177
1234
|
const configArgs = [
|
|
1178
1235
|
"--plugins",
|
|
1179
1236
|
pluginPath,
|
|
@@ -1234,8 +1291,7 @@ const runExtraCoverage = async ({ bins, command, env, gitFiles }) => {
|
|
|
1234
1291
|
notes: shell.notes
|
|
1235
1292
|
};
|
|
1236
1293
|
};
|
|
1237
|
-
|
|
1238
|
-
//#region src/format.ts
|
|
1294
|
+
// src/format.ts
|
|
1239
1295
|
const formatGrouped = ({ files }) => {
|
|
1240
1296
|
if (files.length === 0) return "";
|
|
1241
1297
|
const parts = [];
|
|
@@ -1251,12 +1307,10 @@ const formatGrouped = ({ files }) => {
|
|
|
1251
1307
|
}
|
|
1252
1308
|
return parts.join("\n");
|
|
1253
1309
|
};
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
const
|
|
1258
|
-
const oxlintDisableRe$1 = /oxlint-disable(?:-next-line)?\s+([^\n]*)/gv;
|
|
1259
|
-
const biomeIgnoreRe = /biome-ignore(?:-all)?\s+([\w/]+)/gu;
|
|
1310
|
+
// src/ignores.ts
|
|
1311
|
+
const eslintDisableRe = /eslint-disable(?:-next-line)?\s+(?<rules>[^\n]*)/gv;
|
|
1312
|
+
const oxlintDisableRe$1 = /oxlint-disable(?:-next-line)?\s+(?<rules>[^\n]*)/gv;
|
|
1313
|
+
const biomeIgnoreRe = /biome-ignore(?:-all)?\s+(?<rules>[\w/]+)/gu;
|
|
1260
1314
|
const tsIgnoreRe = /@ts-(?:expect-error|ignore|nocheck)/gv;
|
|
1261
1315
|
const stripRuleTail = (rule) => {
|
|
1262
1316
|
const dash = rule.indexOf("--");
|
|
@@ -1282,13 +1336,13 @@ const DANGEROUS_NON_TEST_PATTERNS = [
|
|
|
1282
1336
|
"no-explicit-any",
|
|
1283
1337
|
"noExplicitAny"
|
|
1284
1338
|
];
|
|
1285
|
-
const isTestFile = (f) => ESLINT_TEST_FILE_PATTERNS.some((p) => new Glob(p)
|
|
1339
|
+
const isTestFile = (f) => ESLINT_TEST_FILE_PATTERNS.some((p) => matchesGlob(new Glob(p), f));
|
|
1286
1340
|
const parseRules = (line, re) => {
|
|
1287
1341
|
const rules = [];
|
|
1288
1342
|
re.lastIndex = 0;
|
|
1289
1343
|
let match = re.exec(line);
|
|
1290
1344
|
while (match) {
|
|
1291
|
-
const raw = match[1];
|
|
1345
|
+
const raw = match.groups?.rules ?? match[1];
|
|
1292
1346
|
if (raw) for (const r of raw.split(",")) {
|
|
1293
1347
|
const trimmed = stripRuleTail(r);
|
|
1294
1348
|
if (trimmed) rules.push(trimmed);
|
|
@@ -1317,7 +1371,7 @@ const rulesFromContent = (content) => {
|
|
|
1317
1371
|
};
|
|
1318
1372
|
const findDangerousSuppressions = async (cwd) => {
|
|
1319
1373
|
const ignoreGlobs = DEFAULT_SHARED_IGNORE_PATTERNS.map((p) => new Glob(p));
|
|
1320
|
-
const files = (await listProjectFiles({ root: cwd })).filter((p) => (p.endsWith(".ts") || p.endsWith(".tsx")) && !p.endsWith(".d.ts") &&
|
|
1374
|
+
const files = (await listProjectFiles({ root: cwd })).filter((p) => (p.endsWith(".ts") || p.endsWith(".tsx")) && !p.endsWith(".d.ts") && ignoreGlobs.every((g) => !matchesGlob(g, p)));
|
|
1321
1375
|
return (await Promise.all(files.map(async (relativePath) => {
|
|
1322
1376
|
const lines = (await file(joinPath(cwd, relativePath)).text()).split("\n");
|
|
1323
1377
|
const findings = [];
|
|
@@ -1331,8 +1385,7 @@ const findDangerousSuppressions = async (cwd) => {
|
|
|
1331
1385
|
return findings;
|
|
1332
1386
|
}))).flat();
|
|
1333
1387
|
};
|
|
1334
|
-
|
|
1335
|
-
//#region src/jsx-extension.ts
|
|
1388
|
+
// src/jsx-extension.ts
|
|
1336
1389
|
const containsJsxNode = (program) => {
|
|
1337
1390
|
let found = false;
|
|
1338
1391
|
const visit = (node) => {
|
|
@@ -1350,9 +1403,9 @@ const containsJsxNode = (program) => {
|
|
|
1350
1403
|
visit(program);
|
|
1351
1404
|
return found;
|
|
1352
1405
|
};
|
|
1353
|
-
const hasJsx = (sourceText) => {
|
|
1354
|
-
if (
|
|
1355
|
-
const asTsx =
|
|
1406
|
+
const hasJsx = async (sourceText) => {
|
|
1407
|
+
if ((await parse("file.ts", sourceText)).errors.length === 0) return false;
|
|
1408
|
+
const asTsx = await parse("file.tsx", sourceText);
|
|
1356
1409
|
return containsJsxNode(asTsx.program);
|
|
1357
1410
|
};
|
|
1358
1411
|
const checkJsxExtension = async ({ root }) => {
|
|
@@ -1361,7 +1414,7 @@ const checkJsxExtension = async ({ root }) => {
|
|
|
1361
1414
|
const paths = (await listProjectFiles({ root })).filter((p) => p.endsWith(".ts") && !isIgnored(p));
|
|
1362
1415
|
return (await Promise.all(paths.map(async (path) => {
|
|
1363
1416
|
const content = await file(`${root}/${path}`).text();
|
|
1364
|
-
if (!hasJsx(content)) return [];
|
|
1417
|
+
if (!await hasJsx(content)) return [];
|
|
1365
1418
|
return [{
|
|
1366
1419
|
file: `${root}/${path}`,
|
|
1367
1420
|
line: 1,
|
|
@@ -1370,15 +1423,13 @@ const checkJsxExtension = async ({ root }) => {
|
|
|
1370
1423
|
}];
|
|
1371
1424
|
}))).flat();
|
|
1372
1425
|
};
|
|
1373
|
-
|
|
1374
|
-
//#region src/unused-suppressions.ts
|
|
1426
|
+
// src/unused-suppressions.ts
|
|
1375
1427
|
/** biome-ignore-all lint/performance/noAwaitInLoops: sequential file io */
|
|
1376
1428
|
/** biome-ignore-all lint/style/noProcessEnv: linter env passthrough */
|
|
1377
1429
|
const oxlintDisableRe = /^(?<prefix>\s*\/\*\s*oxlint-disable\s+)(?<rules>\S(?:[^*]*[^\s*])?)(?<close>\s*\*\/)?$/v;
|
|
1378
1430
|
const oxlintDisablePresentRe = /\/\*\s*oxlint-disable\s/v;
|
|
1379
1431
|
const biomeIgnoreAllRe = /^\s*\/\*\*\s*biome-ignore-all\s+(?<first>[\w\/]+)(?<rest>(?:[^\w\/*][^*]*)?)\*\/\s*$/v;
|
|
1380
1432
|
const biomeIgnoreAllLineRe = /^\s*\/\/\s*biome-ignore-all\s+(?<first>[\w\/]+)(?<rest>(?:[^\w\/].*)?)$/v;
|
|
1381
|
-
/** Both scan for a fixed delimiter, which a regex does by retrying at every start position — super-linear on a long line for a job `indexOf` does in one pass. */
|
|
1382
1433
|
const stripTrailingComment = (str) => {
|
|
1383
1434
|
const at = str.indexOf("--");
|
|
1384
1435
|
return at === -1 ? str : str.slice(0, at).trimEnd();
|
|
@@ -1397,28 +1448,25 @@ const extractJson = (stdout) => {
|
|
|
1397
1448
|
return stdout.slice(start);
|
|
1398
1449
|
};
|
|
1399
1450
|
const absFile = (p) => p.startsWith("/") ? p : joinPath(cwd, p);
|
|
1451
|
+
const buildFileData = (filePath, orig, parseDirectives) => {
|
|
1452
|
+
const lines = orig.split("\n");
|
|
1453
|
+
const directiveLines = parseDirectives(lines);
|
|
1454
|
+
if (directiveLines.length === 0) return;
|
|
1455
|
+
const directiveIndexes = new Set(directiveLines.map((d) => d.index));
|
|
1456
|
+
return {
|
|
1457
|
+
directiveLines,
|
|
1458
|
+
filePath,
|
|
1459
|
+
lines,
|
|
1460
|
+
orig,
|
|
1461
|
+
stripped: lines.filter((_, index) => !directiveIndexes.has(index)).join("\n")
|
|
1462
|
+
};
|
|
1463
|
+
};
|
|
1400
1464
|
const collectFileData = async (files, parseDirectives) => {
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
const lines = orig.split("\n");
|
|
1407
|
-
const directiveLines = parseDirectives(lines);
|
|
1408
|
-
if (directiveLines.length > 0) {
|
|
1409
|
-
const directiveIndexes = new Set(directiveLines.map((d) => d.index));
|
|
1410
|
-
const stripped = lines.filter((_, index) => !directiveIndexes.has(index)).join("\n");
|
|
1411
|
-
out.push({
|
|
1412
|
-
directiveLines,
|
|
1413
|
-
filePath,
|
|
1414
|
-
lines,
|
|
1415
|
-
orig,
|
|
1416
|
-
stripped
|
|
1417
|
-
});
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
return out;
|
|
1465
|
+
return (await Promise.all(files.map(async (filePath) => {
|
|
1466
|
+
const source = file(filePath);
|
|
1467
|
+
if (!await source.exists()) return;
|
|
1468
|
+
return buildFileData(filePath, await source.text(), parseDirectives);
|
|
1469
|
+
}))).filter((result) => result !== void 0);
|
|
1422
1470
|
};
|
|
1423
1471
|
const batchStripRestore = async ({ data, lint }) => {
|
|
1424
1472
|
await Promise.all(data.map(async (d) => write(d.filePath, d.stripped)));
|
|
@@ -1436,13 +1484,6 @@ const rebuildBiomeLine = ({ line, rules }) => {
|
|
|
1436
1484
|
const reason = biomeReasonOf(line) ?? "suppressed";
|
|
1437
1485
|
return `${leadingWhitespaceRe.exec(line)?.[0] ?? ""}/** biome-ignore-all ${rules.join(", ")}: ${reason} */`;
|
|
1438
1486
|
};
|
|
1439
|
-
/**
|
|
1440
|
-
* A lint run that could not ANSWER must refuse, never resolve to an empty fired set. An empty map reads as
|
|
1441
|
-
* `no rule fired anywhere`, which marks EVERY directive in the tree unused — MEASURED on one CI lane, 35 of 35
|
|
1442
|
-
* directives reported while each one was genuinely needed. A clean run is not this shape: both linters emit
|
|
1443
|
-
* `{"diagnostics": []}` and exit 0 when they find nothing, so requiring a parsed diagnostics array refuses a
|
|
1444
|
-
* crash without ever refusing a clean tree.
|
|
1445
|
-
*/
|
|
1446
1487
|
const oxlintUnusedArgs = ({ configPath, files, oxlintBin }) => [
|
|
1447
1488
|
oxlintBin,
|
|
1448
1489
|
"-c",
|
|
@@ -1472,6 +1513,17 @@ const requireLintAnswer = ({ exitCode, label, stderr, stdout }) => {
|
|
|
1472
1513
|
if (exitCode !== 0 && parsed.diagnostics.length === 0) refuse("failed with zero diagnostics");
|
|
1473
1514
|
return json;
|
|
1474
1515
|
};
|
|
1516
|
+
const groupOxlintDiagnostics = (diagnostics) => {
|
|
1517
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
1518
|
+
for (const d of diagnostics) {
|
|
1519
|
+
const key = absFile(d.file);
|
|
1520
|
+
const set = byFile.get(key) ?? /* @__PURE__ */ new Set();
|
|
1521
|
+
set.add(d.rule);
|
|
1522
|
+
for (const v of normalizeRule(d.rule)) set.add(v);
|
|
1523
|
+
byFile.set(key, set);
|
|
1524
|
+
}
|
|
1525
|
+
return byFile;
|
|
1526
|
+
};
|
|
1475
1527
|
const firedOxlintByFile = async ({ configPath, files, oxlintBin }) => {
|
|
1476
1528
|
if (!await file(configPath).exists()) throw new Error(`oxlint-unused: the generated config is absent at ${configPath}, so no rule can fire and every directive would read as unused. The stage that writes it did not run.`);
|
|
1477
1529
|
const result = await runCapture({
|
|
@@ -1490,15 +1542,7 @@ const firedOxlintByFile = async ({ configPath, files, oxlintBin }) => {
|
|
|
1490
1542
|
stderr: result.stderr,
|
|
1491
1543
|
stdout: result.stdout
|
|
1492
1544
|
}) });
|
|
1493
|
-
|
|
1494
|
-
for (const d of diagnostics) {
|
|
1495
|
-
const key = absFile(d.file);
|
|
1496
|
-
const set = byFile.get(key) ?? /* @__PURE__ */ new Set();
|
|
1497
|
-
set.add(d.rule);
|
|
1498
|
-
for (const v of normalizeRule(d.rule)) set.add(v);
|
|
1499
|
-
byFile.set(key, set);
|
|
1500
|
-
}
|
|
1501
|
-
return byFile;
|
|
1545
|
+
return groupOxlintDiagnostics(diagnostics);
|
|
1502
1546
|
};
|
|
1503
1547
|
const isOxlintRuleFired = (rule, fired) => {
|
|
1504
1548
|
if (fired.has(rule)) return true;
|
|
@@ -1557,32 +1601,28 @@ const rebuildOxlintDirectiveLine = ({ directive, filePath, fired, index, line })
|
|
|
1557
1601
|
emitted: []
|
|
1558
1602
|
};
|
|
1559
1603
|
};
|
|
1560
|
-
const
|
|
1561
|
-
const
|
|
1562
|
-
const diagnostics = [];
|
|
1563
|
-
let removed = 0;
|
|
1564
|
-
for (let index = 0; index < data.lines.length; index += 1) {
|
|
1565
|
-
const line = data.lines[index] ?? "";
|
|
1604
|
+
const rebuildFile = async ({ data, dryRun, fired }, rebuildLine) => {
|
|
1605
|
+
const outcomes = data.lines.map((line, index) => {
|
|
1566
1606
|
const directive = data.directiveLines.find((d) => d.index === index);
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
if (removed > 0 && !dryRun) await write(data.filePath, result.join("\n"));
|
|
1607
|
+
return directive ? rebuildLine({
|
|
1608
|
+
directive,
|
|
1609
|
+
filePath: data.filePath,
|
|
1610
|
+
fired,
|
|
1611
|
+
index,
|
|
1612
|
+
line
|
|
1613
|
+
}) : {
|
|
1614
|
+
diagnostics: [],
|
|
1615
|
+
emitted: [line]
|
|
1616
|
+
};
|
|
1617
|
+
});
|
|
1618
|
+
const diagnostics = outcomes.flatMap((outcome) => outcome.diagnostics);
|
|
1619
|
+
if (diagnostics.length > 0 && !dryRun) await write(data.filePath, outcomes.flatMap((outcome) => outcome.emitted).join("\n"));
|
|
1581
1620
|
return {
|
|
1582
1621
|
diagnostics,
|
|
1583
|
-
removed
|
|
1622
|
+
removed: diagnostics.length
|
|
1584
1623
|
};
|
|
1585
1624
|
};
|
|
1625
|
+
const rebuildOxlintFile = async (input) => rebuildFile(input, rebuildOxlintDirectiveLine);
|
|
1586
1626
|
const findOxlintDisableFiles = async (filePaths) => {
|
|
1587
1627
|
const out = [];
|
|
1588
1628
|
for (const fp of filePaths) {
|
|
@@ -1633,13 +1673,15 @@ const firedBiomeByFile = async ({ biomeBin, configDir, files }) => {
|
|
|
1633
1673
|
}
|
|
1634
1674
|
return byFile;
|
|
1635
1675
|
};
|
|
1676
|
+
const matchBiomeDirective = (line) => {
|
|
1677
|
+
biomeIgnoreAllRe.lastIndex = 0;
|
|
1678
|
+
biomeIgnoreAllLineRe.lastIndex = 0;
|
|
1679
|
+
return biomeIgnoreAllRe.exec(line) ?? biomeIgnoreAllLineRe.exec(line);
|
|
1680
|
+
};
|
|
1636
1681
|
const parseBiomeDirectiveLines = (lines) => {
|
|
1637
1682
|
const directiveLines = [];
|
|
1638
1683
|
for (let index = 0; index < lines.length; index += 1) {
|
|
1639
|
-
const
|
|
1640
|
-
biomeIgnoreAllRe.lastIndex = 0;
|
|
1641
|
-
biomeIgnoreAllLineRe.lastIndex = 0;
|
|
1642
|
-
const match = biomeIgnoreAllRe.exec(line) ?? biomeIgnoreAllLineRe.exec(line);
|
|
1684
|
+
const match = matchBiomeDirective(lines[index] ?? "");
|
|
1643
1685
|
if (match) {
|
|
1644
1686
|
const first = match.groups?.first ?? "";
|
|
1645
1687
|
const rest = match.groups?.rest ?? "";
|
|
@@ -1689,51 +1731,24 @@ const rebuildBiomeDirectiveLine = ({ directive, filePath, fired, index, line })
|
|
|
1689
1731
|
emitted: []
|
|
1690
1732
|
};
|
|
1691
1733
|
};
|
|
1692
|
-
const rebuildBiomeFile = async (
|
|
1693
|
-
|
|
1694
|
-
const
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
fired,
|
|
1704
|
-
index,
|
|
1705
|
-
line
|
|
1706
|
-
});
|
|
1707
|
-
removed += outcome.diagnostics.length;
|
|
1708
|
-
diagnostics.push(...outcome.diagnostics);
|
|
1709
|
-
result.push(...outcome.emitted);
|
|
1710
|
-
} else result.push(line);
|
|
1711
|
-
}
|
|
1712
|
-
if (removed > 0 && !dryRun) await write(data.filePath, result.join("\n"));
|
|
1734
|
+
const rebuildBiomeFile = async (input) => rebuildFile(input, rebuildBiomeDirectiveLine);
|
|
1735
|
+
const rebuildBatch = async ({ dryRun, files, firedByFile, rebuild }) => {
|
|
1736
|
+
const outcomes = await Promise.all(files.map(async (data) => ({
|
|
1737
|
+
filePath: data.filePath,
|
|
1738
|
+
outcome: await rebuild({
|
|
1739
|
+
data,
|
|
1740
|
+
dryRun,
|
|
1741
|
+
fired: firedByFile.get(absFile(data.filePath)) ?? /* @__PURE__ */ new Set()
|
|
1742
|
+
})
|
|
1743
|
+
})));
|
|
1744
|
+
const diagnostics = outcomes.flatMap((result) => result.outcome.diagnostics);
|
|
1713
1745
|
return {
|
|
1714
1746
|
diagnostics,
|
|
1715
|
-
removed
|
|
1747
|
+
files: outcomes.filter((result) => result.outcome.removed > 0).map((result) => result.filePath),
|
|
1748
|
+
removed: diagnostics.length
|
|
1716
1749
|
};
|
|
1717
1750
|
};
|
|
1718
|
-
const
|
|
1719
|
-
const targets = filePaths ?? [];
|
|
1720
|
-
if (targets.length === 0) return {
|
|
1721
|
-
diagnostics: [],
|
|
1722
|
-
files: [],
|
|
1723
|
-
removed: 0
|
|
1724
|
-
};
|
|
1725
|
-
const configDir = joinPath(root, cacheDir);
|
|
1726
|
-
const oxlintConfigPath = joinPath(configDir, ".oxlintrc.json");
|
|
1727
|
-
const [oxlintBin, biomeBin] = await Promise.all([resolveBin({
|
|
1728
|
-
bin: "oxlint",
|
|
1729
|
-
pkg: "oxlint"
|
|
1730
|
-
}), resolveBin({
|
|
1731
|
-
bin: "biome",
|
|
1732
|
-
pkg: "@biomejs/biome"
|
|
1733
|
-
})]);
|
|
1734
|
-
const changedFiles = /* @__PURE__ */ new Set();
|
|
1735
|
-
const diagnostics = [];
|
|
1736
|
-
let removed = 0;
|
|
1751
|
+
const removeOxlintSuppressions = async ({ dryRun, oxlintBin, oxlintConfigPath, targets }) => {
|
|
1737
1752
|
const oxlintData = await collectFileData(await findOxlintDisableFiles(targets), parseOxlintDirectiveLines);
|
|
1738
1753
|
if (oxlintData.length > 0) {
|
|
1739
1754
|
const firedByFile = await batchStripRestore({
|
|
@@ -1744,19 +1759,20 @@ const removeUnusedSuppressions = async ({ dryRun = false, filePaths, root }) =>
|
|
|
1744
1759
|
oxlintBin
|
|
1745
1760
|
})
|
|
1746
1761
|
});
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
if (outcome.removed > 0) {
|
|
1754
|
-
removed += outcome.removed;
|
|
1755
|
-
changedFiles.add(data.filePath);
|
|
1756
|
-
}
|
|
1757
|
-
diagnostics.push(...outcome.diagnostics);
|
|
1758
|
-
}
|
|
1762
|
+
return rebuildBatch({
|
|
1763
|
+
dryRun,
|
|
1764
|
+
files: oxlintData,
|
|
1765
|
+
firedByFile,
|
|
1766
|
+
rebuild: rebuildOxlintFile
|
|
1767
|
+
});
|
|
1759
1768
|
}
|
|
1769
|
+
return {
|
|
1770
|
+
diagnostics: [],
|
|
1771
|
+
files: [],
|
|
1772
|
+
removed: 0
|
|
1773
|
+
};
|
|
1774
|
+
};
|
|
1775
|
+
const removeBiomeSuppressions = async ({ biomeBin, configDir, dryRun, targets }) => {
|
|
1760
1776
|
const biomeData = await collectFileData(await findBiomeIgnoreAllFiles(targets), parseBiomeDirectiveLines);
|
|
1761
1777
|
if (biomeData.length > 0) {
|
|
1762
1778
|
const firedByFile = await batchStripRestore({
|
|
@@ -1767,27 +1783,54 @@ const removeUnusedSuppressions = async ({ dryRun = false, filePaths, root }) =>
|
|
|
1767
1783
|
files: biomeData.map((d) => d.filePath)
|
|
1768
1784
|
})
|
|
1769
1785
|
});
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
if (outcome.removed > 0) {
|
|
1777
|
-
removed += outcome.removed;
|
|
1778
|
-
changedFiles.add(data.filePath);
|
|
1779
|
-
}
|
|
1780
|
-
diagnostics.push(...outcome.diagnostics);
|
|
1781
|
-
}
|
|
1786
|
+
return rebuildBatch({
|
|
1787
|
+
dryRun,
|
|
1788
|
+
files: biomeData,
|
|
1789
|
+
firedByFile,
|
|
1790
|
+
rebuild: rebuildBiomeFile
|
|
1791
|
+
});
|
|
1782
1792
|
}
|
|
1783
1793
|
return {
|
|
1784
|
-
diagnostics,
|
|
1785
|
-
files: [
|
|
1786
|
-
removed
|
|
1794
|
+
diagnostics: [],
|
|
1795
|
+
files: [],
|
|
1796
|
+
removed: 0
|
|
1787
1797
|
};
|
|
1788
1798
|
};
|
|
1789
|
-
|
|
1790
|
-
|
|
1799
|
+
const removeUnusedSuppressions = async ({ dryRun = false, filePaths, root }) => {
|
|
1800
|
+
const targets = filePaths ?? [];
|
|
1801
|
+
if (targets.length === 0) return {
|
|
1802
|
+
diagnostics: [],
|
|
1803
|
+
files: [],
|
|
1804
|
+
removed: 0
|
|
1805
|
+
};
|
|
1806
|
+
const configDir = joinPath(root, cacheDir);
|
|
1807
|
+
const oxlintConfigPath = joinPath(configDir, ".oxlintrc.json");
|
|
1808
|
+
const [oxlintBin, biomeBin] = await Promise.all([resolveBin({
|
|
1809
|
+
bin: "oxlint",
|
|
1810
|
+
pkg: "oxlint"
|
|
1811
|
+
}), resolveBin({
|
|
1812
|
+
bin: "biome",
|
|
1813
|
+
pkg: "@biomejs/biome"
|
|
1814
|
+
})]);
|
|
1815
|
+
const oxlint = await removeOxlintSuppressions({
|
|
1816
|
+
dryRun,
|
|
1817
|
+
oxlintBin,
|
|
1818
|
+
oxlintConfigPath,
|
|
1819
|
+
targets
|
|
1820
|
+
});
|
|
1821
|
+
const biome = await removeBiomeSuppressions({
|
|
1822
|
+
biomeBin,
|
|
1823
|
+
configDir,
|
|
1824
|
+
dryRun,
|
|
1825
|
+
targets
|
|
1826
|
+
});
|
|
1827
|
+
return {
|
|
1828
|
+
diagnostics: [...oxlint.diagnostics, ...biome.diagnostics],
|
|
1829
|
+
files: [.../* @__PURE__ */ new Set([...oxlint.files, ...biome.files])],
|
|
1830
|
+
removed: oxlint.removed + biome.removed
|
|
1831
|
+
};
|
|
1832
|
+
};
|
|
1833
|
+
// src/pipeline.ts
|
|
1791
1834
|
/** biome-ignore-all lint/performance/noAwaitInLoops: sequential pipeline fix steps mutate files in order */
|
|
1792
1835
|
const emitExtra = (result) => {
|
|
1793
1836
|
for (const note of result.notes) process.stderr.write(`lintmax: ${note}\n`);
|
|
@@ -2003,7 +2046,8 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
2003
2046
|
silent: true
|
|
2004
2047
|
}
|
|
2005
2048
|
];
|
|
2006
|
-
|
|
2049
|
+
const markdownFiles = prettierMarkdownTargets.filter((p) => p.endsWith(".md"));
|
|
2050
|
+
if (hasFlowmark) for (const target of markdownFiles) steps.push({
|
|
2007
2051
|
args: [
|
|
2008
2052
|
"-w",
|
|
2009
2053
|
"0",
|
|
@@ -2033,43 +2077,78 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
2033
2077
|
return true;
|
|
2034
2078
|
});
|
|
2035
2079
|
};
|
|
2036
|
-
const
|
|
2037
|
-
const
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2080
|
+
const recordEmptyCapture = ({ byteCount, failures, label, result }) => {
|
|
2081
|
+
const stderr = result.stderr.trim();
|
|
2082
|
+
const stdout = result.stdout.trim();
|
|
2083
|
+
const stdoutFirst = stdout.split("\n", 1)[0]?.trimStart() ?? "";
|
|
2084
|
+
const stdoutMessage = stdoutFirst.startsWith("[") || stdoutFirst.startsWith("{") ? void 0 : stdout || void 0;
|
|
2085
|
+
const detail = stderr.length > 0 ? stderr : stdoutMessage;
|
|
2086
|
+
const message = `Output parsed to zero diagnostics (${byteCount} bytes)${detail ? `\n${detail}` : ""}`;
|
|
2087
|
+
failures.push({
|
|
2088
|
+
code: result.exitCode,
|
|
2089
|
+
label,
|
|
2090
|
+
message
|
|
2042
2091
|
});
|
|
2043
|
-
|
|
2092
|
+
};
|
|
2093
|
+
const recordCaptureParseFailure = ({ failures, label, parseError, result }) => {
|
|
2044
2094
|
const byteCount = Buffer.byteLength(result.stdout);
|
|
2045
2095
|
const stderrDetail = result.stderr ? `\n${result.stderr.trim()}` : "";
|
|
2096
|
+
const detail = parseError instanceof Error ? parseError.message : String(parseError);
|
|
2097
|
+
failures.push({
|
|
2098
|
+
code: result.exitCode,
|
|
2099
|
+
label,
|
|
2100
|
+
message: `Output parse error (${byteCount} bytes): ${detail}${stderrDetail}`
|
|
2101
|
+
});
|
|
2102
|
+
};
|
|
2103
|
+
const parseCaptureDiagnostics = ({ failures, label, parser, result }) => {
|
|
2046
2104
|
let diagnostics;
|
|
2047
2105
|
try {
|
|
2048
2106
|
if (label === "eslint" || label === "biome" || label === "oxlint") readRequiredJson(result.stdout);
|
|
2049
2107
|
diagnostics = parser(result);
|
|
2050
2108
|
} catch (parseError) {
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
code: result.exitCode,
|
|
2109
|
+
recordCaptureParseFailure({
|
|
2110
|
+
failures,
|
|
2054
2111
|
label,
|
|
2055
|
-
|
|
2112
|
+
parseError,
|
|
2113
|
+
result
|
|
2056
2114
|
});
|
|
2057
|
-
return
|
|
2115
|
+
return;
|
|
2058
2116
|
}
|
|
2117
|
+
return diagnostics;
|
|
2118
|
+
};
|
|
2119
|
+
const parseCaptureResult = ({ failures, label, parser, result }) => {
|
|
2120
|
+
const byteCount = Buffer.byteLength(result.stdout);
|
|
2121
|
+
const diagnostics = parseCaptureDiagnostics({
|
|
2122
|
+
failures,
|
|
2123
|
+
label,
|
|
2124
|
+
parser,
|
|
2125
|
+
result
|
|
2126
|
+
});
|
|
2127
|
+
if (diagnostics === void 0) return [];
|
|
2059
2128
|
if (diagnostics.length > 0) return diagnostics;
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
const stdoutMessage = stdoutFirst.startsWith("[") || stdoutFirst.startsWith("{") ? void 0 : stdout || void 0;
|
|
2064
|
-
const detail = stderr.length > 0 ? stderr : stdoutMessage;
|
|
2065
|
-
const message = `Output parsed to zero diagnostics (${byteCount} bytes)${detail ? `\n${detail}` : ""}`;
|
|
2066
|
-
failures.push({
|
|
2067
|
-
code: result.exitCode,
|
|
2129
|
+
recordEmptyCapture({
|
|
2130
|
+
byteCount,
|
|
2131
|
+
failures,
|
|
2068
2132
|
label,
|
|
2069
|
-
|
|
2133
|
+
result
|
|
2070
2134
|
});
|
|
2071
2135
|
return [];
|
|
2072
2136
|
};
|
|
2137
|
+
const captureAndParse = async ({ env, failures, label, opts, parser }) => {
|
|
2138
|
+
const result = await runCapture({
|
|
2139
|
+
args: opts.args,
|
|
2140
|
+
command: opts.command,
|
|
2141
|
+
env,
|
|
2142
|
+
label
|
|
2143
|
+
});
|
|
2144
|
+
if (result.exitCode === 0) return [];
|
|
2145
|
+
return parseCaptureResult({
|
|
2146
|
+
failures,
|
|
2147
|
+
label,
|
|
2148
|
+
parser,
|
|
2149
|
+
result
|
|
2150
|
+
});
|
|
2151
|
+
};
|
|
2073
2152
|
const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failures, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson, targets }) => {
|
|
2074
2153
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
2075
2154
|
const allDiagnostics = [];
|
|
@@ -2255,8 +2334,7 @@ const runFixAgent = async (ctx) => {
|
|
|
2255
2334
|
failures: ctx.failures
|
|
2256
2335
|
});
|
|
2257
2336
|
};
|
|
2258
|
-
const
|
|
2259
|
-
await ctx.runSteps({ steps: ctx.checkSteps });
|
|
2337
|
+
const collectHumanCustomDiagnostics = async (ctx) => {
|
|
2260
2338
|
const cnDiagsHuman = await checkClassName({ root: cwd });
|
|
2261
2339
|
const jsxDiagsHuman = await checkJsxExtension({ root: cwd });
|
|
2262
2340
|
const unusedHuman = ctx.sourceFiles.length > 0 ? await removeUnusedSuppressions({
|
|
@@ -2268,7 +2346,7 @@ const runCheckHuman = async (ctx) => {
|
|
|
2268
2346
|
files: [],
|
|
2269
2347
|
removed: 0
|
|
2270
2348
|
};
|
|
2271
|
-
|
|
2349
|
+
return [
|
|
2272
2350
|
...cnDiagsHuman,
|
|
2273
2351
|
...jsxDiagsHuman,
|
|
2274
2352
|
...unusedToDiagnostics({
|
|
@@ -2283,6 +2361,10 @@ const runCheckHuman = async (ctx) => {
|
|
|
2283
2361
|
gitFiles: ctx.allGitFiles
|
|
2284
2362
|
}))
|
|
2285
2363
|
];
|
|
2364
|
+
};
|
|
2365
|
+
const runCheckHuman = async (ctx) => {
|
|
2366
|
+
await ctx.runSteps({ steps: ctx.checkSteps });
|
|
2367
|
+
const humanCustomDiags = await collectHumanCustomDiagnostics(ctx);
|
|
2286
2368
|
if (humanCustomDiags.length > 0) {
|
|
2287
2369
|
const grouped = aggregate({ diagnostics: humanCustomDiags });
|
|
2288
2370
|
const output = formatGrouped({ files: grouped });
|
|
@@ -2313,13 +2395,10 @@ const runCheckAgent = async (ctx) => {
|
|
|
2313
2395
|
env: ctx.env,
|
|
2314
2396
|
gitFiles: ctx.allGitFiles
|
|
2315
2397
|
})));
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
if (ctx.failures.length > 0) process.stderr.write(`${formatFailureDetails(ctx.failures)}\n`);
|
|
2321
|
-
throw new CliExitError({ code: 1 });
|
|
2322
|
-
}
|
|
2398
|
+
throwAgentResults({
|
|
2399
|
+
diagnostics: allDiagnostics,
|
|
2400
|
+
failures: ctx.failures
|
|
2401
|
+
});
|
|
2323
2402
|
};
|
|
2324
2403
|
const buildLintEnv = () => {
|
|
2325
2404
|
const bundledBinA = joinPath(lintmaxRoot, "node_modules", ".bin");
|
|
@@ -2382,7 +2461,7 @@ const runFixCommand = async ({ clearFailures, ctx, fixSteps, human, runStepsSile
|
|
|
2382
2461
|
});
|
|
2383
2462
|
await (human ? runFixHuman(ctx) : runFixAgent(ctx));
|
|
2384
2463
|
};
|
|
2385
|
-
const
|
|
2464
|
+
const prepareLintRuntime = async () => {
|
|
2386
2465
|
const dir = joinPath(cwd, cacheDir);
|
|
2387
2466
|
await ensureDirectory({ directory: dir });
|
|
2388
2467
|
const configPath = joinPath(cwd, "lintmax.config.ts");
|
|
@@ -2394,11 +2473,19 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2394
2473
|
});
|
|
2395
2474
|
const runtime = readRequiredJson(await file(runtimePath).text());
|
|
2396
2475
|
const failures = [];
|
|
2397
|
-
|
|
2476
|
+
return {
|
|
2477
|
+
dir,
|
|
2398
2478
|
env,
|
|
2479
|
+
executor: createStepExecutor({
|
|
2480
|
+
env,
|
|
2481
|
+
failures,
|
|
2482
|
+
root: cwd
|
|
2483
|
+
}),
|
|
2399
2484
|
failures,
|
|
2400
|
-
|
|
2401
|
-
}
|
|
2485
|
+
runtime
|
|
2486
|
+
};
|
|
2487
|
+
};
|
|
2488
|
+
const prepareLintFiles = async ({ command, dir, env, human, runCompactContinue, runtime }) => {
|
|
2402
2489
|
const oxlintIgnorePatternsEarly = await readOxlintIgnorePatterns({ dir });
|
|
2403
2490
|
const ignoreGlobsEarly = oxlintIgnorePatternsEarly.map((p) => new Glob(p));
|
|
2404
2491
|
const isIgnored = (filePath) => ignoreGlobsEarly.some((g) => g.match(filePath));
|
|
@@ -2407,11 +2494,16 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2407
2494
|
isIgnored,
|
|
2408
2495
|
mode: "fix"
|
|
2409
2496
|
});
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2497
|
+
return {
|
|
2498
|
+
allGitFiles: (await listCompactFiles({
|
|
2499
|
+
env,
|
|
2500
|
+
root: cwd
|
|
2501
|
+
})).filter((one) => !isIgnored(one)),
|
|
2502
|
+
isIgnored,
|
|
2503
|
+
oxlintIgnorePatternsEarly
|
|
2504
|
+
};
|
|
2505
|
+
};
|
|
2506
|
+
const prepareLintCommands = async ({ allGitFiles, dir, env, failures, oxlintIgnorePatternsEarly, targets }) => {
|
|
2415
2507
|
const eslintArgs = [
|
|
2416
2508
|
"--config",
|
|
2417
2509
|
joinPath(dir, "eslint.generated.mjs"),
|
|
@@ -2424,61 +2516,75 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2424
2516
|
tombi: tombiBin
|
|
2425
2517
|
};
|
|
2426
2518
|
const hasFlowmark = (await $`which flowmark`.env(env).quiet().nothrow()).exitCode === 0;
|
|
2427
|
-
const
|
|
2428
|
-
const prettierMarkdownTargets = allGitFiles.filter((p) => hasExtension(p, PRETTIER_EXTENSIONS)).map((p) => joinPath(cwd, p));
|
|
2429
|
-
const checkSteps = createCheckSteps({
|
|
2519
|
+
const commandParams = {
|
|
2430
2520
|
biomeBin,
|
|
2431
2521
|
dir,
|
|
2432
2522
|
eslintArgs,
|
|
2433
2523
|
eslintBin,
|
|
2434
2524
|
oxlintBin,
|
|
2435
|
-
oxlintIgnorePatterns,
|
|
2525
|
+
oxlintIgnorePatterns: oxlintIgnorePatternsEarly,
|
|
2436
2526
|
prettierBin,
|
|
2437
|
-
prettierMarkdownTargets,
|
|
2527
|
+
prettierMarkdownTargets: allGitFiles.filter((p) => hasExtension(p, PRETTIER_EXTENSIONS)).map((p) => joinPath(cwd, p)),
|
|
2438
2528
|
sortPkgJson,
|
|
2439
2529
|
targets
|
|
2530
|
+
};
|
|
2531
|
+
const checkSteps = createCheckSteps(commandParams);
|
|
2532
|
+
const fixSteps = createFixSteps({
|
|
2533
|
+
...commandParams,
|
|
2534
|
+
hasFlowmark
|
|
2440
2535
|
});
|
|
2441
|
-
|
|
2442
|
-
const sourceFiles = allGitFiles.filter((f) => !isIgnored(f));
|
|
2443
|
-
const ctx = {
|
|
2536
|
+
return {
|
|
2444
2537
|
agentParams: {
|
|
2445
|
-
|
|
2446
|
-
dir,
|
|
2538
|
+
...commandParams,
|
|
2447
2539
|
env,
|
|
2448
|
-
|
|
2449
|
-
eslintBin,
|
|
2450
|
-
failures,
|
|
2451
|
-
oxlintBin,
|
|
2452
|
-
oxlintIgnorePatterns,
|
|
2453
|
-
prettierBin,
|
|
2454
|
-
prettierMarkdownTargets,
|
|
2455
|
-
sortPkgJson,
|
|
2456
|
-
targets
|
|
2540
|
+
failures
|
|
2457
2541
|
},
|
|
2458
|
-
allGitFiles,
|
|
2459
2542
|
checkSteps,
|
|
2460
|
-
env,
|
|
2461
2543
|
extraBins,
|
|
2544
|
+
fixSteps
|
|
2545
|
+
};
|
|
2546
|
+
};
|
|
2547
|
+
const prepareLintContext = async (command, human) => {
|
|
2548
|
+
const { dir, env, executor, failures, runtime } = await prepareLintRuntime();
|
|
2549
|
+
const { clearFailures, runCompactContinue, runSteps, runStepsSilent, throwIfFailures } = executor;
|
|
2550
|
+
const { allGitFiles, isIgnored, oxlintIgnorePatternsEarly } = await prepareLintFiles({
|
|
2551
|
+
command,
|
|
2552
|
+
dir,
|
|
2553
|
+
env,
|
|
2554
|
+
human,
|
|
2555
|
+
runCompactContinue,
|
|
2556
|
+
runtime
|
|
2557
|
+
});
|
|
2558
|
+
const targets = createLintTargets(allGitFiles);
|
|
2559
|
+
const { agentParams, checkSteps, extraBins, fixSteps } = await prepareLintCommands({
|
|
2560
|
+
allGitFiles,
|
|
2561
|
+
dir,
|
|
2562
|
+
env,
|
|
2462
2563
|
failures,
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2564
|
+
oxlintIgnorePatternsEarly,
|
|
2565
|
+
targets
|
|
2566
|
+
});
|
|
2567
|
+
return {
|
|
2568
|
+
clearFailures,
|
|
2569
|
+
ctx: {
|
|
2570
|
+
agentParams,
|
|
2571
|
+
allGitFiles,
|
|
2572
|
+
checkSteps,
|
|
2573
|
+
env,
|
|
2574
|
+
extraBins,
|
|
2575
|
+
failures,
|
|
2576
|
+
runSteps,
|
|
2577
|
+
shouldComments: runtime.comments !== false,
|
|
2578
|
+
sourceFiles: allGitFiles.filter((f) => !isIgnored(f)),
|
|
2579
|
+
throwIfFailures
|
|
2580
|
+
},
|
|
2581
|
+
fixSteps,
|
|
2582
|
+
runStepsSilent
|
|
2467
2583
|
};
|
|
2584
|
+
};
|
|
2585
|
+
const runLint = async ({ command, human = false }) => {
|
|
2586
|
+
const { clearFailures, ctx, fixSteps, runStepsSilent } = await prepareLintContext(command, human);
|
|
2468
2587
|
if (command === "fix") {
|
|
2469
|
-
const fixSteps = createFixSteps({
|
|
2470
|
-
biomeBin,
|
|
2471
|
-
dir,
|
|
2472
|
-
eslintArgs,
|
|
2473
|
-
eslintBin,
|
|
2474
|
-
hasFlowmark,
|
|
2475
|
-
oxlintBin,
|
|
2476
|
-
oxlintIgnorePatterns,
|
|
2477
|
-
prettierBin,
|
|
2478
|
-
prettierMarkdownTargets,
|
|
2479
|
-
sortPkgJson,
|
|
2480
|
-
targets
|
|
2481
|
-
});
|
|
2482
2588
|
await runFixCommand({
|
|
2483
2589
|
clearFailures,
|
|
2484
2590
|
ctx,
|
|
@@ -2490,8 +2596,7 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2490
2596
|
}
|
|
2491
2597
|
await (human ? runCheckHuman(ctx) : runCheckAgent(ctx));
|
|
2492
2598
|
};
|
|
2493
|
-
|
|
2494
|
-
//#region src/state.ts
|
|
2599
|
+
// src/state.ts
|
|
2495
2600
|
const appDir = "lintmax";
|
|
2496
2601
|
const fileName = "state.json";
|
|
2497
2602
|
const userCacheDir = () => {
|
|
@@ -2546,7 +2651,7 @@ const loadState = async () => {
|
|
|
2546
2651
|
const saveState = async (state) => {
|
|
2547
2652
|
const path = statePath();
|
|
2548
2653
|
try {
|
|
2549
|
-
await write(path, `${JSON.stringify(state,
|
|
2654
|
+
await write(path, `${JSON.stringify(state, void 0, 2)}\n`);
|
|
2550
2655
|
} catch {
|
|
2551
2656
|
process.exitCode ??= 0;
|
|
2552
2657
|
}
|
|
@@ -2571,37 +2676,54 @@ const hashTree = async ({ files, root, version }) => {
|
|
|
2571
2676
|
for (const line of digests) hash.update(line);
|
|
2572
2677
|
return hash.digest("hex");
|
|
2573
2678
|
};
|
|
2574
|
-
|
|
2575
|
-
//#region src/staleness.ts
|
|
2679
|
+
// src/staleness.ts
|
|
2576
2680
|
const httpTimeoutMs = 15e3;
|
|
2577
2681
|
const cacheTtlMs = 864e5;
|
|
2578
2682
|
const sixMonthsMs = 158112e5;
|
|
2579
2683
|
const envSkip = "LINTMAX_SKIP_STALENESS";
|
|
2580
2684
|
const envForce = "LINTMAX_STALENESS_FORCE";
|
|
2581
|
-
/** Every linter this ships, read from the manifest that declares them. A hand-kept list beside the real one watches whatever it happened to name on the day it was written: it held eight of twenty-four, and the dep pinning the whole fleet to an old eslint major sat outside it, stale for well over a year, unseen. */
|
|
2582
2685
|
const trackedPackages = async () => {
|
|
2583
2686
|
const deps = (await readJson({ path: joinPath(lintmaxRoot, "package.json") })).dependencies;
|
|
2584
2687
|
return isRecord(deps) ? Object.keys(deps).toSorted((a, b) => a.localeCompare(b)) : [];
|
|
2585
2688
|
};
|
|
2586
|
-
|
|
2587
|
-
const
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2689
|
+
const readLatestTag = (distTags, name) => {
|
|
2690
|
+
const { latest } = distTags;
|
|
2691
|
+
if (typeof latest !== "string") throw new TypeError(`no latest tag for ${name}`);
|
|
2692
|
+
return latest;
|
|
2693
|
+
};
|
|
2694
|
+
const readPublishTime = (time, latest, name) => {
|
|
2695
|
+
const published = time[latest];
|
|
2696
|
+
if (typeof published !== "string") throw new TypeError(`no publish time for ${name}@${latest}`);
|
|
2697
|
+
return published;
|
|
2698
|
+
};
|
|
2699
|
+
const readPublishTables = (body, name) => {
|
|
2591
2700
|
if (!isRecord(body)) throw new Error(`registry sent no document for ${name}`);
|
|
2592
2701
|
const distTags = body["dist-tags"];
|
|
2593
2702
|
const { time } = body;
|
|
2594
2703
|
if (!isRecord(distTags)) throw new Error(`no dist-tags for ${name}`);
|
|
2595
2704
|
if (!isRecord(time)) throw new Error(`no publish times for ${name} — the abbreviated packument omits them`);
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2705
|
+
return {
|
|
2706
|
+
distTags,
|
|
2707
|
+
time
|
|
2708
|
+
};
|
|
2709
|
+
};
|
|
2710
|
+
const readPublishMetadata = (body, name) => {
|
|
2711
|
+
const { distTags, time } = readPublishTables(body, name);
|
|
2712
|
+
const latest = readLatestTag(distTags, name);
|
|
2713
|
+
return {
|
|
2714
|
+
latest,
|
|
2715
|
+
published: readPublishTime(time, latest, name)
|
|
2716
|
+
};
|
|
2717
|
+
};
|
|
2718
|
+
const fetchLatestPublish = async (name) => {
|
|
2719
|
+
const response = await fetch(`https://registry.npmjs.org/${name}`, { signal: AbortSignal.timeout(httpTimeoutMs) });
|
|
2720
|
+
if (!response.ok) throw new Error(`registry answered ${String(response.status)} for ${name}`);
|
|
2721
|
+
const body = await response.json();
|
|
2722
|
+
const { latest, published } = readPublishMetadata(body, name);
|
|
2600
2723
|
const parsed = Date.parse(published);
|
|
2601
|
-
if (Number.isNaN(parsed)) throw new
|
|
2724
|
+
if (Number.isNaN(parsed)) throw new TypeError(`unparsable publish time for ${name}@${latest}: ${published}`);
|
|
2602
2725
|
return parsed;
|
|
2603
2726
|
};
|
|
2604
|
-
/** Age alone cannot tell a rotting package from a finished one, so a package leaves the gate ONLY with a reason and the trigger that ends the exception — never by being quietly dropped from the tracked set, which reads identically to "fresh" forever. Each entry is re-argued whenever this list is touched: an inherited exception is not a justified one. */
|
|
2605
2727
|
const staleExceptions = {
|
|
2606
2728
|
"@eslint/js": {
|
|
2607
2729
|
reason: "it is the eslint monorepo own co-published config package, republished only when its recommended/all rule map changes; eslint core ships actively (10.8.x within days) while @eslint/js sits at 10.0.1 because that rule map is settled under eslint 10 — the age means finished, not abandoned",
|
|
@@ -2614,12 +2736,16 @@ const staleExceptions = {
|
|
|
2614
2736
|
"eslint-plugin-react": {
|
|
2615
2737
|
reason: "it is the sole dep still pinning eslint to ^9, and replacing it COSTS coverage: of its 83 active rules oxlint re-owns 49 and @eslint-react/perfectionist re-own 5, 20 are obsolete under the new JSX transform or the propTypes era, 7 belong to the formatter, and 6 have no home anywhere — destructuring-assignment, no-invalid-html-attribute, no-adjacent-inline-elements, plus the class-only no-arrow-function-lifecycle, static-property-placement and require-optimization. Strictness is monotonic-up, so the gate carries a stale dep rather than drop six enforced rules",
|
|
2616
2738
|
revisitWhen: "a maintained plugin covers those 6 ids, or every class component is gone (retiring the 3 class-only ones) and the other 3 are re-homed — then drop this dep and take eslint 10"
|
|
2739
|
+
},
|
|
2740
|
+
"eslint-plugin-react-hooks": {
|
|
2741
|
+
reason: "its source in facebook/react under packages/eslint-plugin-react-hooks received commits on 2026-10-14 and its npm record changed on 2026-10-15 through prerelease publishes; stable latest 7.1.1 is older than 6 months because stable releases follow React own release cadence — the age means a slow stable cadence, not abandonment",
|
|
2742
|
+
revisitWhen: "a stable eslint-plugin-react-hooks past 7.1.1 is published, or packages/eslint-plugin-react-hooks in facebook/react stops receiving commits for 6 months"
|
|
2617
2743
|
}
|
|
2618
2744
|
};
|
|
2619
2745
|
const toIssue = (name, publishedAt) => {
|
|
2620
|
-
if (name in staleExceptions) return
|
|
2746
|
+
if (name in staleExceptions) return;
|
|
2621
2747
|
const age = Date.now() - publishedAt;
|
|
2622
|
-
if (age < sixMonthsMs) return
|
|
2748
|
+
if (age < sixMonthsMs) return;
|
|
2623
2749
|
return {
|
|
2624
2750
|
ageDays: Math.floor(age / 864e5),
|
|
2625
2751
|
name
|
|
@@ -2630,12 +2756,12 @@ const scanStaleness = async (force = false) => {
|
|
|
2630
2756
|
const ci = envValue("CI") === "true" || envValue("CI") === "1";
|
|
2631
2757
|
const forced = force || ci || envValue(envForce) === "1";
|
|
2632
2758
|
const state = await loadState();
|
|
2633
|
-
if (!forced && state.lastCheck > 0 && Date.now() - state.lastCheck < cacheTtlMs) return state.staleIssues;
|
|
2759
|
+
if (!forced && state.lastCheck > 0 && Date.now() - state.lastCheck < cacheTtlMs) return state.staleIssues.filter((issue) => !Object.hasOwn(staleExceptions, issue.name));
|
|
2634
2760
|
const names = await trackedPackages();
|
|
2635
2761
|
const issues = (await Promise.all(names.map(async (name) => {
|
|
2636
2762
|
const publishedAt = await fetchLatestPublish(name);
|
|
2637
2763
|
return toIssue(name, publishedAt);
|
|
2638
|
-
}))).filter((issue) => issue !==
|
|
2764
|
+
}))).filter((issue) => issue !== void 0);
|
|
2639
2765
|
await saveState({
|
|
2640
2766
|
...state,
|
|
2641
2767
|
lastCheck: Date.now(),
|
|
@@ -2645,13 +2771,12 @@ const scanStaleness = async (force = false) => {
|
|
|
2645
2771
|
};
|
|
2646
2772
|
const formatStaleness = (issues) => {
|
|
2647
2773
|
if (issues.length === 0) return "";
|
|
2648
|
-
return `lintmax: stale linter deps
|
|
2774
|
+
return `lintmax: stale linter deps — FAILS the gate:\n${issues.map((issue) => ` ${issue.name} latest release ${issue.ageDays}d old (>6mo)`).join("\n")}\nClear by bumping the dependency, or adding a staleExceptions entry with a reason and a revisitWhen trigger.`;
|
|
2649
2775
|
};
|
|
2650
|
-
|
|
2651
|
-
//#region src/gate.ts
|
|
2776
|
+
// src/gate.ts
|
|
2652
2777
|
const envNoCache = "LINTMAX_NO_CACHE";
|
|
2653
2778
|
const computeGreenKey = async (version) => {
|
|
2654
|
-
if (envValue(envNoCache) === "1") return
|
|
2779
|
+
if (envValue(envNoCache) === "1") return;
|
|
2655
2780
|
const files = await listProjectFiles({ root: cwd });
|
|
2656
2781
|
return hashTree({
|
|
2657
2782
|
files,
|
|
@@ -2660,18 +2785,17 @@ const computeGreenKey = async (version) => {
|
|
|
2660
2785
|
});
|
|
2661
2786
|
};
|
|
2662
2787
|
const tryCached = async (greenKey) => {
|
|
2663
|
-
if (greenKey ===
|
|
2788
|
+
if (greenKey === void 0) return false;
|
|
2664
2789
|
if ((await loadState()).lastGreenByCwd[cwd] !== greenKey) return false;
|
|
2665
2790
|
process.stdout.write("ok (cached)\n");
|
|
2666
2791
|
return true;
|
|
2667
2792
|
};
|
|
2668
2793
|
const persistGreen = async (greenKey) => {
|
|
2669
|
-
if (greenKey ===
|
|
2794
|
+
if (greenKey === void 0) return;
|
|
2670
2795
|
const state = await loadState();
|
|
2671
2796
|
state.lastGreenByCwd[cwd] = greenKey;
|
|
2672
2797
|
await saveState(state);
|
|
2673
2798
|
};
|
|
2674
|
-
/** A stale dep FAILS the gate: the baseline is clean, so every finding here is a new one, and a warning nobody has to act on is how the check sat broken for its whole life while printing nothing. A dep leaves the gate through `staleExceptions` with its reason and trigger, never by being tolerated in the output. A scan that cannot reach the registry is reported and does NOT fail — an offline developer is never blocked by it, but the silence that once read as clean is gone. */
|
|
2675
2799
|
const emitStaleness = async () => {
|
|
2676
2800
|
try {
|
|
2677
2801
|
const issues = await scanStaleness();
|
|
@@ -2695,24 +2819,18 @@ const runGate = async ({ command, human, version }) => {
|
|
|
2695
2819
|
});
|
|
2696
2820
|
await persistGreen(await computeGreenKey(version));
|
|
2697
2821
|
await stalePromise;
|
|
2822
|
+
if (process.exitCode !== void 0 && process.exitCode !== 0) return;
|
|
2698
2823
|
process.stdout.write("ok\n");
|
|
2699
2824
|
};
|
|
2700
|
-
|
|
2701
|
-
//#region src/cli.ts
|
|
2825
|
+
// src/cli.ts
|
|
2702
2826
|
const command = process.argv[2];
|
|
2703
|
-
const
|
|
2704
|
-
const
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
const human = process.argv.includes("--human");
|
|
2711
|
-
const rules = await extractAllRules();
|
|
2712
|
-
const output = human ? formatRulesHuman(rules) : formatRulesCompact(rules);
|
|
2713
|
-
process.stdout.write(`${output}\n`);
|
|
2714
|
-
return;
|
|
2715
|
-
}
|
|
2827
|
+
const printRules = async () => {
|
|
2828
|
+
const human = process.argv.includes("--human");
|
|
2829
|
+
const rules = await extractAllRules();
|
|
2830
|
+
const output = human ? formatRulesHuman(rules) : formatRulesCompact(rules);
|
|
2831
|
+
process.stdout.write(`${output}\n`);
|
|
2832
|
+
};
|
|
2833
|
+
const runLintCommand = async (version) => {
|
|
2716
2834
|
if (command !== "fix" && command !== "check") {
|
|
2717
2835
|
usage({ version });
|
|
2718
2836
|
if (command === "--help" || command === "-h") return;
|
|
@@ -2725,6 +2843,15 @@ const main = async () => {
|
|
|
2725
2843
|
version
|
|
2726
2844
|
});
|
|
2727
2845
|
};
|
|
2846
|
+
const main = async () => {
|
|
2847
|
+
const version = await readVersion();
|
|
2848
|
+
if (command === "--version" || command === "-v" || command === "version") {
|
|
2849
|
+
process.stdout.write(`${version}\n`);
|
|
2850
|
+
return;
|
|
2851
|
+
}
|
|
2852
|
+
if (command === "rules") return printRules();
|
|
2853
|
+
await runLintCommand(version);
|
|
2854
|
+
};
|
|
2728
2855
|
try {
|
|
2729
2856
|
await main();
|
|
2730
2857
|
} catch (error) {
|
|
@@ -2733,5 +2860,4 @@ try {
|
|
|
2733
2860
|
process.exitCode = error.code;
|
|
2734
2861
|
} else throw error;
|
|
2735
2862
|
}
|
|
2736
|
-
//#endregion
|
|
2737
2863
|
export {};
|