lintmax 0.1.102 → 0.1.104
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/dist/cli.mjs +159 -160
- package/dist/eslint.mjs +3 -1
- package/dist/index.mjs +1 -2
- package/dist/{path-Dgmf8CJi.mjs → project-files-DudveeQZ.mjs} +181 -1
- package/dist/{src-DlUsR71K.mjs → src-8LKWIKXe.mjs} +64 -120
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { B as OXLINT_CLI_ALLOW, D as isRecord, H as PARSE_DIALECTS, R as DEFAULT_SHARED_IGNORE_PATTERNS, S as joinPath, _ as runCapture, a as cacheDir, b as fromFileUrl, c as ensureDirectory, d as pathExists, f as readJson, g as run, h as resolveBin, i as PRETTIER_MD_ARGS, l as envValue, m as readVersion, n as listProjectFiles, o as cwd, p as readRequiredJson, r as CliExitError, s as decodeText, t as escapeGlobPath, u as lintmaxRoot, v as usage, y as dirnamePath, z as ESLINT_TEST_FILE_PATTERNS } from "./project-files-DudveeQZ.mjs";
|
|
3
|
+
import { r as sync } from "./src-8LKWIKXe.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 { parseSync } from "oxc-parser";
|
|
8
|
+
import { ESLint } from "eslint";
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
9
10
|
import { homedir, platform, tmpdir } from "node:os";
|
|
10
11
|
//#region src/rule-equivalence.ts
|
|
@@ -410,17 +411,8 @@ const checkClassNameFile = async (filePath) => {
|
|
|
410
411
|
}));
|
|
411
412
|
};
|
|
412
413
|
const checkClassName = async ({ root }) => {
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
for await (const path of glob.scan({
|
|
416
|
-
absolute: true,
|
|
417
|
-
cwd: root,
|
|
418
|
-
dot: false
|
|
419
|
-
})) if (!(path.includes("node_modules") || path.includes("readonly") || path.includes(".next") || path.includes("dist"))) {
|
|
420
|
-
const diagnostics = await checkClassNameFile(path);
|
|
421
|
-
allDiagnostics.push(...diagnostics);
|
|
422
|
-
}
|
|
423
|
-
return allDiagnostics;
|
|
414
|
+
const paths = (await listProjectFiles({ root })).filter((path) => isTsxFile(path) && !(path.includes("node_modules") || path.includes("readonly") || path.includes(".next") || path.includes("dist")));
|
|
415
|
+
return (await Promise.all(paths.map(async (path) => checkClassNameFile(joinPath(root, path))))).flat();
|
|
424
416
|
};
|
|
425
417
|
//#endregion
|
|
426
418
|
//#region src/rules.ts
|
|
@@ -543,10 +535,8 @@ const formatRulesHuman = (rules) => {
|
|
|
543
535
|
};
|
|
544
536
|
//#endregion
|
|
545
537
|
//#region src/clean-ignores.ts
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
const eslintLineRe = /^(\s*(?:\/\/|\/\*)\s*eslint-disable(?:-next-line)?\s+)(\S(?:[^*]*[^\s*])?)(\s*\*\/)?$/v;
|
|
549
|
-
const oxlintLineRe = /^(\s*(?:\/\/|\/\*)\s*oxlint-disable(?:-next-line)?\s+)(\S(?:[^*]*[^\s*])?)(\s*\*\/)?$/v;
|
|
538
|
+
const eslintLineRe = /^(?<prefix>\s*(?:\/\/|\/\*)\s*eslint-disable(?:-next-line)?\s+)(?<rules>\S(?:[^*]*[^\s*])?)(?<suffix>\s*\*\/)?$/v;
|
|
539
|
+
const oxlintLineRe = /^(?<prefix>\s*(?:\/\/|\/\*)\s*oxlint-disable(?:-next-line)?\s+)(?<rules>\S(?:[^*]*[^\s*])?)(?<suffix>\s*\*\/)?$/v;
|
|
550
540
|
const biomeLineRe = /^\s*(?:\/\/|\/\*\*)\s*biome-ignore(?:-all)?\s+(?<rule>[\w\/]+)/v;
|
|
551
541
|
const OXLINT_PREFIXES = [
|
|
552
542
|
"eslint",
|
|
@@ -643,10 +633,10 @@ const loadOxlintOffRules = async () => {
|
|
|
643
633
|
}
|
|
644
634
|
return off;
|
|
645
635
|
};
|
|
646
|
-
const buildActiveRuleSet = async () => {
|
|
636
|
+
const buildActiveRuleSet = async ({ excludeEslint = false } = {}) => {
|
|
647
637
|
const rules = await extractAllRules();
|
|
648
638
|
const active = /* @__PURE__ */ new Set();
|
|
649
|
-
for (const r of rules) {
|
|
639
|
+
for (const r of rules.filter((rule) => !excludeEslint || rule.linter !== "eslint")) {
|
|
650
640
|
active.add(r.rule);
|
|
651
641
|
for (const v of normalizeRule(r.rule)) active.add(v);
|
|
652
642
|
}
|
|
@@ -679,9 +669,9 @@ const splitDirective = (str) => {
|
|
|
679
669
|
};
|
|
680
670
|
};
|
|
681
671
|
const processMultiRuleLine = ({ active, isOxlint, line, match, oxlintOff, result }) => {
|
|
682
|
-
const prefix = match
|
|
683
|
-
const rulesStr = match
|
|
684
|
-
const suffix = match
|
|
672
|
+
const prefix = match.prefix ?? "";
|
|
673
|
+
const rulesStr = match.rules ?? "";
|
|
674
|
+
const suffix = match.suffix ?? "";
|
|
685
675
|
const { reason, rules } = splitDirective(rulesStr);
|
|
686
676
|
const kept = rules.filter((r) => isRuleActive(r, active, isOxlint ? oxlintOff : void 0));
|
|
687
677
|
if (kept.length === 0) return rules.length;
|
|
@@ -693,15 +683,19 @@ const processMultiRuleLine = ({ active, isOxlint, line, match, oxlintOff, result
|
|
|
693
683
|
return 0;
|
|
694
684
|
};
|
|
695
685
|
/** Process one source line: keep-or-rewrite it into `result` and return how many disabled rules were removed. */
|
|
696
|
-
const processIgnoreLine = ({ active, line, oxlintOff, result }) => {
|
|
686
|
+
const processIgnoreLine = ({ active, eslintActive, line, oxlintOff, result }) => {
|
|
697
687
|
eslintLineRe.lastIndex = 0;
|
|
698
688
|
oxlintLineRe.lastIndex = 0;
|
|
699
689
|
biomeLineRe.lastIndex = 0;
|
|
700
690
|
const eslintMatch = eslintLineRe.exec(line);
|
|
701
691
|
if (eslintMatch) return processMultiRuleLine({
|
|
702
|
-
active,
|
|
692
|
+
active: eslintActive ?? active,
|
|
703
693
|
line,
|
|
704
|
-
match:
|
|
694
|
+
match: {
|
|
695
|
+
prefix: eslintMatch.groups?.prefix,
|
|
696
|
+
rules: eslintMatch.groups?.rules,
|
|
697
|
+
suffix: eslintMatch.groups?.suffix
|
|
698
|
+
},
|
|
705
699
|
result
|
|
706
700
|
});
|
|
707
701
|
const oxlintMatch = oxlintLineRe.exec(line);
|
|
@@ -709,7 +703,11 @@ const processIgnoreLine = ({ active, line, oxlintOff, result }) => {
|
|
|
709
703
|
active,
|
|
710
704
|
isOxlint: true,
|
|
711
705
|
line,
|
|
712
|
-
match:
|
|
706
|
+
match: {
|
|
707
|
+
prefix: oxlintMatch.groups?.prefix,
|
|
708
|
+
rules: oxlintMatch.groups?.rules,
|
|
709
|
+
suffix: oxlintMatch.groups?.suffix
|
|
710
|
+
},
|
|
713
711
|
oxlintOff,
|
|
714
712
|
result
|
|
715
713
|
});
|
|
@@ -718,7 +716,7 @@ const processIgnoreLine = ({ active, line, oxlintOff, result }) => {
|
|
|
718
716
|
result.push(line);
|
|
719
717
|
return 0;
|
|
720
718
|
};
|
|
721
|
-
const cleanFileIgnores = async (filePath, active, oxlintOff) => {
|
|
719
|
+
const cleanFileIgnores = async (filePath, active, { eslintActive, oxlintOff } = {}) => {
|
|
722
720
|
const f = file(filePath);
|
|
723
721
|
if (!await f.exists()) return 0;
|
|
724
722
|
const lines = (await f.text()).split("\n");
|
|
@@ -726,6 +724,7 @@ const cleanFileIgnores = async (filePath, active, oxlintOff) => {
|
|
|
726
724
|
let removed = 0;
|
|
727
725
|
for (const line of lines) removed += processIgnoreLine({
|
|
728
726
|
active,
|
|
727
|
+
eslintActive,
|
|
729
728
|
line,
|
|
730
729
|
oxlintOff,
|
|
731
730
|
result
|
|
@@ -733,21 +732,42 @@ const cleanFileIgnores = async (filePath, active, oxlintOff) => {
|
|
|
733
732
|
if (removed > 0) await write(filePath, result.join("\n"));
|
|
734
733
|
return removed;
|
|
735
734
|
};
|
|
735
|
+
const buildEslintActiveRuleSet = (config, active) => {
|
|
736
|
+
const eslintActive = new Set(active);
|
|
737
|
+
if (typeof config !== "object" || config === null || !("rules" in config)) return eslintActive;
|
|
738
|
+
const rules = config.rules;
|
|
739
|
+
if (typeof rules !== "object" || rules === null) return eslintActive;
|
|
740
|
+
for (const [rule, value] of Object.entries(rules)) {
|
|
741
|
+
const severity = Array.isArray(value) ? value[0] : value;
|
|
742
|
+
if (severity !== 0 && severity !== "off") for (const variant of normalizeRule(rule)) eslintActive.add(variant);
|
|
743
|
+
}
|
|
744
|
+
return eslintActive;
|
|
745
|
+
};
|
|
746
|
+
const cleanConfiguredFile = async ({ active, eslint, filePath, oxlintOff }) => {
|
|
747
|
+
const config = await eslint.calculateConfigForFile(filePath);
|
|
748
|
+
if (!config) return 0;
|
|
749
|
+
const eslintActive = buildEslintActiveRuleSet(config, active);
|
|
750
|
+
return cleanFileIgnores(filePath, active, {
|
|
751
|
+
eslintActive,
|
|
752
|
+
oxlintOff
|
|
753
|
+
});
|
|
754
|
+
};
|
|
736
755
|
const cleanIgnores = async (filePaths) => {
|
|
737
|
-
const active = await buildActiveRuleSet();
|
|
756
|
+
const active = await buildActiveRuleSet({ excludeEslint: true });
|
|
738
757
|
const oxlintOff = await loadOxlintOffRules();
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
758
|
+
const eslint = new ESLint({
|
|
759
|
+
cwd: process.cwd(),
|
|
760
|
+
overrideConfigFile: joinPath(process.cwd(), cacheDir, "eslint.generated.mjs")
|
|
761
|
+
});
|
|
762
|
+
const counts = await Promise.all(filePaths.map(async (filePath) => cleanConfiguredFile({
|
|
763
|
+
active,
|
|
764
|
+
eslint,
|
|
765
|
+
filePath,
|
|
766
|
+
oxlintOff
|
|
767
|
+
})));
|
|
748
768
|
return {
|
|
749
|
-
cleaned,
|
|
750
|
-
files
|
|
769
|
+
cleaned: counts.reduce((total, count) => total + count, 0),
|
|
770
|
+
files: filePaths.filter((_, index) => (counts[index] ?? 0) > 0)
|
|
751
771
|
};
|
|
752
772
|
};
|
|
753
773
|
//#endregion
|
|
@@ -923,16 +943,10 @@ const isBinary = ({ bytes }) => {
|
|
|
923
943
|
return false;
|
|
924
944
|
};
|
|
925
945
|
const listCompactFiles = async ({ env, root }) => {
|
|
926
|
-
const
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
throw new CliExitError({
|
|
931
|
-
code: result.exitCode,
|
|
932
|
-
message: stderr.length > 0 ? stderr : "Failed to list files for compact step"
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
const entries = result.stdout.toString().split("\0").filter((e) => e.length > 0 && e !== "bun.lock");
|
|
946
|
+
const entries = (await listProjectFiles({
|
|
947
|
+
env,
|
|
948
|
+
root
|
|
949
|
+
})).filter((e) => e !== "bun.lock");
|
|
936
950
|
const symlinkFlags = await Promise.all(entries.map(async (e) => isSymlinkSafe(join(root, e))));
|
|
937
951
|
return entries.filter((_e, index) => !symlinkFlags[index]);
|
|
938
952
|
};
|
|
@@ -1243,7 +1257,6 @@ const eslintDisableRe = /eslint-disable(?:-next-line)?\s+([^\n]*)/gv;
|
|
|
1243
1257
|
const oxlintDisableRe$1 = /oxlint-disable(?:-next-line)?\s+([^\n]*)/gv;
|
|
1244
1258
|
const biomeIgnoreRe = /biome-ignore(?:-all)?\s+([\w/]+)/gu;
|
|
1245
1259
|
const tsIgnoreRe = /@ts-(?:expect-error|ignore|nocheck)/gv;
|
|
1246
|
-
/** Strip a trailing `-- reason` and a trailing block-comment close from one split rule. indexOf is linear where the leading-whitespace regexes backtrack. */
|
|
1247
1260
|
const stripRuleTail = (rule) => {
|
|
1248
1261
|
const dash = rule.indexOf("--");
|
|
1249
1262
|
const noComment = dash === -1 ? rule : rule.slice(0, dash);
|
|
@@ -1251,6 +1264,7 @@ const stripRuleTail = (rule) => {
|
|
|
1251
1264
|
return (close === -1 ? noComment : noComment.slice(0, close)).trim();
|
|
1252
1265
|
};
|
|
1253
1266
|
const tsInlineRe = /@ts-(?:expect-error|ignore|nocheck)/v;
|
|
1267
|
+
const suppressionLineRe = /^\s*(?:\/\/\s*(?:eslint-disable|oxlint-disable|@ts-ignore|@ts-expect-error|@ts-nocheck)|\/\*\s*(?:eslint-disable|oxlint-disable|@ts-nocheck)|\/\*\*\s*biome-ignore)/v;
|
|
1254
1268
|
const DANGEROUS_PATTERNS = [
|
|
1255
1269
|
"no-unsafe-argument",
|
|
1256
1270
|
"no-unsafe-assignment",
|
|
@@ -1282,21 +1296,11 @@ const parseRules = (line, re) => {
|
|
|
1282
1296
|
}
|
|
1283
1297
|
return rules;
|
|
1284
1298
|
};
|
|
1285
|
-
const isDangerousRule = (rule,
|
|
1299
|
+
const isDangerousRule = (rule, filePath) => {
|
|
1286
1300
|
if (DANGEROUS_PATTERNS.some((p) => rule.includes(p))) return true;
|
|
1287
|
-
if (DANGEROUS_NON_TEST_PATTERNS.some((p) => rule.includes(p))) return !isTestFile(
|
|
1301
|
+
if (DANGEROUS_NON_TEST_PATTERNS.some((p) => rule.includes(p))) return !isTestFile(filePath);
|
|
1288
1302
|
return false;
|
|
1289
1303
|
};
|
|
1290
|
-
const parseRipgrepLine = (raw, cwd) => {
|
|
1291
|
-
const firstColon = raw.indexOf(":");
|
|
1292
|
-
const secondColon = raw.indexOf(":", firstColon + 1);
|
|
1293
|
-
if (secondColon <= firstColon) return;
|
|
1294
|
-
return {
|
|
1295
|
-
content: raw.slice(secondColon + 1),
|
|
1296
|
-
file: raw.slice(0, firstColon).replace(`${cwd}/`, ""),
|
|
1297
|
-
lineNum: Number(raw.slice(firstColon + 1, secondColon))
|
|
1298
|
-
};
|
|
1299
|
-
};
|
|
1300
1304
|
const rulesFromContent = (content) => {
|
|
1301
1305
|
const rules = [
|
|
1302
1306
|
...parseRules(content, eslintDisableRe),
|
|
@@ -1311,21 +1315,20 @@ const rulesFromContent = (content) => {
|
|
|
1311
1315
|
return rules;
|
|
1312
1316
|
};
|
|
1313
1317
|
const findDangerousSuppressions = async (cwd) => {
|
|
1314
|
-
const
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
const
|
|
1319
|
-
if (
|
|
1320
|
-
const
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
line: lineNum,
|
|
1318
|
+
const ignoreGlobs = DEFAULT_SHARED_IGNORE_PATTERNS.map((p) => new Glob(p));
|
|
1319
|
+
const files = (await listProjectFiles({ root: cwd })).filter((p) => (p.endsWith(".ts") || p.endsWith(".tsx")) && !p.endsWith(".d.ts") && !ignoreGlobs.some((g) => g.match(p)));
|
|
1320
|
+
return (await Promise.all(files.map(async (relativePath) => {
|
|
1321
|
+
const lines = (await file(joinPath(cwd, relativePath)).text()).split("\n");
|
|
1322
|
+
const findings = [];
|
|
1323
|
+
for (const [index, content] of lines.entries()) if (suppressionLineRe.test(content)) {
|
|
1324
|
+
for (const rule of rulesFromContent(content)) if (isDangerousRule(rule, relativePath)) findings.push({
|
|
1325
|
+
file: relativePath,
|
|
1326
|
+
line: index + 1,
|
|
1324
1327
|
rule
|
|
1325
1328
|
});
|
|
1326
1329
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1330
|
+
return findings;
|
|
1331
|
+
}))).flat();
|
|
1329
1332
|
};
|
|
1330
1333
|
//#endregion
|
|
1331
1334
|
//#region src/jsx-extension.ts
|
|
@@ -1352,24 +1355,19 @@ const hasJsx = (sourceText) => {
|
|
|
1352
1355
|
return containsJsxNode(asTsx.program);
|
|
1353
1356
|
};
|
|
1354
1357
|
const checkJsxExtension = async ({ root }) => {
|
|
1355
|
-
const glob = new Glob("**/*.ts");
|
|
1356
1358
|
const ignoreGlobs = DEFAULT_SHARED_IGNORE_PATTERNS.map((p) => new Glob(p));
|
|
1357
1359
|
const isIgnored = (p) => p.includes("node_modules") || p.endsWith(".d.ts") || ignoreGlobs.some((g) => g.match(p));
|
|
1358
|
-
const
|
|
1359
|
-
|
|
1360
|
-
absolute: false,
|
|
1361
|
-
cwd: root,
|
|
1362
|
-
dot: false
|
|
1363
|
-
})) if (!isIgnored(path)) {
|
|
1360
|
+
const paths = (await listProjectFiles({ root })).filter((p) => p.endsWith(".ts") && !isIgnored(p));
|
|
1361
|
+
return (await Promise.all(paths.map(async (path) => {
|
|
1364
1362
|
const content = await file(`${root}/${path}`).text();
|
|
1365
|
-
if (hasJsx(content))
|
|
1363
|
+
if (!hasJsx(content)) return [];
|
|
1364
|
+
return [{
|
|
1366
1365
|
file: `${root}/${path}`,
|
|
1367
1366
|
line: 1,
|
|
1368
1367
|
linter: "lintmax",
|
|
1369
1368
|
rule: "jsx-requires-tsx-extension"
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
return diagnostics;
|
|
1369
|
+
}];
|
|
1370
|
+
}))).flat();
|
|
1373
1371
|
};
|
|
1374
1372
|
//#endregion
|
|
1375
1373
|
//#region src/unused-suppressions.ts
|
|
@@ -1881,16 +1879,14 @@ const createStepExecutor = ({ env, failures, root }) => {
|
|
|
1881
1879
|
throwIfFailures
|
|
1882
1880
|
};
|
|
1883
1881
|
};
|
|
1884
|
-
const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson }) => {
|
|
1882
|
+
const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson, targets }) => {
|
|
1885
1883
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
1886
1884
|
const steps = [
|
|
1887
1885
|
{
|
|
1888
1886
|
args: [
|
|
1889
1887
|
sortPkgJson,
|
|
1890
1888
|
"--check",
|
|
1891
|
-
|
|
1892
|
-
"--ignore",
|
|
1893
|
-
"**/node_modules/**"
|
|
1889
|
+
...targets.packages
|
|
1894
1890
|
],
|
|
1895
1891
|
label: "sort-package-json"
|
|
1896
1892
|
},
|
|
@@ -1900,7 +1896,8 @@ const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxl
|
|
|
1900
1896
|
"ci",
|
|
1901
1897
|
"--config-path",
|
|
1902
1898
|
dir,
|
|
1903
|
-
"--diagnostic-level=error"
|
|
1899
|
+
"--diagnostic-level=error",
|
|
1900
|
+
...targets.biome
|
|
1904
1901
|
],
|
|
1905
1902
|
label: "biome"
|
|
1906
1903
|
},
|
|
@@ -1911,7 +1908,8 @@ const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxl
|
|
|
1911
1908
|
joinPath(dir, ".oxlintrc.json"),
|
|
1912
1909
|
"--quiet",
|
|
1913
1910
|
"--no-error-on-unmatched-pattern",
|
|
1914
|
-
...oxlintCliAllow
|
|
1911
|
+
...oxlintCliAllow,
|
|
1912
|
+
...targets.source
|
|
1915
1913
|
],
|
|
1916
1914
|
label: "oxlint"
|
|
1917
1915
|
},
|
|
@@ -1934,19 +1932,20 @@ const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxl
|
|
|
1934
1932
|
],
|
|
1935
1933
|
label: "prettier"
|
|
1936
1934
|
});
|
|
1937
|
-
return steps
|
|
1935
|
+
return steps.filter((step) => {
|
|
1936
|
+
if (step.label === "sort-package-json") return targets.packages.length > 0;
|
|
1937
|
+
if (step.label === "biome") return targets.biome.length > 0;
|
|
1938
|
+
if (step.label === "oxlint") return targets.source.length > 0;
|
|
1939
|
+
if (step.label === "eslint") return targets.eslint.length > 0;
|
|
1940
|
+
return true;
|
|
1941
|
+
});
|
|
1938
1942
|
};
|
|
1939
1943
|
const DESTRUCTIVE_FIX_OVERRIDES = ["--rule", "{\"@eslint-react/no-missing-context-display-name\":\"off\"}"];
|
|
1940
|
-
const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson }) => {
|
|
1944
|
+
const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson, targets }) => {
|
|
1941
1945
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
1942
1946
|
const steps = [
|
|
1943
1947
|
{
|
|
1944
|
-
args: [
|
|
1945
|
-
sortPkgJson,
|
|
1946
|
-
"**/package.json",
|
|
1947
|
-
"--ignore",
|
|
1948
|
-
"**/node_modules/**"
|
|
1949
|
-
],
|
|
1948
|
+
args: [sortPkgJson, ...targets.packages],
|
|
1950
1949
|
label: "sort-package-json",
|
|
1951
1950
|
silent: true
|
|
1952
1951
|
},
|
|
@@ -1957,7 +1956,8 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
1957
1956
|
"--config-path",
|
|
1958
1957
|
dir,
|
|
1959
1958
|
"--fix",
|
|
1960
|
-
"--diagnostic-level=error"
|
|
1959
|
+
"--diagnostic-level=error",
|
|
1960
|
+
...targets.biome
|
|
1961
1961
|
],
|
|
1962
1962
|
label: "biome",
|
|
1963
1963
|
silent: true
|
|
@@ -1971,7 +1971,8 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
1971
1971
|
"--fix-suggestions",
|
|
1972
1972
|
"--quiet",
|
|
1973
1973
|
"--no-error-on-unmatched-pattern",
|
|
1974
|
-
...oxlintCliAllow
|
|
1974
|
+
...oxlintCliAllow,
|
|
1975
|
+
...targets.source
|
|
1975
1976
|
],
|
|
1976
1977
|
label: "oxlint",
|
|
1977
1978
|
silent: true
|
|
@@ -1993,18 +1994,19 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
1993
1994
|
"--config-path",
|
|
1994
1995
|
dir,
|
|
1995
1996
|
"--fix",
|
|
1996
|
-
"--diagnostic-level=error"
|
|
1997
|
+
"--diagnostic-level=error",
|
|
1998
|
+
...targets.biome
|
|
1997
1999
|
],
|
|
1998
2000
|
label: "biome",
|
|
1999
2001
|
silent: true
|
|
2000
2002
|
}
|
|
2001
2003
|
];
|
|
2002
|
-
if (hasFlowmark) steps.push({
|
|
2004
|
+
if (hasFlowmark) for (const target of prettierMarkdownTargets.filter((p) => p.endsWith(".md"))) steps.push({
|
|
2003
2005
|
args: [
|
|
2004
2006
|
"-w",
|
|
2005
2007
|
"0",
|
|
2006
2008
|
"--auto",
|
|
2007
|
-
|
|
2009
|
+
target
|
|
2008
2010
|
],
|
|
2009
2011
|
command: "flowmark",
|
|
2010
2012
|
label: "flowmark",
|
|
@@ -2021,7 +2023,13 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
2021
2023
|
label: "prettier",
|
|
2022
2024
|
silent: true
|
|
2023
2025
|
});
|
|
2024
|
-
return steps
|
|
2026
|
+
return steps.filter((step) => {
|
|
2027
|
+
if (step.label === "sort-package-json") return targets.packages.length > 0;
|
|
2028
|
+
if (step.label === "biome") return targets.biome.length > 0;
|
|
2029
|
+
if (step.label === "oxlint") return targets.source.length > 0;
|
|
2030
|
+
if (step.label === "eslint") return targets.eslint.length > 0;
|
|
2031
|
+
return true;
|
|
2032
|
+
});
|
|
2025
2033
|
};
|
|
2026
2034
|
const captureAndParse = async ({ env, failures, label, opts, parser }) => {
|
|
2027
2035
|
const result = await runCapture({
|
|
@@ -2045,13 +2053,13 @@ const captureAndParse = async ({ env, failures, label, opts, parser }) => {
|
|
|
2045
2053
|
});
|
|
2046
2054
|
return [];
|
|
2047
2055
|
};
|
|
2048
|
-
const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failures, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson }) => {
|
|
2056
|
+
const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failures, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson, targets }) => {
|
|
2049
2057
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
2050
2058
|
const allDiagnostics = [];
|
|
2051
2059
|
const push = (d) => {
|
|
2052
2060
|
if (d.length > 0) allDiagnostics.push(...d);
|
|
2053
2061
|
};
|
|
2054
|
-
push(await captureAndParse({
|
|
2062
|
+
if (targets.packages.length > 0) push(await captureAndParse({
|
|
2055
2063
|
env,
|
|
2056
2064
|
failures,
|
|
2057
2065
|
label: "sort-package-json",
|
|
@@ -2059,15 +2067,13 @@ const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failur
|
|
|
2059
2067
|
args: [
|
|
2060
2068
|
sortPkgJson,
|
|
2061
2069
|
"--check",
|
|
2062
|
-
|
|
2063
|
-
"--ignore",
|
|
2064
|
-
"**/node_modules/**"
|
|
2070
|
+
...targets.packages
|
|
2065
2071
|
],
|
|
2066
2072
|
command: "bun"
|
|
2067
2073
|
},
|
|
2068
2074
|
parser: parseSortPackageJsonOutput
|
|
2069
2075
|
}));
|
|
2070
|
-
push(await captureAndParse({
|
|
2076
|
+
if (targets.biome.length > 0) push(await captureAndParse({
|
|
2071
2077
|
env,
|
|
2072
2078
|
failures,
|
|
2073
2079
|
label: "biome",
|
|
@@ -2077,13 +2083,14 @@ const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failur
|
|
|
2077
2083
|
"check",
|
|
2078
2084
|
"--config-path",
|
|
2079
2085
|
dir,
|
|
2080
|
-
"--reporter=json"
|
|
2086
|
+
"--reporter=json",
|
|
2087
|
+
...targets.biome
|
|
2081
2088
|
],
|
|
2082
2089
|
command: "bun"
|
|
2083
2090
|
},
|
|
2084
2091
|
parser: ({ stdout }) => parseBiomeDiagnostics({ stdout })
|
|
2085
2092
|
}));
|
|
2086
|
-
push(await captureAndParse({
|
|
2093
|
+
if (targets.source.length > 0) push(await captureAndParse({
|
|
2087
2094
|
env,
|
|
2088
2095
|
failures,
|
|
2089
2096
|
label: "oxlint",
|
|
@@ -2096,13 +2103,14 @@ const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failur
|
|
|
2096
2103
|
"--no-error-on-unmatched-pattern",
|
|
2097
2104
|
"-f",
|
|
2098
2105
|
"json",
|
|
2099
|
-
...oxlintCliAllow
|
|
2106
|
+
...oxlintCliAllow,
|
|
2107
|
+
...targets.source
|
|
2100
2108
|
],
|
|
2101
2109
|
command: "bun"
|
|
2102
2110
|
},
|
|
2103
2111
|
parser: ({ stdout }) => parseOxlintDiagnostics({ stdout })
|
|
2104
2112
|
}));
|
|
2105
|
-
push(await captureAndParse({
|
|
2113
|
+
if (targets.eslint.length > 0) push(await captureAndParse({
|
|
2106
2114
|
env,
|
|
2107
2115
|
failures,
|
|
2108
2116
|
label: "eslint",
|
|
@@ -2153,30 +2161,28 @@ const dangerousToDiagnostics = (items) => items.map((d) => ({
|
|
|
2153
2161
|
linter: "forbidden-suppression",
|
|
2154
2162
|
rule: d.rule
|
|
2155
2163
|
}));
|
|
2156
|
-
const
|
|
2164
|
+
const SOURCE_EXTENSIONS = [
|
|
2165
|
+
".js",
|
|
2166
|
+
".jsx",
|
|
2167
|
+
".mjs",
|
|
2168
|
+
".cjs",
|
|
2169
|
+
".ts",
|
|
2170
|
+
".tsx",
|
|
2171
|
+
".mts",
|
|
2172
|
+
".cts"
|
|
2173
|
+
];
|
|
2157
2174
|
const PRETTIER_EXTENSIONS = [
|
|
2158
2175
|
".md",
|
|
2159
2176
|
".yml",
|
|
2160
2177
|
".yaml"
|
|
2161
2178
|
];
|
|
2162
|
-
const
|
|
2163
|
-
const
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
dot: false
|
|
2170
|
-
})) if (!(path.includes("node_modules") || isIgnored(path))) found.push(path);
|
|
2171
|
-
return found;
|
|
2172
|
-
};
|
|
2173
|
-
const createPrettierMarkdownTargets = async ({ gitFiles, gitWorkTree, isIgnored, root }) => {
|
|
2174
|
-
if (gitWorkTree) return gitFiles.filter((f) => isPrettierTarget(f) && !isIgnored(f));
|
|
2175
|
-
return await scanPrettierTargets({
|
|
2176
|
-
isIgnored,
|
|
2177
|
-
root
|
|
2178
|
-
});
|
|
2179
|
-
};
|
|
2179
|
+
const hasExtension = (path, extensions) => extensions.some((ext) => path.endsWith(ext));
|
|
2180
|
+
const createLintTargets = (files) => ({
|
|
2181
|
+
biome: files.map((p) => joinPath(cwd, p)),
|
|
2182
|
+
eslint: files.map((p) => joinPath(cwd, p)),
|
|
2183
|
+
packages: files.filter((p) => p === "package.json" || p.endsWith("/package.json")).map((p) => escapeGlobPath(joinPath(cwd, p))),
|
|
2184
|
+
source: files.filter((p) => hasExtension(p, SOURCE_EXTENSIONS)).map((p) => joinPath(cwd, p))
|
|
2185
|
+
});
|
|
2180
2186
|
const throwAgentResults = ({ diagnostics, failures }) => {
|
|
2181
2187
|
if (diagnostics.length === 0 && failures.length === 0) return;
|
|
2182
2188
|
const grouped = aggregate({ diagnostics });
|
|
@@ -2384,28 +2390,25 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2384
2390
|
isIgnored,
|
|
2385
2391
|
mode: "fix"
|
|
2386
2392
|
});
|
|
2387
|
-
const
|
|
2393
|
+
const allGitFiles = (await listCompactFiles({
|
|
2394
|
+
env,
|
|
2395
|
+
root: cwd
|
|
2396
|
+
})).filter((one) => !isIgnored(one));
|
|
2397
|
+
const targets = createLintTargets(allGitFiles);
|
|
2398
|
+
const eslintArgs = [
|
|
2399
|
+
"--config",
|
|
2400
|
+
joinPath(dir, "eslint.generated.mjs"),
|
|
2401
|
+
"--no-warn-ignored",
|
|
2402
|
+
...targets.eslint
|
|
2403
|
+
];
|
|
2388
2404
|
const [sortPkgJson, biomeBin, oxlintBin, eslintBin, prettierBin, tombiBin, dprintBin] = await resolveAllBins();
|
|
2389
2405
|
const extraBins = {
|
|
2390
2406
|
dprint: dprintBin,
|
|
2391
2407
|
tombi: tombiBin
|
|
2392
2408
|
};
|
|
2393
2409
|
const hasFlowmark = (await $`which flowmark`.env(env).quiet().nothrow()).exitCode === 0;
|
|
2394
|
-
const gitWorkTree = await isGitWorkTree({
|
|
2395
|
-
env,
|
|
2396
|
-
root: cwd
|
|
2397
|
-
});
|
|
2398
|
-
const allGitFiles = (gitWorkTree ? await listCompactFiles({
|
|
2399
|
-
env,
|
|
2400
|
-
root: cwd
|
|
2401
|
-
}) : []).filter((one) => !isIgnored(one));
|
|
2402
2410
|
const oxlintIgnorePatterns = oxlintIgnorePatternsEarly;
|
|
2403
|
-
const prettierMarkdownTargets =
|
|
2404
|
-
gitFiles: allGitFiles,
|
|
2405
|
-
gitWorkTree,
|
|
2406
|
-
isIgnored,
|
|
2407
|
-
root: cwd
|
|
2408
|
-
});
|
|
2411
|
+
const prettierMarkdownTargets = allGitFiles.filter((p) => hasExtension(p, PRETTIER_EXTENSIONS)).map((p) => joinPath(cwd, p));
|
|
2409
2412
|
const checkSteps = createCheckSteps({
|
|
2410
2413
|
biomeBin,
|
|
2411
2414
|
dir,
|
|
@@ -2415,7 +2418,8 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2415
2418
|
oxlintIgnorePatterns,
|
|
2416
2419
|
prettierBin,
|
|
2417
2420
|
prettierMarkdownTargets,
|
|
2418
|
-
sortPkgJson
|
|
2421
|
+
sortPkgJson,
|
|
2422
|
+
targets
|
|
2419
2423
|
});
|
|
2420
2424
|
const shouldComments = runtime.comments !== false;
|
|
2421
2425
|
const sourceFiles = allGitFiles.filter((f) => !isIgnored(f));
|
|
@@ -2431,7 +2435,8 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2431
2435
|
oxlintIgnorePatterns,
|
|
2432
2436
|
prettierBin,
|
|
2433
2437
|
prettierMarkdownTargets,
|
|
2434
|
-
sortPkgJson
|
|
2438
|
+
sortPkgJson,
|
|
2439
|
+
targets
|
|
2435
2440
|
},
|
|
2436
2441
|
allGitFiles,
|
|
2437
2442
|
checkSteps,
|
|
@@ -2454,7 +2459,8 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2454
2459
|
oxlintIgnorePatterns,
|
|
2455
2460
|
prettierBin,
|
|
2456
2461
|
prettierMarkdownTargets,
|
|
2457
|
-
sortPkgJson
|
|
2462
|
+
sortPkgJson,
|
|
2463
|
+
targets
|
|
2458
2464
|
});
|
|
2459
2465
|
await runFixCommand({
|
|
2460
2466
|
clearFailures,
|
|
@@ -2627,16 +2633,9 @@ const formatStaleness = (issues) => {
|
|
|
2627
2633
|
//#endregion
|
|
2628
2634
|
//#region src/gate.ts
|
|
2629
2635
|
const envNoCache = "LINTMAX_NO_CACHE";
|
|
2630
|
-
const listTrackedFiles = async () => {
|
|
2631
|
-
if ((await $`git -C ${cwd} rev-parse --is-inside-work-tree`.env(bunEnv).quiet().nothrow()).exitCode !== 0) return null;
|
|
2632
|
-
const result = await $`git -C ${cwd} ls-files -z --cached --others --exclude-standard`.env(bunEnv).quiet().nothrow();
|
|
2633
|
-
if (result.exitCode !== 0) return null;
|
|
2634
|
-
return result.stdout.toString().split("\0").filter((entry) => entry.length > 0);
|
|
2635
|
-
};
|
|
2636
2636
|
const computeGreenKey = async (version) => {
|
|
2637
2637
|
if (envValue(envNoCache) === "1") return null;
|
|
2638
|
-
const files = await
|
|
2639
|
-
if (files === null) return null;
|
|
2638
|
+
const files = await listProjectFiles({ root: cwd });
|
|
2640
2639
|
return hashTree({
|
|
2641
2640
|
files,
|
|
2642
2641
|
root: cwd,
|
package/dist/eslint.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as normalizePathListInput, D as isRecord, E as findUnknownRules, M as normalizeTailwindOption, P as warnToError, R as DEFAULT_SHARED_IGNORE_PATTERNS, S as joinPath, U as SHARED_OVERRIDE_SYMBOL_KEY, W as TAILWIND_ENTRY_CANDIDATES, j as normalizeRulesOffInput, k as normalizeObjectListInput, n as listProjectFiles, x as isAbsolutePath, z as ESLINT_TEST_FILE_PATTERNS } from "./project-files-DudveeQZ.mjs";
|
|
2
2
|
import { file } from "bun";
|
|
3
3
|
import eslintReact from "@eslint-react/eslint-plugin";
|
|
4
4
|
import { includeIgnoreFile } from "@eslint/compat";
|
|
@@ -95,7 +95,9 @@ const resolveTailwindEntry = async ({ root, tailwind }) => {
|
|
|
95
95
|
const tailwindSetting = tailwind ?? true;
|
|
96
96
|
if (tailwindSetting === false) return;
|
|
97
97
|
if (typeof tailwindSetting === "string") return isAbsolutePath(tailwindSetting) ? tailwindSetting : joinPath(root, tailwindSetting);
|
|
98
|
+
const projectFiles = new Set(await listProjectFiles({ root }));
|
|
98
99
|
const matches = (await Promise.all(TAILWIND_ENTRY_CANDIDATES.map(async (candidate) => {
|
|
100
|
+
if (!projectFiles.has(candidate)) return [];
|
|
99
101
|
const resolved = joinPath(root, candidate);
|
|
100
102
|
return await file(resolved).exists() ? [resolved] : [];
|
|
101
103
|
}))).flat();
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { defineConfig, eslintImport, sync };
|
|
1
|
+
export { t as defineConfig, n as eslintImport, r as sync } from "./src-8LKWIKXe.mjs";
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { $, Glob, env, env as bunEnv, file, spawn } from "bun";
|
|
2
|
+
import { lstat, realpath } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
1
4
|
//#region src/constants.ts
|
|
2
5
|
const BIOME_RULES_OFF = [
|
|
3
6
|
"noBarrelFile",
|
|
@@ -352,4 +355,181 @@ const isAbsolutePath = (value) => {
|
|
|
352
355
|
return normalized.startsWith("/") || DRIVE_PATH_REGEX.test(normalized);
|
|
353
356
|
};
|
|
354
357
|
//#endregion
|
|
355
|
-
|
|
358
|
+
//#region src/core.ts
|
|
359
|
+
var CliExitError = class extends Error {
|
|
360
|
+
code;
|
|
361
|
+
name = "CliExitError";
|
|
362
|
+
constructor({ code, message }) {
|
|
363
|
+
super(message ?? "");
|
|
364
|
+
this.code = code;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
const decoder = new TextDecoder();
|
|
368
|
+
const cacheDir = "node_modules/.cache/lintmax";
|
|
369
|
+
const cwd = process.cwd();
|
|
370
|
+
const lintmaxRoot = dirnamePath(dirnamePath(fromFileUrl(import.meta.url)));
|
|
371
|
+
const PRETTIER_MD_ARGS = [
|
|
372
|
+
"--single-quote",
|
|
373
|
+
"--no-semi",
|
|
374
|
+
"--trailing-comma",
|
|
375
|
+
"none",
|
|
376
|
+
"--print-width",
|
|
377
|
+
"80",
|
|
378
|
+
"--arrow-parens",
|
|
379
|
+
"avoid",
|
|
380
|
+
"--tab-width",
|
|
381
|
+
"2",
|
|
382
|
+
"--prose-wrap",
|
|
383
|
+
"preserve"
|
|
384
|
+
];
|
|
385
|
+
const parseJsonObject = ({ text }) => {
|
|
386
|
+
const parsed = JSON.parse(text);
|
|
387
|
+
return isRecord(parsed) ? parsed : {};
|
|
388
|
+
};
|
|
389
|
+
const decodeText = (bytes) => decoder.decode(bytes ?? /* @__PURE__ */ new Uint8Array());
|
|
390
|
+
const pathExists = async ({ path }) => file(path).exists();
|
|
391
|
+
const readJson = async ({ path }) => {
|
|
392
|
+
if (!await pathExists({ path })) return {};
|
|
393
|
+
try {
|
|
394
|
+
const text = await file(path).text();
|
|
395
|
+
return parseJsonObject({ text });
|
|
396
|
+
} catch {
|
|
397
|
+
return {};
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
const readRequiredJson = (text) => JSON.parse(text);
|
|
401
|
+
const ensureDirectory = async ({ directory }) => {
|
|
402
|
+
const result = await $`mkdir -p ${directory}`.quiet().nothrow();
|
|
403
|
+
if (result.exitCode === 0) return;
|
|
404
|
+
const stderr = result.stderr.toString().trim();
|
|
405
|
+
throw new CliExitError({
|
|
406
|
+
code: result.exitCode,
|
|
407
|
+
message: stderr.length > 0 ? stderr : `Failed to create directory: ${directory}`
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
const resolvePackageJsonPath = async ({ pkg }) => {
|
|
411
|
+
try {
|
|
412
|
+
return fromFileUrl(import.meta.resolve(`${pkg}/package.json`));
|
|
413
|
+
} catch {
|
|
414
|
+
const consumerCandidate = joinPath(cwd, "node_modules", pkg, "package.json");
|
|
415
|
+
if (await pathExists({ path: consumerCandidate })) return consumerCandidate;
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
const resolveBin = async ({ bin, pkg }) => {
|
|
420
|
+
const packageJsonPath = await resolvePackageJsonPath({ pkg });
|
|
421
|
+
if (!packageJsonPath) throw new CliExitError({
|
|
422
|
+
code: 1,
|
|
423
|
+
message: `Cannot find ${pkg} — run: bun add -d ${pkg}`
|
|
424
|
+
});
|
|
425
|
+
const pkgJson = readRequiredJson(await file(packageJsonPath).text());
|
|
426
|
+
const pkgDir = dirnamePath(packageJsonPath);
|
|
427
|
+
const binPath = typeof pkgJson.bin === "string" ? pkgJson.bin : pkgJson.bin?.[bin] ?? "";
|
|
428
|
+
return joinPath(pkgDir, binPath);
|
|
429
|
+
};
|
|
430
|
+
const run = async ({ args, command, env, label, silent = false }) => {
|
|
431
|
+
const base = $`${command} ${args}`.cwd(cwd).env(env).nothrow();
|
|
432
|
+
const result = await (silent ? base.quiet() : base);
|
|
433
|
+
if (result.exitCode === 0) return;
|
|
434
|
+
if (silent) {
|
|
435
|
+
process.stderr.write(`[${label}]\n`);
|
|
436
|
+
const stdout = result.stdout.toString();
|
|
437
|
+
if (stdout.length > 0) process.stderr.write(stdout);
|
|
438
|
+
const stderr = result.stderr.toString();
|
|
439
|
+
if (stderr.length > 0) process.stderr.write(stderr);
|
|
440
|
+
}
|
|
441
|
+
throw new CliExitError({ code: result.exitCode });
|
|
442
|
+
};
|
|
443
|
+
const runCapture = async ({ args, command, env }) => {
|
|
444
|
+
const result = await $`${command} ${args}`.cwd(cwd).env(env).quiet().nothrow();
|
|
445
|
+
return {
|
|
446
|
+
exitCode: result.exitCode,
|
|
447
|
+
stderr: result.stderr.toString(),
|
|
448
|
+
stdout: result.stdout.toString()
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
const envValue = (name) => bunEnv[name] ?? "";
|
|
452
|
+
const readVersion = async () => {
|
|
453
|
+
return readRequiredJson(await file(joinPath(lintmaxRoot, "package.json")).text()).version;
|
|
454
|
+
};
|
|
455
|
+
const usage = ({ version }) => {
|
|
456
|
+
process.stdout.write(`lintmax v${version}\n\n`);
|
|
457
|
+
process.stdout.write("Usage: lintmax <command>\n\n");
|
|
458
|
+
process.stdout.write("Commands:\n");
|
|
459
|
+
process.stdout.write(" fix Format, auto-fix, and gate all files (default)\n");
|
|
460
|
+
process.stdout.write(" check Verify all files without modifying (CI)\n");
|
|
461
|
+
process.stdout.write(" rules List all enabled rules\n");
|
|
462
|
+
process.stdout.write(" version Show version\n");
|
|
463
|
+
};
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/project-files.ts
|
|
466
|
+
const fixedIgnoreGlobs = ["**/node_modules/**", ...DEFAULT_SHARED_IGNORE_PATTERNS].map((pattern) => new Glob(pattern));
|
|
467
|
+
const isIncludedProjectFile = (path) => !fixedIgnoreGlobs.some((glob) => glob.match(path));
|
|
468
|
+
const hasGitDirectory = async (directory) => {
|
|
469
|
+
try {
|
|
470
|
+
await lstat(join(directory, ".git"));
|
|
471
|
+
return true;
|
|
472
|
+
} catch (error) {
|
|
473
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
|
|
474
|
+
}
|
|
475
|
+
const parent = dirname(directory);
|
|
476
|
+
return parent === directory ? false : hasGitDirectory(parent);
|
|
477
|
+
};
|
|
478
|
+
const escapeGlobPath = (path) => Array.from(path, (character) => String.raw`\*?()[]{}!+@|`.includes(character) ? `\\${character}` : character).join("");
|
|
479
|
+
const listVersionControlFiles = async ({ env: env$1 = env, root }) => {
|
|
480
|
+
if (!await hasGitDirectory(await realpath(resolve(root)))) return null;
|
|
481
|
+
const subprocess = spawn({
|
|
482
|
+
cmd: [
|
|
483
|
+
"git",
|
|
484
|
+
"-C",
|
|
485
|
+
root,
|
|
486
|
+
"ls-files",
|
|
487
|
+
"-z",
|
|
488
|
+
"--cached",
|
|
489
|
+
"--others",
|
|
490
|
+
"--exclude-standard"
|
|
491
|
+
],
|
|
492
|
+
env: env$1,
|
|
493
|
+
stderr: "pipe",
|
|
494
|
+
stdout: "pipe",
|
|
495
|
+
timeout: 3e4
|
|
496
|
+
});
|
|
497
|
+
const [exitCode, stdout, stderr] = await Promise.all([
|
|
498
|
+
subprocess.exited,
|
|
499
|
+
new Response(subprocess.stdout).text(),
|
|
500
|
+
new Response(subprocess.stderr).text()
|
|
501
|
+
]);
|
|
502
|
+
if (exitCode !== 0) throw new CliExitError({
|
|
503
|
+
code: exitCode,
|
|
504
|
+
message: `Failed to list version-control files: ${stderr.trim()}`
|
|
505
|
+
});
|
|
506
|
+
return stdout.split("\0").filter((entry) => entry.length > 0);
|
|
507
|
+
};
|
|
508
|
+
const listProjectFiles = async ({ env, root }) => {
|
|
509
|
+
const entries = await listVersionControlFiles({
|
|
510
|
+
env,
|
|
511
|
+
root
|
|
512
|
+
});
|
|
513
|
+
if (entries !== null) {
|
|
514
|
+
const present = await Promise.all(entries.map(async (entry) => {
|
|
515
|
+
try {
|
|
516
|
+
const stats = await lstat(join(root, entry));
|
|
517
|
+
return stats.isFile() || stats.isSymbolicLink();
|
|
518
|
+
} catch (error) {
|
|
519
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") return false;
|
|
520
|
+
throw error;
|
|
521
|
+
}
|
|
522
|
+
}));
|
|
523
|
+
return entries.filter((_entry, index) => present[index]).filter(isIncludedProjectFile);
|
|
524
|
+
}
|
|
525
|
+
const files = [];
|
|
526
|
+
for await (const path of new Glob("**/*").scan({
|
|
527
|
+
cwd: root,
|
|
528
|
+
dot: true,
|
|
529
|
+
followSymlinks: false,
|
|
530
|
+
onlyFiles: true
|
|
531
|
+
})) files.push(path);
|
|
532
|
+
return files.filter(isIncludedProjectFile);
|
|
533
|
+
};
|
|
534
|
+
//#endregion
|
|
535
|
+
export { normalizePathListInput as A, OXLINT_CLI_ALLOW as B, assertJsonSerializable as C, isRecord as D, findUnknownRules as E, BIOME_IGNORE_PATTERNS as F, PARSE_DIALECTS as H, BIOME_PATTERN_RULE_OVERRIDES as I, BIOME_RULES_OFF as L, normalizeTailwindOption as M, stripPluginNamespace as N, normalizeIgnorePattern as O, warnToError as P, DEFAULT_SHARED_IGNORE_PATTERNS as R, joinPath as S, assertOptionalString as T, SHARED_OVERRIDE_SYMBOL_KEY as U, OXLINT_PATTERN_RULE_OVERRIDES as V, TAILWIND_ENTRY_CANDIDATES as W, runCapture as _, cacheDir as a, fromFileUrl as b, ensureDirectory as c, pathExists as d, readJson as f, run as g, resolveBin as h, PRETTIER_MD_ARGS as i, normalizeRulesOffInput as j, normalizeObjectListInput as k, envValue as l, readVersion as m, listProjectFiles as n, cwd as o, readRequiredJson as p, CliExitError as r, decodeText as s, escapeGlobPath as t, lintmaxRoot as u, usage as v, assertObject as w, isAbsolutePath as x, dirnamePath as y, ESLINT_TEST_FILE_PATTERNS as z };
|
|
@@ -1,114 +1,7 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import {
|
|
1
|
+
import { A as normalizePathListInput, C as assertJsonSerializable, E as findUnknownRules, F as BIOME_IGNORE_PATTERNS, I as BIOME_PATTERN_RULE_OVERRIDES, L as BIOME_RULES_OFF, M as normalizeTailwindOption, N as stripPluginNamespace, O as normalizeIgnorePattern, R as DEFAULT_SHARED_IGNORE_PATTERNS, S as joinPath, T as assertOptionalString, U as SHARED_OVERRIDE_SYMBOL_KEY, V as OXLINT_PATTERN_RULE_OVERRIDES, a as cacheDir, b as fromFileUrl, c as ensureDirectory, j as normalizeRulesOffInput, k as normalizeObjectListInput, n as listProjectFiles, p as readRequiredJson, w as assertObject, y as dirnamePath } from "./project-files-DudveeQZ.mjs";
|
|
2
|
+
import { file, write } from "bun";
|
|
3
3
|
import { lstat } from "node:fs/promises";
|
|
4
4
|
import { join, relative } from "node:path";
|
|
5
|
-
//#region src/core.ts
|
|
6
|
-
var CliExitError = class extends Error {
|
|
7
|
-
code;
|
|
8
|
-
name = "CliExitError";
|
|
9
|
-
constructor({ code, message }) {
|
|
10
|
-
super(message ?? "");
|
|
11
|
-
this.code = code;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const decoder = new TextDecoder();
|
|
15
|
-
const cacheDir = "node_modules/.cache/lintmax";
|
|
16
|
-
const cwd = process.cwd();
|
|
17
|
-
const lintmaxRoot = dirnamePath(dirnamePath(fromFileUrl(import.meta.url)));
|
|
18
|
-
const PRETTIER_MD_ARGS = [
|
|
19
|
-
"--single-quote",
|
|
20
|
-
"--no-semi",
|
|
21
|
-
"--trailing-comma",
|
|
22
|
-
"none",
|
|
23
|
-
"--print-width",
|
|
24
|
-
"80",
|
|
25
|
-
"--arrow-parens",
|
|
26
|
-
"avoid",
|
|
27
|
-
"--tab-width",
|
|
28
|
-
"2",
|
|
29
|
-
"--prose-wrap",
|
|
30
|
-
"preserve"
|
|
31
|
-
];
|
|
32
|
-
const parseJsonObject = ({ text }) => {
|
|
33
|
-
const parsed = JSON.parse(text);
|
|
34
|
-
return isRecord(parsed) ? parsed : {};
|
|
35
|
-
};
|
|
36
|
-
const decodeText = (bytes) => decoder.decode(bytes ?? /* @__PURE__ */ new Uint8Array());
|
|
37
|
-
const pathExists = async ({ path }) => file(path).exists();
|
|
38
|
-
const readJson = async ({ path }) => {
|
|
39
|
-
if (!await pathExists({ path })) return {};
|
|
40
|
-
try {
|
|
41
|
-
const text = await file(path).text();
|
|
42
|
-
return parseJsonObject({ text });
|
|
43
|
-
} catch {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const readRequiredJson = (text) => JSON.parse(text);
|
|
48
|
-
const ensureDirectory = async ({ directory }) => {
|
|
49
|
-
const result = await $`mkdir -p ${directory}`.quiet().nothrow();
|
|
50
|
-
if (result.exitCode === 0) return;
|
|
51
|
-
const stderr = result.stderr.toString().trim();
|
|
52
|
-
throw new CliExitError({
|
|
53
|
-
code: result.exitCode,
|
|
54
|
-
message: stderr.length > 0 ? stderr : `Failed to create directory: ${directory}`
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
const resolvePackageJsonPath = async ({ pkg }) => {
|
|
58
|
-
try {
|
|
59
|
-
return fromFileUrl(import.meta.resolve(`${pkg}/package.json`));
|
|
60
|
-
} catch {
|
|
61
|
-
const consumerCandidate = joinPath(cwd, "node_modules", pkg, "package.json");
|
|
62
|
-
if (await pathExists({ path: consumerCandidate })) return consumerCandidate;
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const resolveBin = async ({ bin, pkg }) => {
|
|
67
|
-
const packageJsonPath = await resolvePackageJsonPath({ pkg });
|
|
68
|
-
if (!packageJsonPath) throw new CliExitError({
|
|
69
|
-
code: 1,
|
|
70
|
-
message: `Cannot find ${pkg} — run: bun add -d ${pkg}`
|
|
71
|
-
});
|
|
72
|
-
const pkgJson = readRequiredJson(await file(packageJsonPath).text());
|
|
73
|
-
const pkgDir = dirnamePath(packageJsonPath);
|
|
74
|
-
const binPath = typeof pkgJson.bin === "string" ? pkgJson.bin : pkgJson.bin?.[bin] ?? "";
|
|
75
|
-
return joinPath(pkgDir, binPath);
|
|
76
|
-
};
|
|
77
|
-
const run = async ({ args, command, env, label, silent = false }) => {
|
|
78
|
-
const base = $`${command} ${args}`.cwd(cwd).env(env).nothrow();
|
|
79
|
-
const result = await (silent ? base.quiet() : base);
|
|
80
|
-
if (result.exitCode === 0) return;
|
|
81
|
-
if (silent) {
|
|
82
|
-
process.stderr.write(`[${label}]\n`);
|
|
83
|
-
const stdout = result.stdout.toString();
|
|
84
|
-
if (stdout.length > 0) process.stderr.write(stdout);
|
|
85
|
-
const stderr = result.stderr.toString();
|
|
86
|
-
if (stderr.length > 0) process.stderr.write(stderr);
|
|
87
|
-
}
|
|
88
|
-
throw new CliExitError({ code: result.exitCode });
|
|
89
|
-
};
|
|
90
|
-
const runCapture = async ({ args, command, env }) => {
|
|
91
|
-
const result = await $`${command} ${args}`.cwd(cwd).env(env).quiet().nothrow();
|
|
92
|
-
return {
|
|
93
|
-
exitCode: result.exitCode,
|
|
94
|
-
stderr: result.stderr.toString(),
|
|
95
|
-
stdout: result.stdout.toString()
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
const envValue = (name) => bunEnv[name] ?? "";
|
|
99
|
-
const readVersion = async () => {
|
|
100
|
-
return readRequiredJson(await file(joinPath(lintmaxRoot, "package.json")).text()).version;
|
|
101
|
-
};
|
|
102
|
-
const usage = ({ version }) => {
|
|
103
|
-
process.stdout.write(`lintmax v${version}\n\n`);
|
|
104
|
-
process.stdout.write("Usage: lintmax <command>\n\n");
|
|
105
|
-
process.stdout.write("Commands:\n");
|
|
106
|
-
process.stdout.write(" fix Format, auto-fix, and gate all files (default)\n");
|
|
107
|
-
process.stdout.write(" check Verify all files without modifying (CI)\n");
|
|
108
|
-
process.stdout.write(" rules List all enabled rules\n");
|
|
109
|
-
process.stdout.write(" version Show version\n");
|
|
110
|
-
};
|
|
111
|
-
//#endregion
|
|
112
5
|
//#region src/index.ts
|
|
113
6
|
const SHARED_OVERRIDE_KEYS = [
|
|
114
7
|
"biome",
|
|
@@ -585,10 +478,22 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
585
478
|
}) }
|
|
586
479
|
}, {
|
|
587
480
|
includes: ["**"],
|
|
588
|
-
linter: { rules: {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
481
|
+
linter: { rules: {
|
|
482
|
+
nursery: {
|
|
483
|
+
useLayeredStyles: {
|
|
484
|
+
level: "error",
|
|
485
|
+
options: { requireImportLayers: false }
|
|
486
|
+
},
|
|
487
|
+
useReactFunctionComponentDefinition: {
|
|
488
|
+
level: "error",
|
|
489
|
+
options: { namedComponents: "arrowFunction" }
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
style: { noNegationElse: {
|
|
493
|
+
fix: "none",
|
|
494
|
+
level: "error"
|
|
495
|
+
} }
|
|
496
|
+
} }
|
|
592
497
|
}];
|
|
593
498
|
for (const override of BIOME_PATTERN_RULE_OVERRIDES) overrides.push({
|
|
594
499
|
includes: [...override.includes],
|
|
@@ -625,6 +530,7 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
625
530
|
},
|
|
626
531
|
files: {
|
|
627
532
|
experimentalScannerIgnores: ignorePatterns.map((p) => p.startsWith("!!") ? p.slice(2) : p),
|
|
533
|
+
ignoreUnknown: true,
|
|
628
534
|
includes: ["**", ...ignorePatterns]
|
|
629
535
|
},
|
|
630
536
|
formatter: {
|
|
@@ -712,9 +618,7 @@ const resolveSyncImportSource = ({ cwd, dir, source }) => {
|
|
|
712
618
|
return relativeSource.startsWith(".") ? relativeSource : `./${relativeSource}`;
|
|
713
619
|
};
|
|
714
620
|
const discoverSymlinkPatterns = async ({ root }) => {
|
|
715
|
-
const
|
|
716
|
-
if (result.exitCode !== 0) return [];
|
|
717
|
-
const entries = result.stdout.toString().split("\0").filter((e) => e.length > 0);
|
|
621
|
+
const entries = await listProjectFiles({ root });
|
|
718
622
|
const symlinkFlags = await Promise.all(entries.map(async (entry) => {
|
|
719
623
|
try {
|
|
720
624
|
return (await lstat(join(root, entry))).isSymbolicLink();
|
|
@@ -773,10 +677,50 @@ const sync = async (options) => {
|
|
|
773
677
|
})
|
|
774
678
|
}));
|
|
775
679
|
const importStatements = normalizedImportRefs.map((importRef, index) => `import * as __lintmaxAppendImport${index} from ${JSON.stringify(importRef.source)}`).join("\n");
|
|
776
|
-
const importEntries = normalizedImportRefs.map((importRef, index) =>
|
|
777
|
-
|
|
680
|
+
const importEntries = normalizedImportRefs.map((importRef, index) => [
|
|
681
|
+
` { exportName: ${JSON.stringify(importRef.exportName)}, `,
|
|
682
|
+
`files: ${JSON.stringify(importRef.files ?? null)}, `,
|
|
683
|
+
`ignores: ${JSON.stringify(importRef.ignores ?? null)}, module: __lintmaxAppendImport${index} }`
|
|
684
|
+
].join("")).join(",\n");
|
|
685
|
+
const importMarkerKey = JSON.stringify(ESLINT_IMPORT_MARKER_KEY);
|
|
686
|
+
const sharedOverrideSymbolKey = JSON.stringify(SHARED_OVERRIDE_SYMBOL_KEY);
|
|
687
|
+
const importExpansion = normalizedImportRefs.length === 0 ? "" : `
|
|
688
|
+
const appendImports = [
|
|
689
|
+
${importEntries}
|
|
690
|
+
]
|
|
691
|
+
const normalizedAppend = []
|
|
692
|
+
for (const entry of options.append ?? []) {
|
|
693
|
+
if (entry && typeof entry === 'object' && !Array.isArray(entry) && ${importMarkerKey} in entry) {
|
|
694
|
+
const importIndex = entry[${importMarkerKey}]
|
|
695
|
+
if (typeof importIndex !== 'number' || !Number.isInteger(importIndex))
|
|
696
|
+
throw new Error('Invalid eslint import marker index in generated config')
|
|
697
|
+
const importRef = appendImports[importIndex]
|
|
698
|
+
if (!importRef) throw new Error(\`Missing eslint import ref for index \${importIndex}\`)
|
|
699
|
+
const imported = importRef.module[importRef.exportName]
|
|
700
|
+
const importedEntries = Array.isArray(imported) ? imported : [imported]
|
|
701
|
+
for (const importedEntry of importedEntries) {
|
|
702
|
+
if (!importedEntry || typeof importedEntry !== 'object' || Array.isArray(importedEntry))
|
|
703
|
+
throw new Error(\`Imported eslint append from \${importRef.exportName} must resolve to config object(s)\`)
|
|
704
|
+
normalizedAppend.push({
|
|
705
|
+
...importedEntry,
|
|
706
|
+
...(Array.isArray(importRef.files) ? { files: [...importRef.files] } : {}),
|
|
707
|
+
...(Array.isArray(importRef.ignores) ? { ignores: [...importRef.ignores] } : {})
|
|
708
|
+
})
|
|
709
|
+
}
|
|
710
|
+
continue
|
|
711
|
+
}
|
|
712
|
+
normalizedAppend.push(entry)
|
|
713
|
+
}
|
|
714
|
+
options.append = normalizedAppend
|
|
715
|
+
`;
|
|
778
716
|
const importStatementsBlock = importStatements.length > 0 ? `${importStatements}\n` : "";
|
|
779
|
-
const eslintConfig = eslintOptions ? `${importStatementsBlock}import { eslint } from 'lintmax/eslint'
|
|
717
|
+
const eslintConfig = eslintOptions ? `${importStatementsBlock}import { eslint } from 'lintmax/eslint'
|
|
718
|
+
const options = ${JSON.stringify(eslintOptions)}
|
|
719
|
+
for (const index of ${JSON.stringify(sharedOverrideAppendIndexes)}) {
|
|
720
|
+
const entry = options.append?.[index]
|
|
721
|
+
if (entry && typeof entry === 'object') entry[Symbol.for(${sharedOverrideSymbolKey})] = true
|
|
722
|
+
}${importExpansion}export default await eslint(options)
|
|
723
|
+
` : "export { default } from 'lintmax/eslint'\n";
|
|
780
724
|
const runtimeConfig = {
|
|
781
725
|
comments: options?.comments !== false,
|
|
782
726
|
compact: options?.compact !== false
|
|
@@ -801,4 +745,4 @@ const defineConfig = (options) => {
|
|
|
801
745
|
return options;
|
|
802
746
|
};
|
|
803
747
|
//#endregion
|
|
804
|
-
export {
|
|
748
|
+
export { eslintImport as n, sync as r, defineConfig as t };
|