lintmax 0.1.103 → 0.1.105
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 +124 -137
- package/dist/eslint.mjs +3 -1
- package/dist/index.mjs +1 -2
- package/dist/{path-Dgmf8CJi.mjs → project-files-C4cvEhY7.mjs} +212 -1
- package/dist/{src-gPY63Hnk.mjs → src-DDkinCyR.mjs} +20 -122
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
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-C4cvEhY7.mjs";
|
|
3
|
+
import { r as sync } from "./src-DDkinCyR.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
|
+
import { homedir, platform, tmpdir } from "node:os";
|
|
8
|
+
import { Buffer } from "node:buffer";
|
|
7
9
|
import { parseSync } from "oxc-parser";
|
|
8
10
|
import { ESLint } from "eslint";
|
|
9
11
|
import { createHash } from "node:crypto";
|
|
10
|
-
import { homedir, platform, tmpdir } from "node:os";
|
|
11
12
|
//#region src/rule-equivalence.ts
|
|
12
13
|
const equivalenceGroups = [
|
|
13
14
|
[
|
|
@@ -411,17 +412,8 @@ const checkClassNameFile = async (filePath) => {
|
|
|
411
412
|
}));
|
|
412
413
|
};
|
|
413
414
|
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;
|
|
415
|
+
const paths = (await listProjectFiles({ root })).filter((path) => isTsxFile(path) && !(path.includes("node_modules") || path.includes("readonly") || path.includes(".next") || path.includes("dist")));
|
|
416
|
+
return (await Promise.all(paths.map(async (path) => checkClassNameFile(joinPath(root, path))))).flat();
|
|
425
417
|
};
|
|
426
418
|
//#endregion
|
|
427
419
|
//#region src/rules.ts
|
|
@@ -952,16 +944,10 @@ const isBinary = ({ bytes }) => {
|
|
|
952
944
|
return false;
|
|
953
945
|
};
|
|
954
946
|
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");
|
|
947
|
+
const entries = (await listProjectFiles({
|
|
948
|
+
env,
|
|
949
|
+
root
|
|
950
|
+
})).filter((e) => e !== "bun.lock");
|
|
965
951
|
const symlinkFlags = await Promise.all(entries.map(async (e) => isSymlinkSafe(join(root, e))));
|
|
966
952
|
return entries.filter((_e, index) => !symlinkFlags[index]);
|
|
967
953
|
};
|
|
@@ -1272,7 +1258,6 @@ const eslintDisableRe = /eslint-disable(?:-next-line)?\s+([^\n]*)/gv;
|
|
|
1272
1258
|
const oxlintDisableRe$1 = /oxlint-disable(?:-next-line)?\s+([^\n]*)/gv;
|
|
1273
1259
|
const biomeIgnoreRe = /biome-ignore(?:-all)?\s+([\w/]+)/gu;
|
|
1274
1260
|
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
1261
|
const stripRuleTail = (rule) => {
|
|
1277
1262
|
const dash = rule.indexOf("--");
|
|
1278
1263
|
const noComment = dash === -1 ? rule : rule.slice(0, dash);
|
|
@@ -1280,6 +1265,7 @@ const stripRuleTail = (rule) => {
|
|
|
1280
1265
|
return (close === -1 ? noComment : noComment.slice(0, close)).trim();
|
|
1281
1266
|
};
|
|
1282
1267
|
const tsInlineRe = /@ts-(?:expect-error|ignore|nocheck)/v;
|
|
1268
|
+
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
1269
|
const DANGEROUS_PATTERNS = [
|
|
1284
1270
|
"no-unsafe-argument",
|
|
1285
1271
|
"no-unsafe-assignment",
|
|
@@ -1311,21 +1297,11 @@ const parseRules = (line, re) => {
|
|
|
1311
1297
|
}
|
|
1312
1298
|
return rules;
|
|
1313
1299
|
};
|
|
1314
|
-
const isDangerousRule = (rule,
|
|
1300
|
+
const isDangerousRule = (rule, filePath) => {
|
|
1315
1301
|
if (DANGEROUS_PATTERNS.some((p) => rule.includes(p))) return true;
|
|
1316
|
-
if (DANGEROUS_NON_TEST_PATTERNS.some((p) => rule.includes(p))) return !isTestFile(
|
|
1302
|
+
if (DANGEROUS_NON_TEST_PATTERNS.some((p) => rule.includes(p))) return !isTestFile(filePath);
|
|
1317
1303
|
return false;
|
|
1318
1304
|
};
|
|
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
1305
|
const rulesFromContent = (content) => {
|
|
1330
1306
|
const rules = [
|
|
1331
1307
|
...parseRules(content, eslintDisableRe),
|
|
@@ -1340,21 +1316,20 @@ const rulesFromContent = (content) => {
|
|
|
1340
1316
|
return rules;
|
|
1341
1317
|
};
|
|
1342
1318
|
const findDangerousSuppressions = async (cwd) => {
|
|
1343
|
-
const
|
|
1344
|
-
const
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
const
|
|
1348
|
-
if (
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
line: lineNum,
|
|
1319
|
+
const ignoreGlobs = DEFAULT_SHARED_IGNORE_PATTERNS.map((p) => new Glob(p));
|
|
1320
|
+
const files = (await listProjectFiles({ root: cwd })).filter((p) => (p.endsWith(".ts") || p.endsWith(".tsx")) && !p.endsWith(".d.ts") && !ignoreGlobs.some((g) => g.match(p)));
|
|
1321
|
+
return (await Promise.all(files.map(async (relativePath) => {
|
|
1322
|
+
const lines = (await file(joinPath(cwd, relativePath)).text()).split("\n");
|
|
1323
|
+
const findings = [];
|
|
1324
|
+
for (const [index, content] of lines.entries()) if (suppressionLineRe.test(content)) {
|
|
1325
|
+
for (const rule of rulesFromContent(content)) if (isDangerousRule(rule, relativePath)) findings.push({
|
|
1326
|
+
file: relativePath,
|
|
1327
|
+
line: index + 1,
|
|
1353
1328
|
rule
|
|
1354
1329
|
});
|
|
1355
1330
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1331
|
+
return findings;
|
|
1332
|
+
}))).flat();
|
|
1358
1333
|
};
|
|
1359
1334
|
//#endregion
|
|
1360
1335
|
//#region src/jsx-extension.ts
|
|
@@ -1381,24 +1356,19 @@ const hasJsx = (sourceText) => {
|
|
|
1381
1356
|
return containsJsxNode(asTsx.program);
|
|
1382
1357
|
};
|
|
1383
1358
|
const checkJsxExtension = async ({ root }) => {
|
|
1384
|
-
const glob = new Glob("**/*.ts");
|
|
1385
1359
|
const ignoreGlobs = DEFAULT_SHARED_IGNORE_PATTERNS.map((p) => new Glob(p));
|
|
1386
1360
|
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)) {
|
|
1361
|
+
const paths = (await listProjectFiles({ root })).filter((p) => p.endsWith(".ts") && !isIgnored(p));
|
|
1362
|
+
return (await Promise.all(paths.map(async (path) => {
|
|
1393
1363
|
const content = await file(`${root}/${path}`).text();
|
|
1394
|
-
if (hasJsx(content))
|
|
1364
|
+
if (!hasJsx(content)) return [];
|
|
1365
|
+
return [{
|
|
1395
1366
|
file: `${root}/${path}`,
|
|
1396
1367
|
line: 1,
|
|
1397
1368
|
linter: "lintmax",
|
|
1398
1369
|
rule: "jsx-requires-tsx-extension"
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
return diagnostics;
|
|
1370
|
+
}];
|
|
1371
|
+
}))).flat();
|
|
1402
1372
|
};
|
|
1403
1373
|
//#endregion
|
|
1404
1374
|
//#region src/unused-suppressions.ts
|
|
@@ -1499,6 +1469,7 @@ const requireLintAnswer = ({ exitCode, label, stderr, stdout }) => {
|
|
|
1499
1469
|
refuse("produced no parseable JSON");
|
|
1500
1470
|
}
|
|
1501
1471
|
if (!Array.isArray(parsed.diagnostics)) refuse("returned JSON carrying no diagnostics array");
|
|
1472
|
+
if (exitCode !== 0 && parsed.diagnostics.length === 0) refuse("failed with zero diagnostics");
|
|
1502
1473
|
return json;
|
|
1503
1474
|
};
|
|
1504
1475
|
const firedOxlintByFile = async ({ configPath, files, oxlintBin }) => {
|
|
@@ -1910,16 +1881,14 @@ const createStepExecutor = ({ env, failures, root }) => {
|
|
|
1910
1881
|
throwIfFailures
|
|
1911
1882
|
};
|
|
1912
1883
|
};
|
|
1913
|
-
const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson }) => {
|
|
1884
|
+
const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson, targets }) => {
|
|
1914
1885
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
1915
1886
|
const steps = [
|
|
1916
1887
|
{
|
|
1917
1888
|
args: [
|
|
1918
1889
|
sortPkgJson,
|
|
1919
1890
|
"--check",
|
|
1920
|
-
|
|
1921
|
-
"--ignore",
|
|
1922
|
-
"**/node_modules/**"
|
|
1891
|
+
...targets.packages
|
|
1923
1892
|
],
|
|
1924
1893
|
label: "sort-package-json"
|
|
1925
1894
|
},
|
|
@@ -1929,7 +1898,8 @@ const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxl
|
|
|
1929
1898
|
"ci",
|
|
1930
1899
|
"--config-path",
|
|
1931
1900
|
dir,
|
|
1932
|
-
"--diagnostic-level=error"
|
|
1901
|
+
"--diagnostic-level=error",
|
|
1902
|
+
...targets.biome
|
|
1933
1903
|
],
|
|
1934
1904
|
label: "biome"
|
|
1935
1905
|
},
|
|
@@ -1940,7 +1910,8 @@ const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxl
|
|
|
1940
1910
|
joinPath(dir, ".oxlintrc.json"),
|
|
1941
1911
|
"--quiet",
|
|
1942
1912
|
"--no-error-on-unmatched-pattern",
|
|
1943
|
-
...oxlintCliAllow
|
|
1913
|
+
...oxlintCliAllow,
|
|
1914
|
+
...targets.source
|
|
1944
1915
|
],
|
|
1945
1916
|
label: "oxlint"
|
|
1946
1917
|
},
|
|
@@ -1963,19 +1934,20 @@ const createCheckSteps = ({ biomeBin, dir, eslintArgs, eslintBin, oxlintBin, oxl
|
|
|
1963
1934
|
],
|
|
1964
1935
|
label: "prettier"
|
|
1965
1936
|
});
|
|
1966
|
-
return steps
|
|
1937
|
+
return steps.filter((step) => {
|
|
1938
|
+
if (step.label === "sort-package-json") return targets.packages.length > 0;
|
|
1939
|
+
if (step.label === "biome") return targets.biome.length > 0;
|
|
1940
|
+
if (step.label === "oxlint") return targets.source.length > 0;
|
|
1941
|
+
if (step.label === "eslint") return targets.eslint.length > 0;
|
|
1942
|
+
return true;
|
|
1943
|
+
});
|
|
1967
1944
|
};
|
|
1968
1945
|
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 }) => {
|
|
1946
|
+
const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson, targets }) => {
|
|
1970
1947
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
1971
1948
|
const steps = [
|
|
1972
1949
|
{
|
|
1973
|
-
args: [
|
|
1974
|
-
sortPkgJson,
|
|
1975
|
-
"**/package.json",
|
|
1976
|
-
"--ignore",
|
|
1977
|
-
"**/node_modules/**"
|
|
1978
|
-
],
|
|
1950
|
+
args: [sortPkgJson, ...targets.packages],
|
|
1979
1951
|
label: "sort-package-json",
|
|
1980
1952
|
silent: true
|
|
1981
1953
|
},
|
|
@@ -1986,7 +1958,8 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
1986
1958
|
"--config-path",
|
|
1987
1959
|
dir,
|
|
1988
1960
|
"--fix",
|
|
1989
|
-
"--diagnostic-level=error"
|
|
1961
|
+
"--diagnostic-level=error",
|
|
1962
|
+
...targets.biome
|
|
1990
1963
|
],
|
|
1991
1964
|
label: "biome",
|
|
1992
1965
|
silent: true
|
|
@@ -2000,7 +1973,8 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
2000
1973
|
"--fix-suggestions",
|
|
2001
1974
|
"--quiet",
|
|
2002
1975
|
"--no-error-on-unmatched-pattern",
|
|
2003
|
-
...oxlintCliAllow
|
|
1976
|
+
...oxlintCliAllow,
|
|
1977
|
+
...targets.source
|
|
2004
1978
|
],
|
|
2005
1979
|
label: "oxlint",
|
|
2006
1980
|
silent: true
|
|
@@ -2022,18 +1996,19 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
2022
1996
|
"--config-path",
|
|
2023
1997
|
dir,
|
|
2024
1998
|
"--fix",
|
|
2025
|
-
"--diagnostic-level=error"
|
|
1999
|
+
"--diagnostic-level=error",
|
|
2000
|
+
...targets.biome
|
|
2026
2001
|
],
|
|
2027
2002
|
label: "biome",
|
|
2028
2003
|
silent: true
|
|
2029
2004
|
}
|
|
2030
2005
|
];
|
|
2031
|
-
if (hasFlowmark) steps.push({
|
|
2006
|
+
if (hasFlowmark) for (const target of prettierMarkdownTargets.filter((p) => p.endsWith(".md"))) steps.push({
|
|
2032
2007
|
args: [
|
|
2033
2008
|
"-w",
|
|
2034
2009
|
"0",
|
|
2035
2010
|
"--auto",
|
|
2036
|
-
|
|
2011
|
+
target
|
|
2037
2012
|
],
|
|
2038
2013
|
command: "flowmark",
|
|
2039
2014
|
label: "flowmark",
|
|
@@ -2050,7 +2025,13 @@ const createFixSteps = ({ biomeBin, dir, eslintArgs, eslintBin, hasFlowmark, oxl
|
|
|
2050
2025
|
label: "prettier",
|
|
2051
2026
|
silent: true
|
|
2052
2027
|
});
|
|
2053
|
-
return steps
|
|
2028
|
+
return steps.filter((step) => {
|
|
2029
|
+
if (step.label === "sort-package-json") return targets.packages.length > 0;
|
|
2030
|
+
if (step.label === "biome") return targets.biome.length > 0;
|
|
2031
|
+
if (step.label === "oxlint") return targets.source.length > 0;
|
|
2032
|
+
if (step.label === "eslint") return targets.eslint.length > 0;
|
|
2033
|
+
return true;
|
|
2034
|
+
});
|
|
2054
2035
|
};
|
|
2055
2036
|
const captureAndParse = async ({ env, failures, label, opts, parser }) => {
|
|
2056
2037
|
const result = await runCapture({
|
|
@@ -2060,13 +2041,28 @@ const captureAndParse = async ({ env, failures, label, opts, parser }) => {
|
|
|
2060
2041
|
label
|
|
2061
2042
|
});
|
|
2062
2043
|
if (result.exitCode === 0) return [];
|
|
2063
|
-
const
|
|
2044
|
+
const byteCount = Buffer.byteLength(result.stdout);
|
|
2045
|
+
const stderrDetail = result.stderr ? `\n${result.stderr.trim()}` : "";
|
|
2046
|
+
let diagnostics;
|
|
2047
|
+
try {
|
|
2048
|
+
if (label === "eslint" || label === "biome" || label === "oxlint") readRequiredJson(result.stdout);
|
|
2049
|
+
diagnostics = parser(result);
|
|
2050
|
+
} catch (parseError) {
|
|
2051
|
+
const detail = parseError instanceof Error ? parseError.message : String(parseError);
|
|
2052
|
+
failures.push({
|
|
2053
|
+
code: result.exitCode,
|
|
2054
|
+
label,
|
|
2055
|
+
message: `Output parse error (${byteCount} bytes): ${detail}${stderrDetail}`
|
|
2056
|
+
});
|
|
2057
|
+
return [];
|
|
2058
|
+
}
|
|
2064
2059
|
if (diagnostics.length > 0) return diagnostics;
|
|
2065
2060
|
const stderr = result.stderr.trim();
|
|
2066
2061
|
const stdout = result.stdout.trim();
|
|
2067
2062
|
const stdoutFirst = stdout.split("\n", 1)[0]?.trimStart() ?? "";
|
|
2068
2063
|
const stdoutMessage = stdoutFirst.startsWith("[") || stdoutFirst.startsWith("{") ? void 0 : stdout || void 0;
|
|
2069
|
-
const
|
|
2064
|
+
const detail = stderr.length > 0 ? stderr : stdoutMessage;
|
|
2065
|
+
const message = `Output parsed to zero diagnostics (${byteCount} bytes)${detail ? `\n${detail}` : ""}`;
|
|
2070
2066
|
failures.push({
|
|
2071
2067
|
code: result.exitCode,
|
|
2072
2068
|
label,
|
|
@@ -2074,13 +2070,13 @@ const captureAndParse = async ({ env, failures, label, opts, parser }) => {
|
|
|
2074
2070
|
});
|
|
2075
2071
|
return [];
|
|
2076
2072
|
};
|
|
2077
|
-
const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failures, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson }) => {
|
|
2073
|
+
const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failures, oxlintBin, oxlintIgnorePatterns, prettierBin, prettierMarkdownTargets, sortPkgJson, targets }) => {
|
|
2078
2074
|
const oxlintCliAllow = [...OXLINT_CLI_ALLOW.flatMap((r) => ["--allow", r]), ...oxlintIgnorePatterns.flatMap((p) => ["--ignore-pattern", p])];
|
|
2079
2075
|
const allDiagnostics = [];
|
|
2080
2076
|
const push = (d) => {
|
|
2081
2077
|
if (d.length > 0) allDiagnostics.push(...d);
|
|
2082
2078
|
};
|
|
2083
|
-
push(await captureAndParse({
|
|
2079
|
+
if (targets.packages.length > 0) push(await captureAndParse({
|
|
2084
2080
|
env,
|
|
2085
2081
|
failures,
|
|
2086
2082
|
label: "sort-package-json",
|
|
@@ -2088,15 +2084,13 @@ const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failur
|
|
|
2088
2084
|
args: [
|
|
2089
2085
|
sortPkgJson,
|
|
2090
2086
|
"--check",
|
|
2091
|
-
|
|
2092
|
-
"--ignore",
|
|
2093
|
-
"**/node_modules/**"
|
|
2087
|
+
...targets.packages
|
|
2094
2088
|
],
|
|
2095
2089
|
command: "bun"
|
|
2096
2090
|
},
|
|
2097
2091
|
parser: parseSortPackageJsonOutput
|
|
2098
2092
|
}));
|
|
2099
|
-
push(await captureAndParse({
|
|
2093
|
+
if (targets.biome.length > 0) push(await captureAndParse({
|
|
2100
2094
|
env,
|
|
2101
2095
|
failures,
|
|
2102
2096
|
label: "biome",
|
|
@@ -2106,13 +2100,14 @@ const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failur
|
|
|
2106
2100
|
"check",
|
|
2107
2101
|
"--config-path",
|
|
2108
2102
|
dir,
|
|
2109
|
-
"--reporter=json"
|
|
2103
|
+
"--reporter=json",
|
|
2104
|
+
...targets.biome
|
|
2110
2105
|
],
|
|
2111
2106
|
command: "bun"
|
|
2112
2107
|
},
|
|
2113
2108
|
parser: ({ stdout }) => parseBiomeDiagnostics({ stdout })
|
|
2114
2109
|
}));
|
|
2115
|
-
push(await captureAndParse({
|
|
2110
|
+
if (targets.source.length > 0) push(await captureAndParse({
|
|
2116
2111
|
env,
|
|
2117
2112
|
failures,
|
|
2118
2113
|
label: "oxlint",
|
|
@@ -2125,13 +2120,14 @@ const runAgentCheck = async ({ biomeBin, dir, env, eslintArgs, eslintBin, failur
|
|
|
2125
2120
|
"--no-error-on-unmatched-pattern",
|
|
2126
2121
|
"-f",
|
|
2127
2122
|
"json",
|
|
2128
|
-
...oxlintCliAllow
|
|
2123
|
+
...oxlintCliAllow,
|
|
2124
|
+
...targets.source
|
|
2129
2125
|
],
|
|
2130
2126
|
command: "bun"
|
|
2131
2127
|
},
|
|
2132
2128
|
parser: ({ stdout }) => parseOxlintDiagnostics({ stdout })
|
|
2133
2129
|
}));
|
|
2134
|
-
push(await captureAndParse({
|
|
2130
|
+
if (targets.eslint.length > 0) push(await captureAndParse({
|
|
2135
2131
|
env,
|
|
2136
2132
|
failures,
|
|
2137
2133
|
label: "eslint",
|
|
@@ -2182,30 +2178,28 @@ const dangerousToDiagnostics = (items) => items.map((d) => ({
|
|
|
2182
2178
|
linter: "forbidden-suppression",
|
|
2183
2179
|
rule: d.rule
|
|
2184
2180
|
}));
|
|
2185
|
-
const
|
|
2181
|
+
const SOURCE_EXTENSIONS = [
|
|
2182
|
+
".js",
|
|
2183
|
+
".jsx",
|
|
2184
|
+
".mjs",
|
|
2185
|
+
".cjs",
|
|
2186
|
+
".ts",
|
|
2187
|
+
".tsx",
|
|
2188
|
+
".mts",
|
|
2189
|
+
".cts"
|
|
2190
|
+
];
|
|
2186
2191
|
const PRETTIER_EXTENSIONS = [
|
|
2187
2192
|
".md",
|
|
2188
2193
|
".yml",
|
|
2189
2194
|
".yaml"
|
|
2190
2195
|
];
|
|
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
|
-
};
|
|
2196
|
+
const hasExtension = (path, extensions) => extensions.some((ext) => path.endsWith(ext));
|
|
2197
|
+
const createLintTargets = (files) => ({
|
|
2198
|
+
biome: files.map((p) => joinPath(cwd, p)),
|
|
2199
|
+
eslint: files.map((p) => joinPath(cwd, p)),
|
|
2200
|
+
packages: files.filter((p) => p === "package.json" || p.endsWith("/package.json")).map((p) => escapeGlobPath(joinPath(cwd, p))),
|
|
2201
|
+
source: files.filter((p) => hasExtension(p, SOURCE_EXTENSIONS)).map((p) => joinPath(cwd, p))
|
|
2202
|
+
});
|
|
2209
2203
|
const throwAgentResults = ({ diagnostics, failures }) => {
|
|
2210
2204
|
if (diagnostics.length === 0 && failures.length === 0) return;
|
|
2211
2205
|
const grouped = aggregate({ diagnostics });
|
|
@@ -2413,28 +2407,25 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2413
2407
|
isIgnored,
|
|
2414
2408
|
mode: "fix"
|
|
2415
2409
|
});
|
|
2416
|
-
const
|
|
2410
|
+
const allGitFiles = (await listCompactFiles({
|
|
2411
|
+
env,
|
|
2412
|
+
root: cwd
|
|
2413
|
+
})).filter((one) => !isIgnored(one));
|
|
2414
|
+
const targets = createLintTargets(allGitFiles);
|
|
2415
|
+
const eslintArgs = [
|
|
2416
|
+
"--config",
|
|
2417
|
+
joinPath(dir, "eslint.generated.mjs"),
|
|
2418
|
+
"--no-warn-ignored",
|
|
2419
|
+
...targets.eslint
|
|
2420
|
+
];
|
|
2417
2421
|
const [sortPkgJson, biomeBin, oxlintBin, eslintBin, prettierBin, tombiBin, dprintBin] = await resolveAllBins();
|
|
2418
2422
|
const extraBins = {
|
|
2419
2423
|
dprint: dprintBin,
|
|
2420
2424
|
tombi: tombiBin
|
|
2421
2425
|
};
|
|
2422
2426
|
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
2427
|
const oxlintIgnorePatterns = oxlintIgnorePatternsEarly;
|
|
2432
|
-
const prettierMarkdownTargets =
|
|
2433
|
-
gitFiles: allGitFiles,
|
|
2434
|
-
gitWorkTree,
|
|
2435
|
-
isIgnored,
|
|
2436
|
-
root: cwd
|
|
2437
|
-
});
|
|
2428
|
+
const prettierMarkdownTargets = allGitFiles.filter((p) => hasExtension(p, PRETTIER_EXTENSIONS)).map((p) => joinPath(cwd, p));
|
|
2438
2429
|
const checkSteps = createCheckSteps({
|
|
2439
2430
|
biomeBin,
|
|
2440
2431
|
dir,
|
|
@@ -2444,7 +2435,8 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2444
2435
|
oxlintIgnorePatterns,
|
|
2445
2436
|
prettierBin,
|
|
2446
2437
|
prettierMarkdownTargets,
|
|
2447
|
-
sortPkgJson
|
|
2438
|
+
sortPkgJson,
|
|
2439
|
+
targets
|
|
2448
2440
|
});
|
|
2449
2441
|
const shouldComments = runtime.comments !== false;
|
|
2450
2442
|
const sourceFiles = allGitFiles.filter((f) => !isIgnored(f));
|
|
@@ -2460,7 +2452,8 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2460
2452
|
oxlintIgnorePatterns,
|
|
2461
2453
|
prettierBin,
|
|
2462
2454
|
prettierMarkdownTargets,
|
|
2463
|
-
sortPkgJson
|
|
2455
|
+
sortPkgJson,
|
|
2456
|
+
targets
|
|
2464
2457
|
},
|
|
2465
2458
|
allGitFiles,
|
|
2466
2459
|
checkSteps,
|
|
@@ -2483,7 +2476,8 @@ const runLint = async ({ command, human = false }) => {
|
|
|
2483
2476
|
oxlintIgnorePatterns,
|
|
2484
2477
|
prettierBin,
|
|
2485
2478
|
prettierMarkdownTargets,
|
|
2486
|
-
sortPkgJson
|
|
2479
|
+
sortPkgJson,
|
|
2480
|
+
targets
|
|
2487
2481
|
});
|
|
2488
2482
|
await runFixCommand({
|
|
2489
2483
|
clearFailures,
|
|
@@ -2656,16 +2650,9 @@ const formatStaleness = (issues) => {
|
|
|
2656
2650
|
//#endregion
|
|
2657
2651
|
//#region src/gate.ts
|
|
2658
2652
|
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
2653
|
const computeGreenKey = async (version) => {
|
|
2666
2654
|
if (envValue(envNoCache) === "1") return null;
|
|
2667
|
-
const files = await
|
|
2668
|
-
if (files === null) return null;
|
|
2655
|
+
const files = await listProjectFiles({ root: cwd });
|
|
2669
2656
|
return hashTree({
|
|
2670
2657
|
files,
|
|
2671
2658
|
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-C4cvEhY7.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-DDkinCyR.mjs";
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { $, Glob, env, env as bunEnv, file, spawn } from "bun";
|
|
2
|
+
import { lstat, mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
1
5
|
//#region src/constants.ts
|
|
2
6
|
const BIOME_RULES_OFF = [
|
|
3
7
|
"noBarrelFile",
|
|
@@ -352,4 +356,211 @@ const isAbsolutePath = (value) => {
|
|
|
352
356
|
return normalized.startsWith("/") || DRIVE_PATH_REGEX.test(normalized);
|
|
353
357
|
};
|
|
354
358
|
//#endregion
|
|
355
|
-
|
|
359
|
+
//#region src/core.ts
|
|
360
|
+
var CliExitError = class extends Error {
|
|
361
|
+
code;
|
|
362
|
+
name = "CliExitError";
|
|
363
|
+
constructor({ code, message }) {
|
|
364
|
+
super(message ?? "");
|
|
365
|
+
this.code = code;
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const decoder = new TextDecoder();
|
|
369
|
+
const cacheDir = "node_modules/.cache/lintmax";
|
|
370
|
+
const cwd = process.cwd();
|
|
371
|
+
const lintmaxRoot = dirnamePath(dirnamePath(fromFileUrl(import.meta.url)));
|
|
372
|
+
const PRETTIER_MD_ARGS = [
|
|
373
|
+
"--single-quote",
|
|
374
|
+
"--no-semi",
|
|
375
|
+
"--trailing-comma",
|
|
376
|
+
"none",
|
|
377
|
+
"--print-width",
|
|
378
|
+
"80",
|
|
379
|
+
"--arrow-parens",
|
|
380
|
+
"avoid",
|
|
381
|
+
"--tab-width",
|
|
382
|
+
"2",
|
|
383
|
+
"--prose-wrap",
|
|
384
|
+
"preserve"
|
|
385
|
+
];
|
|
386
|
+
const parseJsonObject = ({ text }) => {
|
|
387
|
+
const parsed = JSON.parse(text);
|
|
388
|
+
return isRecord(parsed) ? parsed : {};
|
|
389
|
+
};
|
|
390
|
+
const decodeText = (bytes) => decoder.decode(bytes ?? /* @__PURE__ */ new Uint8Array());
|
|
391
|
+
const pathExists = async ({ path }) => file(path).exists();
|
|
392
|
+
const readJson = async ({ path }) => {
|
|
393
|
+
if (!await pathExists({ path })) return {};
|
|
394
|
+
try {
|
|
395
|
+
const text = await file(path).text();
|
|
396
|
+
return parseJsonObject({ text });
|
|
397
|
+
} catch {
|
|
398
|
+
return {};
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
const readRequiredJson = (text) => JSON.parse(text);
|
|
402
|
+
const ensureDirectory = async ({ directory }) => {
|
|
403
|
+
const result = await $`mkdir -p ${directory}`.quiet().nothrow();
|
|
404
|
+
if (result.exitCode === 0) return;
|
|
405
|
+
const stderr = result.stderr.toString().trim();
|
|
406
|
+
throw new CliExitError({
|
|
407
|
+
code: result.exitCode,
|
|
408
|
+
message: stderr.length > 0 ? stderr : `Failed to create directory: ${directory}`
|
|
409
|
+
});
|
|
410
|
+
};
|
|
411
|
+
const resolvePackageJsonPath = async ({ pkg }) => {
|
|
412
|
+
try {
|
|
413
|
+
return fromFileUrl(import.meta.resolve(`${pkg}/package.json`));
|
|
414
|
+
} catch {
|
|
415
|
+
const consumerCandidate = joinPath(cwd, "node_modules", pkg, "package.json");
|
|
416
|
+
if (await pathExists({ path: consumerCandidate })) return consumerCandidate;
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
const resolveBin = async ({ bin, pkg }) => {
|
|
421
|
+
const packageJsonPath = await resolvePackageJsonPath({ pkg });
|
|
422
|
+
if (!packageJsonPath) throw new CliExitError({
|
|
423
|
+
code: 1,
|
|
424
|
+
message: `Cannot find ${pkg} — run: bun add -d ${pkg}`
|
|
425
|
+
});
|
|
426
|
+
const pkgJson = readRequiredJson(await file(packageJsonPath).text());
|
|
427
|
+
const pkgDir = dirnamePath(packageJsonPath);
|
|
428
|
+
const binPath = typeof pkgJson.bin === "string" ? pkgJson.bin : pkgJson.bin?.[bin] ?? "";
|
|
429
|
+
return joinPath(pkgDir, binPath);
|
|
430
|
+
};
|
|
431
|
+
const run = async ({ args, command, env, label, silent = false }) => {
|
|
432
|
+
const base = $`${command} ${args}`.cwd(cwd).env(env).nothrow();
|
|
433
|
+
const result = await (silent ? base.quiet() : base);
|
|
434
|
+
if (result.exitCode === 0) return;
|
|
435
|
+
if (silent) {
|
|
436
|
+
process.stderr.write(`[${label}]\n`);
|
|
437
|
+
const stdout = result.stdout.toString();
|
|
438
|
+
if (stdout.length > 0) process.stderr.write(stdout);
|
|
439
|
+
const stderr = result.stderr.toString();
|
|
440
|
+
if (stderr.length > 0) process.stderr.write(stderr);
|
|
441
|
+
}
|
|
442
|
+
throw new CliExitError({ code: result.exitCode });
|
|
443
|
+
};
|
|
444
|
+
const runCapture = async ({ args, command, env, label }) => {
|
|
445
|
+
const directory = await mkdtemp(joinPath(tmpdir(), "lintmax-output-"));
|
|
446
|
+
try {
|
|
447
|
+
const stdoutPath = joinPath(directory, "stdout");
|
|
448
|
+
const stderrPath = joinPath(directory, "stderr");
|
|
449
|
+
const outputPath = joinPath(directory, "diagnostics");
|
|
450
|
+
const outputArgs = label === "eslint" ? ["--output-file", outputPath] : [];
|
|
451
|
+
const nativeOutput = outputArgs.length > 0;
|
|
452
|
+
const captureArgs = [...args, ...outputArgs];
|
|
453
|
+
if (nativeOutput) await writeFile(outputPath, "");
|
|
454
|
+
const windows = process.platform === "win32";
|
|
455
|
+
const commandArgs = windows ? [command, ...captureArgs] : [
|
|
456
|
+
"/bin/sh",
|
|
457
|
+
"-c",
|
|
458
|
+
"stdout=$1; stderr=$2; shift 2; exec \"$@\" > \"$stdout\" 2> \"$stderr\"",
|
|
459
|
+
"lintmax-capture",
|
|
460
|
+
stdoutPath,
|
|
461
|
+
stderrPath,
|
|
462
|
+
command,
|
|
463
|
+
...captureArgs
|
|
464
|
+
];
|
|
465
|
+
const exitCode = await spawn(commandArgs, {
|
|
466
|
+
cwd,
|
|
467
|
+
env,
|
|
468
|
+
stderr: windows ? file(stderrPath) : "ignore",
|
|
469
|
+
stdout: windows ? file(stdoutPath) : "ignore",
|
|
470
|
+
timeout: 6e5
|
|
471
|
+
}).exited;
|
|
472
|
+
const [stderr, stdout] = await Promise.all([file(stderrPath).text(), file(nativeOutput ? outputPath : stdoutPath).text()]);
|
|
473
|
+
return {
|
|
474
|
+
exitCode,
|
|
475
|
+
stderr,
|
|
476
|
+
stdout
|
|
477
|
+
};
|
|
478
|
+
} finally {
|
|
479
|
+
await rm(directory, { recursive: true });
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
const envValue = (name) => bunEnv[name] ?? "";
|
|
483
|
+
const readVersion = async () => {
|
|
484
|
+
return readRequiredJson(await file(joinPath(lintmaxRoot, "package.json")).text()).version;
|
|
485
|
+
};
|
|
486
|
+
const usage = ({ version }) => {
|
|
487
|
+
process.stdout.write(`lintmax v${version}\n\n`);
|
|
488
|
+
process.stdout.write("Usage: lintmax <command>\n\n");
|
|
489
|
+
process.stdout.write("Commands:\n");
|
|
490
|
+
process.stdout.write(" fix Format, auto-fix, and gate all files (default)\n");
|
|
491
|
+
process.stdout.write(" check Verify all files without modifying (CI)\n");
|
|
492
|
+
process.stdout.write(" rules List all enabled rules\n");
|
|
493
|
+
process.stdout.write(" version Show version\n");
|
|
494
|
+
};
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/project-files.ts
|
|
497
|
+
const fixedIgnoreGlobs = ["**/node_modules/**", ...DEFAULT_SHARED_IGNORE_PATTERNS].map((pattern) => new Glob(pattern));
|
|
498
|
+
const isIncludedProjectFile = (path) => !fixedIgnoreGlobs.some((glob) => glob.match(path));
|
|
499
|
+
const hasGitDirectory = async (directory) => {
|
|
500
|
+
try {
|
|
501
|
+
await lstat(join(directory, ".git"));
|
|
502
|
+
return true;
|
|
503
|
+
} catch (error) {
|
|
504
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
|
|
505
|
+
}
|
|
506
|
+
const parent = dirname(directory);
|
|
507
|
+
return parent === directory ? false : hasGitDirectory(parent);
|
|
508
|
+
};
|
|
509
|
+
const escapeGlobPath = (path) => Array.from(path, (character) => String.raw`\*?()[]{}!+@|`.includes(character) ? `\\${character}` : character).join("");
|
|
510
|
+
const listVersionControlFiles = async ({ env: env$1 = env, root }) => {
|
|
511
|
+
if (!await hasGitDirectory(await realpath(resolve(root)))) return null;
|
|
512
|
+
const subprocess = spawn({
|
|
513
|
+
cmd: [
|
|
514
|
+
"git",
|
|
515
|
+
"-C",
|
|
516
|
+
root,
|
|
517
|
+
"ls-files",
|
|
518
|
+
"-z",
|
|
519
|
+
"--cached",
|
|
520
|
+
"--others",
|
|
521
|
+
"--exclude-standard"
|
|
522
|
+
],
|
|
523
|
+
env: env$1,
|
|
524
|
+
stderr: "pipe",
|
|
525
|
+
stdout: "pipe",
|
|
526
|
+
timeout: 3e4
|
|
527
|
+
});
|
|
528
|
+
const [exitCode, stdout, stderr] = await Promise.all([
|
|
529
|
+
subprocess.exited,
|
|
530
|
+
new Response(subprocess.stdout).text(),
|
|
531
|
+
new Response(subprocess.stderr).text()
|
|
532
|
+
]);
|
|
533
|
+
if (exitCode !== 0) throw new CliExitError({
|
|
534
|
+
code: exitCode,
|
|
535
|
+
message: `Failed to list version-control files: ${stderr.trim()}`
|
|
536
|
+
});
|
|
537
|
+
return stdout.split("\0").filter((entry) => entry.length > 0);
|
|
538
|
+
};
|
|
539
|
+
const listProjectFiles = async ({ env, root }) => {
|
|
540
|
+
const entries = await listVersionControlFiles({
|
|
541
|
+
env,
|
|
542
|
+
root
|
|
543
|
+
});
|
|
544
|
+
if (entries !== null) {
|
|
545
|
+
const present = await Promise.all(entries.map(async (entry) => {
|
|
546
|
+
try {
|
|
547
|
+
const stats = await lstat(join(root, entry));
|
|
548
|
+
return stats.isFile() || stats.isSymbolicLink();
|
|
549
|
+
} catch (error) {
|
|
550
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") return false;
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
}));
|
|
554
|
+
return entries.filter((_entry, index) => present[index]).filter(isIncludedProjectFile);
|
|
555
|
+
}
|
|
556
|
+
const files = [];
|
|
557
|
+
for await (const path of new Glob("**/*").scan({
|
|
558
|
+
cwd: root,
|
|
559
|
+
dot: true,
|
|
560
|
+
followSymlinks: false,
|
|
561
|
+
onlyFiles: true
|
|
562
|
+
})) files.push(path);
|
|
563
|
+
return files.filter(isIncludedProjectFile);
|
|
564
|
+
};
|
|
565
|
+
//#endregion
|
|
566
|
+
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-C4cvEhY7.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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lintmax",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.105",
|
|
4
4
|
"description": "The #1 anti AI slop typescript tooling. Designed for coding agents, not humans.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"prepublishOnly": "bun run build",
|
|
56
56
|
"postpublish": "bun ../../tools/prune-versions.ts",
|
|
57
57
|
"smoke": "bun script/smoke.ts",
|
|
58
|
-
"test": "bun script/test-magic.ts && bun script/test-coverage.ts"
|
|
58
|
+
"test": "bun test src && bun script/test-magic.ts && bun script/test-coverage.ts"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@biomejs/biome": "latest",
|