lintmax 0.1.103 → 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 +104 -134
- 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-gPY63Hnk.mjs → src-8LKWIKXe.mjs} +20 -122
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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";
|
|
@@ -411,17 +411,8 @@ const checkClassNameFile = async (filePath) => {
|
|
|
411
411
|
}));
|
|
412
412
|
};
|
|
413
413
|
const checkClassName = async ({ root }) => {
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
for await (const path of glob.scan({
|
|
417
|
-
absolute: true,
|
|
418
|
-
cwd: root,
|
|
419
|
-
dot: false
|
|
420
|
-
})) if (!(path.includes("node_modules") || path.includes("readonly") || path.includes(".next") || path.includes("dist"))) {
|
|
421
|
-
const diagnostics = await checkClassNameFile(path);
|
|
422
|
-
allDiagnostics.push(...diagnostics);
|
|
423
|
-
}
|
|
424
|
-
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();
|
|
425
416
|
};
|
|
426
417
|
//#endregion
|
|
427
418
|
//#region src/rules.ts
|
|
@@ -952,16 +943,10 @@ const isBinary = ({ bytes }) => {
|
|
|
952
943
|
return false;
|
|
953
944
|
};
|
|
954
945
|
const listCompactFiles = async ({ env, root }) => {
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
throw new CliExitError({
|
|
960
|
-
code: result.exitCode,
|
|
961
|
-
message: stderr.length > 0 ? stderr : "Failed to list files for compact step"
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
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");
|
|
965
950
|
const symlinkFlags = await Promise.all(entries.map(async (e) => isSymlinkSafe(join(root, e))));
|
|
966
951
|
return entries.filter((_e, index) => !symlinkFlags[index]);
|
|
967
952
|
};
|
|
@@ -1272,7 +1257,6 @@ const eslintDisableRe = /eslint-disable(?:-next-line)?\s+([^\n]*)/gv;
|
|
|
1272
1257
|
const oxlintDisableRe$1 = /oxlint-disable(?:-next-line)?\s+([^\n]*)/gv;
|
|
1273
1258
|
const biomeIgnoreRe = /biome-ignore(?:-all)?\s+([\w/]+)/gu;
|
|
1274
1259
|
const tsIgnoreRe = /@ts-(?:expect-error|ignore|nocheck)/gv;
|
|
1275
|
-
/** Strip a trailing `-- reason` and a trailing block-comment close from one split rule. indexOf is linear where the leading-whitespace regexes backtrack. */
|
|
1276
1260
|
const stripRuleTail = (rule) => {
|
|
1277
1261
|
const dash = rule.indexOf("--");
|
|
1278
1262
|
const noComment = dash === -1 ? rule : rule.slice(0, dash);
|
|
@@ -1280,6 +1264,7 @@ const stripRuleTail = (rule) => {
|
|
|
1280
1264
|
return (close === -1 ? noComment : noComment.slice(0, close)).trim();
|
|
1281
1265
|
};
|
|
1282
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;
|
|
1283
1268
|
const DANGEROUS_PATTERNS = [
|
|
1284
1269
|
"no-unsafe-argument",
|
|
1285
1270
|
"no-unsafe-assignment",
|
|
@@ -1311,21 +1296,11 @@ const parseRules = (line, re) => {
|
|
|
1311
1296
|
}
|
|
1312
1297
|
return rules;
|
|
1313
1298
|
};
|
|
1314
|
-
const isDangerousRule = (rule,
|
|
1299
|
+
const isDangerousRule = (rule, filePath) => {
|
|
1315
1300
|
if (DANGEROUS_PATTERNS.some((p) => rule.includes(p))) return true;
|
|
1316
|
-
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);
|
|
1317
1302
|
return false;
|
|
1318
1303
|
};
|
|
1319
|
-
const parseRipgrepLine = (raw, cwd) => {
|
|
1320
|
-
const firstColon = raw.indexOf(":");
|
|
1321
|
-
const secondColon = raw.indexOf(":", firstColon + 1);
|
|
1322
|
-
if (secondColon <= firstColon) return;
|
|
1323
|
-
return {
|
|
1324
|
-
content: raw.slice(secondColon + 1),
|
|
1325
|
-
file: raw.slice(0, firstColon).replace(`${cwd}/`, ""),
|
|
1326
|
-
lineNum: Number(raw.slice(firstColon + 1, secondColon))
|
|
1327
|
-
};
|
|
1328
|
-
};
|
|
1329
1304
|
const rulesFromContent = (content) => {
|
|
1330
1305
|
const rules = [
|
|
1331
1306
|
...parseRules(content, eslintDisableRe),
|
|
@@ -1340,21 +1315,20 @@ const rulesFromContent = (content) => {
|
|
|
1340
1315
|
return rules;
|
|
1341
1316
|
};
|
|
1342
1317
|
const findDangerousSuppressions = async (cwd) => {
|
|
1343
|
-
const
|
|
1344
|
-
const
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
const
|
|
1348
|
-
if (
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
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,
|
|
1353
1327
|
rule
|
|
1354
1328
|
});
|
|
1355
1329
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1330
|
+
return findings;
|
|
1331
|
+
}))).flat();
|
|
1358
1332
|
};
|
|
1359
1333
|
//#endregion
|
|
1360
1334
|
//#region src/jsx-extension.ts
|
|
@@ -1381,24 +1355,19 @@ const hasJsx = (sourceText) => {
|
|
|
1381
1355
|
return containsJsxNode(asTsx.program);
|
|
1382
1356
|
};
|
|
1383
1357
|
const checkJsxExtension = async ({ root }) => {
|
|
1384
|
-
const glob = new Glob("**/*.ts");
|
|
1385
1358
|
const ignoreGlobs = DEFAULT_SHARED_IGNORE_PATTERNS.map((p) => new Glob(p));
|
|
1386
1359
|
const isIgnored = (p) => p.includes("node_modules") || p.endsWith(".d.ts") || ignoreGlobs.some((g) => g.match(p));
|
|
1387
|
-
const
|
|
1388
|
-
|
|
1389
|
-
absolute: false,
|
|
1390
|
-
cwd: root,
|
|
1391
|
-
dot: false
|
|
1392
|
-
})) 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) => {
|
|
1393
1362
|
const content = await file(`${root}/${path}`).text();
|
|
1394
|
-
if (hasJsx(content))
|
|
1363
|
+
if (!hasJsx(content)) return [];
|
|
1364
|
+
return [{
|
|
1395
1365
|
file: `${root}/${path}`,
|
|
1396
1366
|
line: 1,
|
|
1397
1367
|
linter: "lintmax",
|
|
1398
1368
|
rule: "jsx-requires-tsx-extension"
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
return diagnostics;
|
|
1369
|
+
}];
|
|
1370
|
+
}))).flat();
|
|
1402
1371
|
};
|
|
1403
1372
|
//#endregion
|
|
1404
1373
|
//#region src/unused-suppressions.ts
|
|
@@ -1910,16 +1879,14 @@ const createStepExecutor = ({ env, failures, root }) => {
|
|
|
1910
1879
|
throwIfFailures
|
|
1911
1880
|
};
|
|
1912
1881
|
};
|
|
1913
|
-
const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson }) => {
|
|
1882
|
+
const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson, targets }) => {
|
|
1914
1883
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
1915
1884
|
const steps = [
|
|
1916
1885
|
{
|
|
1917
1886
|
args: [
|
|
1918
1887
|
sortPkgJson,
|
|
1919
1888
|
"--check",
|
|
1920
|
-
|
|
1921
|
-
"--ignore",
|
|
1922
|
-
"**/node_modules/**"
|
|
1889
|
+
...targets.packages
|
|
1923
1890
|
],
|
|
1924
1891
|
label: "sort-package-json"
|
|
1925
1892
|
},
|
|
@@ -1929,7 +1896,8 @@ const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxl
|
|
|
1929
1896
|
"ci",
|
|
1930
1897
|
"--config-path",
|
|
1931
1898
|
dir,
|
|
1932
|
-
"--diagnostic-level=error"
|
|
1899
|
+
"--diagnostic-level=error",
|
|
1900
|
+
...targets.biome
|
|
1933
1901
|
],
|
|
1934
1902
|
label: "biome"
|
|
1935
1903
|
},
|
|
@@ -1940,7 +1908,8 @@ const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxl
|
|
|
1940
1908
|
joinPath(dir, ".oxlintrc.json"),
|
|
1941
1909
|
"--quiet",
|
|
1942
1910
|
"--no-error-on-unmatched-pattern",
|
|
1943
|
-
...oxlintCliAllow
|
|
1911
|
+
...oxlintCliAllow,
|
|
1912
|
+
...targets.source
|
|
1944
1913
|
],
|
|
1945
1914
|
label: "oxlint"
|
|
1946
1915
|
},
|
|
@@ -1963,19 +1932,20 @@ const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxl
|
|
|
1963
1932
|
],
|
|
1964
1933
|
label: "prettier"
|
|
1965
1934
|
});
|
|
1966
|
-
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
|
+
});
|
|
1967
1942
|
};
|
|
1968
1943
|
const DESTRUCTIVE_FIX_OVERRIDES = ["--rule", "{\"@eslint-react/no-missing-context-display-name\":\"off\"}"];
|
|
1969
|
-
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 }) => {
|
|
1970
1945
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
1971
1946
|
const steps = [
|
|
1972
1947
|
{
|
|
1973
|
-
args: [
|
|
1974
|
-
sortPkgJson,
|
|
1975
|
-
"**/package.json",
|
|
1976
|
-
"--ignore",
|
|
1977
|
-
"**/node_modules/**"
|
|
1978
|
-
],
|
|
1948
|
+
args: [sortPkgJson, ...targets.packages],
|
|
1979
1949
|
label: "sort-package-json",
|
|
1980
1950
|
silent: true
|
|
1981
1951
|
},
|
|
@@ -1986,7 +1956,8 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
1986
1956
|
"--config-path",
|
|
1987
1957
|
dir,
|
|
1988
1958
|
"--fix",
|
|
1989
|
-
"--diagnostic-level=error"
|
|
1959
|
+
"--diagnostic-level=error",
|
|
1960
|
+
...targets.biome
|
|
1990
1961
|
],
|
|
1991
1962
|
label: "biome",
|
|
1992
1963
|
silent: true
|
|
@@ -2000,7 +1971,8 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
2000
1971
|
"--fix-suggestions",
|
|
2001
1972
|
"--quiet",
|
|
2002
1973
|
"--no-error-on-unmatched-pattern",
|
|
2003
|
-
...oxlintCliAllow
|
|
1974
|
+
...oxlintCliAllow,
|
|
1975
|
+
...targets.source
|
|
2004
1976
|
],
|
|
2005
1977
|
label: "oxlint",
|
|
2006
1978
|
silent: true
|
|
@@ -2022,18 +1994,19 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
2022
1994
|
"--config-path",
|
|
2023
1995
|
dir,
|
|
2024
1996
|
"--fix",
|
|
2025
|
-
"--diagnostic-level=error"
|
|
1997
|
+
"--diagnostic-level=error",
|
|
1998
|
+
...targets.biome
|
|
2026
1999
|
],
|
|
2027
2000
|
label: "biome",
|
|
2028
2001
|
silent: true
|
|
2029
2002
|
}
|
|
2030
2003
|
];
|
|
2031
|
-
if (hasFlowmark) steps.push({
|
|
2004
|
+
if (hasFlowmark) for (const target of prettierMarkdownTargets.filter((p) => p.endsWith(".md"))) steps.push({
|
|
2032
2005
|
args: [
|
|
2033
2006
|
"-w",
|
|
2034
2007
|
"0",
|
|
2035
2008
|
"--auto",
|
|
2036
|
-
|
|
2009
|
+
target
|
|
2037
2010
|
],
|
|
2038
2011
|
command: "flowmark",
|
|
2039
2012
|
label: "flowmark",
|
|
@@ -2050,7 +2023,13 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
2050
2023
|
label: "prettier",
|
|
2051
2024
|
silent: true
|
|
2052
2025
|
});
|
|
2053
|
-
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
|
+
});
|
|
2054
2033
|
};
|
|
2055
2034
|
const captureAndParse = async ({ env, failures, label, opts, parser }) => {
|
|
2056
2035
|
const result = await runCapture({
|
|
@@ -2074,13 +2053,13 @@ const captureAndParse = async ({ env, failures, label, opts, parser }) => {
|
|
|
2074
2053
|
});
|
|
2075
2054
|
return [];
|
|
2076
2055
|
};
|
|
2077
|
-
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 }) => {
|
|
2078
2057
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
2079
2058
|
const allDiagnostics = [];
|
|
2080
2059
|
const push = (d) => {
|
|
2081
2060
|
if (d.length > 0) allDiagnostics.push(...d);
|
|
2082
2061
|
};
|
|
2083
|
-
push(await captureAndParse({
|
|
2062
|
+
if (targets.packages.length > 0) push(await captureAndParse({
|
|
2084
2063
|
env,
|
|
2085
2064
|
failures,
|
|
2086
2065
|
label: "sort-package-json",
|
|
@@ -2088,15 +2067,13 @@ const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failur
|
|
|
2088
2067
|
args: [
|
|
2089
2068
|
sortPkgJson,
|
|
2090
2069
|
"--check",
|
|
2091
|
-
|
|
2092
|
-
"--ignore",
|
|
2093
|
-
"**/node_modules/**"
|
|
2070
|
+
...targets.packages
|
|
2094
2071
|
],
|
|
2095
2072
|
command: "bun"
|
|
2096
2073
|
},
|
|
2097
2074
|
parser: parseSortPackageJsonOutput
|
|
2098
2075
|
}));
|
|
2099
|
-
push(await captureAndParse({
|
|
2076
|
+
if (targets.biome.length > 0) push(await captureAndParse({
|
|
2100
2077
|
env,
|
|
2101
2078
|
failures,
|
|
2102
2079
|
label: "biome",
|
|
@@ -2106,13 +2083,14 @@ const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failur
|
|
|
2106
2083
|
"check",
|
|
2107
2084
|
"--config-path",
|
|
2108
2085
|
dir,
|
|
2109
|
-
"--reporter=json"
|
|
2086
|
+
"--reporter=json",
|
|
2087
|
+
...targets.biome
|
|
2110
2088
|
],
|
|
2111
2089
|
command: "bun"
|
|
2112
2090
|
},
|
|
2113
2091
|
parser: ({ stdout }) => parseBiomeDiagnostics({ stdout })
|
|
2114
2092
|
}));
|
|
2115
|
-
push(await captureAndParse({
|
|
2093
|
+
if (targets.source.length > 0) push(await captureAndParse({
|
|
2116
2094
|
env,
|
|
2117
2095
|
failures,
|
|
2118
2096
|
label: "oxlint",
|
|
@@ -2125,13 +2103,14 @@ const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failur
|
|
|
2125
2103
|
"--no-error-on-unmatched-pattern",
|
|
2126
2104
|
"-f",
|
|
2127
2105
|
"json",
|
|
2128
|
-
...oxlintCliAllow
|
|
2106
|
+
...oxlintCliAllow,
|
|
2107
|
+
...targets.source
|
|
2129
2108
|
],
|
|
2130
2109
|
command: "bun"
|
|
2131
2110
|
},
|
|
2132
2111
|
parser: ({ stdout }) => parseOxlintDiagnostics({ stdout })
|
|
2133
2112
|
}));
|
|
2134
|
-
push(await captureAndParse({
|
|
2113
|
+
if (targets.eslint.length > 0) push(await captureAndParse({
|
|
2135
2114
|
env,
|
|
2136
2115
|
failures,
|
|
2137
2116
|
label: "eslint",
|
|
@@ -2182,30 +2161,28 @@ const dangerousToDiagnostics = (items) => items.map((d) => ({
|
|
|
2182
2161
|
linter: "forbidden-suppression",
|
|
2183
2162
|
rule: d.rule
|
|
2184
2163
|
}));
|
|
2185
|
-
const
|
|
2164
|
+
const SOURCE_EXTENSIONS = [
|
|
2165
|
+
".js",
|
|
2166
|
+
".jsx",
|
|
2167
|
+
".mjs",
|
|
2168
|
+
".cjs",
|
|
2169
|
+
".ts",
|
|
2170
|
+
".tsx",
|
|
2171
|
+
".mts",
|
|
2172
|
+
".cts"
|
|
2173
|
+
];
|
|
2186
2174
|
const PRETTIER_EXTENSIONS = [
|
|
2187
2175
|
".md",
|
|
2188
2176
|
".yml",
|
|
2189
2177
|
".yaml"
|
|
2190
2178
|
];
|
|
2191
|
-
const
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
dot: false
|
|
2199
|
-
})) if (!(path.includes("node_modules") || isIgnored(path))) found.push(path);
|
|
2200
|
-
return found;
|
|
2201
|
-
};
|
|
2202
|
-
const createPrettierMarkdownTargets = async ({ gitFiles, gitWorkTree, isIgnored, root }) => {
|
|
2203
|
-
if (gitWorkTree) return gitFiles.filter((f) => isPrettierTarget(f) && !isIgnored(f));
|
|
2204
|
-
return await scanPrettierTargets({
|
|
2205
|
-
isIgnored,
|
|
2206
|
-
root
|
|
2207
|
-
});
|
|
2208
|
-
};
|
|
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
|
+
});
|
|
2209
2186
|
const throwAgentResults = ({ diagnostics, failures }) => {
|
|
2210
2187
|
if (diagnostics.length === 0 && failures.length === 0) return;
|
|
2211
2188
|
const grouped = aggregate({ diagnostics });
|
|
@@ -2413,28 +2390,25 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2413
2390
|
isIgnored,
|
|
2414
2391
|
mode: "fix"
|
|
2415
2392
|
});
|
|
2416
|
-
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
|
+
];
|
|
2417
2404
|
const [sortPkgJson, biomeBin, oxlintBin, eslintBin, prettierBin, tombiBin, dprintBin] = await resolveAllBins();
|
|
2418
2405
|
const extraBins = {
|
|
2419
2406
|
dprint: dprintBin,
|
|
2420
2407
|
tombi: tombiBin
|
|
2421
2408
|
};
|
|
2422
2409
|
const hasFlowmark = (await $`which flowmark`.env(env).quiet().nothrow()).exitCode === 0;
|
|
2423
|
-
const gitWorkTree = await isGitWorkTree({
|
|
2424
|
-
env,
|
|
2425
|
-
root: cwd
|
|
2426
|
-
});
|
|
2427
|
-
const allGitFiles = (gitWorkTree ? await listCompactFiles({
|
|
2428
|
-
env,
|
|
2429
|
-
root: cwd
|
|
2430
|
-
}) : []).filter((one) => !isIgnored(one));
|
|
2431
2410
|
const oxlintIgnorePatterns = oxlintIgnorePatternsEarly;
|
|
2432
|
-
const prettierMarkdownTargets =
|
|
2433
|
-
gitFiles: allGitFiles,
|
|
2434
|
-
gitWorkTree,
|
|
2435
|
-
isIgnored,
|
|
2436
|
-
root: cwd
|
|
2437
|
-
});
|
|
2411
|
+
const prettierMarkdownTargets = allGitFiles.filter((p) => hasExtension(p, PRETTIER_EXTENSIONS)).map((p) => joinPath(cwd, p));
|
|
2438
2412
|
const checkSteps = createCheckSteps({
|
|
2439
2413
|
biomeBin,
|
|
2440
2414
|
dir,
|
|
@@ -2444,7 +2418,8 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2444
2418
|
oxlintIgnorePatterns,
|
|
2445
2419
|
prettierBin,
|
|
2446
2420
|
prettierMarkdownTargets,
|
|
2447
|
-
sortPkgJson
|
|
2421
|
+
sortPkgJson,
|
|
2422
|
+
targets
|
|
2448
2423
|
});
|
|
2449
2424
|
const shouldComments = runtime.comments !== false;
|
|
2450
2425
|
const sourceFiles = allGitFiles.filter((f) => !isIgnored(f));
|
|
@@ -2460,7 +2435,8 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2460
2435
|
oxlintIgnorePatterns,
|
|
2461
2436
|
prettierBin,
|
|
2462
2437
|
prettierMarkdownTargets,
|
|
2463
|
-
sortPkgJson
|
|
2438
|
+
sortPkgJson,
|
|
2439
|
+
targets
|
|
2464
2440
|
},
|
|
2465
2441
|
allGitFiles,
|
|
2466
2442
|
checkSteps,
|
|
@@ -2483,7 +2459,8 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2483
2459
|
oxlintIgnorePatterns,
|
|
2484
2460
|
prettierBin,
|
|
2485
2461
|
prettierMarkdownTargets,
|
|
2486
|
-
sortPkgJson
|
|
2462
|
+
sortPkgJson,
|
|
2463
|
+
targets
|
|
2487
2464
|
});
|
|
2488
2465
|
await runFixCommand({
|
|
2489
2466
|
clearFailures,
|
|
@@ -2656,16 +2633,9 @@ const formatStaleness = (issues) => {
|
|
|
2656
2633
|
//#endregion
|
|
2657
2634
|
//#region src/gate.ts
|
|
2658
2635
|
const envNoCache = "LINTMAX_NO_CACHE";
|
|
2659
|
-
const listTrackedFiles = async () => {
|
|
2660
|
-
if ((await $`git -C ${cwd} rev-parse --is-inside-work-tree`.env(bunEnv).quiet().nothrow()).exitCode !== 0) return null;
|
|
2661
|
-
const result = await $`git -C ${cwd} ls-files -z --cached --others --exclude-standard`.env(bunEnv).quiet().nothrow();
|
|
2662
|
-
if (result.exitCode !== 0) return null;
|
|
2663
|
-
return result.stdout.toString().split("\0").filter((entry) => entry.length > 0);
|
|
2664
|
-
};
|
|
2665
2636
|
const computeGreenKey = async (version) => {
|
|
2666
2637
|
if (envValue(envNoCache) === "1") return null;
|
|
2667
|
-
const files = await
|
|
2668
|
-
if (files === null) return null;
|
|
2638
|
+
const files = await listProjectFiles({ root: cwd });
|
|
2669
2639
|
return hashTree({
|
|
2670
2640
|
files,
|
|
2671
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,16 +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
|
+
}
|
|
592
491
|
},
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
597
|
-
} }
|
|
492
|
+
style: { noNegationElse: {
|
|
493
|
+
fix: "none",
|
|
494
|
+
level: "error"
|
|
495
|
+
} }
|
|
496
|
+
} }
|
|
598
497
|
}];
|
|
599
498
|
for (const override of BIOME_PATTERN_RULE_OVERRIDES) overrides.push({
|
|
600
499
|
includes: [...override.includes],
|
|
@@ -631,6 +530,7 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
631
530
|
},
|
|
632
531
|
files: {
|
|
633
532
|
experimentalScannerIgnores: ignorePatterns.map((p) => p.startsWith("!!") ? p.slice(2) : p),
|
|
533
|
+
ignoreUnknown: true,
|
|
634
534
|
includes: ["**", ...ignorePatterns]
|
|
635
535
|
},
|
|
636
536
|
formatter: {
|
|
@@ -718,9 +618,7 @@ const resolveSyncImportSource = ({ cwd, dir, source }) => {
|
|
|
718
618
|
return relativeSource.startsWith(".") ? relativeSource : `./${relativeSource}`;
|
|
719
619
|
};
|
|
720
620
|
const discoverSymlinkPatterns = async ({ root }) => {
|
|
721
|
-
const
|
|
722
|
-
if (result.exitCode !== 0) return [];
|
|
723
|
-
const entries = result.stdout.toString().split("\0").filter((e) => e.length > 0);
|
|
621
|
+
const entries = await listProjectFiles({ root });
|
|
724
622
|
const symlinkFlags = await Promise.all(entries.map(async (entry) => {
|
|
725
623
|
try {
|
|
726
624
|
return (await lstat(join(root, entry))).isSymbolicLink();
|
|
@@ -847,4 +745,4 @@ const defineConfig = (options) => {
|
|
|
847
745
|
return options;
|
|
848
746
|
};
|
|
849
747
|
//#endregion
|
|
850
|
-
export {
|
|
748
|
+
export { eslintImport as n, sync as r, defineConfig as t };
|