lintmax 0.1.102 → 0.1.103
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 +56 -27
- package/dist/index.mjs +1 -1
- package/dist/{src-DlUsR71K.mjs → src-gPY63Hnk.mjs} +53 -7
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { S as OXLINT_CLI_ALLOW, b as DEFAULT_SHARED_IGNORE_PATTERNS, i as joinPath, l as isRecord, n as fromFileUrl, t as dirnamePath, w as PARSE_DIALECTS, x as ESLINT_TEST_FILE_PATTERNS } from "./path-Dgmf8CJi.mjs";
|
|
3
|
-
import { _ as resolveBin, a as PRETTIER_MD_ARGS, b as usage, c as cwd, d as envValue, f as lintmaxRoot, g as readVersion, h as readRequiredJson, i as CliExitError, l as decodeText, m as readJson, o as bunEnv, p as pathExists, r as sync, s as cacheDir, u as ensureDirectory, v as run, y as runCapture } from "./src-
|
|
3
|
+
import { _ as resolveBin, a as PRETTIER_MD_ARGS, b as usage, c as cwd, d as envValue, f as lintmaxRoot, g as readVersion, h as readRequiredJson, i as CliExitError, l as decodeText, m as readJson, o as bunEnv, p as pathExists, r as sync, s as cacheDir, u as ensureDirectory, v as run, y as runCapture } from "./src-gPY63Hnk.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
|
|
@@ -543,10 +544,8 @@ const formatRulesHuman = (rules) => {
|
|
|
543
544
|
};
|
|
544
545
|
//#endregion
|
|
545
546
|
//#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;
|
|
547
|
+
const eslintLineRe = /^(?<prefix>\s*(?:\/\/|\/\*)\s*eslint-disable(?:-next-line)?\s+)(?<rules>\S(?:[^*]*[^\s*])?)(?<suffix>\s*\*\/)?$/v;
|
|
548
|
+
const oxlintLineRe = /^(?<prefix>\s*(?:\/\/|\/\*)\s*oxlint-disable(?:-next-line)?\s+)(?<rules>\S(?:[^*]*[^\s*])?)(?<suffix>\s*\*\/)?$/v;
|
|
550
549
|
const biomeLineRe = /^\s*(?:\/\/|\/\*\*)\s*biome-ignore(?:-all)?\s+(?<rule>[\w\/]+)/v;
|
|
551
550
|
const OXLINT_PREFIXES = [
|
|
552
551
|
"eslint",
|
|
@@ -643,10 +642,10 @@ const loadOxlintOffRules = async () => {
|
|
|
643
642
|
}
|
|
644
643
|
return off;
|
|
645
644
|
};
|
|
646
|
-
const buildActiveRuleSet = async () => {
|
|
645
|
+
const buildActiveRuleSet = async ({ excludeEslint = false } = {}) => {
|
|
647
646
|
const rules = await extractAllRules();
|
|
648
647
|
const active = /* @__PURE__ */ new Set();
|
|
649
|
-
for (const r of rules) {
|
|
648
|
+
for (const r of rules.filter((rule) => !excludeEslint || rule.linter !== "eslint")) {
|
|
650
649
|
active.add(r.rule);
|
|
651
650
|
for (const v of normalizeRule(r.rule)) active.add(v);
|
|
652
651
|
}
|
|
@@ -679,9 +678,9 @@ const splitDirective = (str) => {
|
|
|
679
678
|
};
|
|
680
679
|
};
|
|
681
680
|
const processMultiRuleLine = ({ active, isOxlint, line, match, oxlintOff, result }) => {
|
|
682
|
-
const prefix = match
|
|
683
|
-
const rulesStr = match
|
|
684
|
-
const suffix = match
|
|
681
|
+
const prefix = match.prefix ?? "";
|
|
682
|
+
const rulesStr = match.rules ?? "";
|
|
683
|
+
const suffix = match.suffix ?? "";
|
|
685
684
|
const { reason, rules } = splitDirective(rulesStr);
|
|
686
685
|
const kept = rules.filter((r) => isRuleActive(r, active, isOxlint ? oxlintOff : void 0));
|
|
687
686
|
if (kept.length === 0) return rules.length;
|
|
@@ -693,15 +692,19 @@ const processMultiRuleLine = ({ active, isOxlint, line, match, oxlintOff, result
|
|
|
693
692
|
return 0;
|
|
694
693
|
};
|
|
695
694
|
/** 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 }) => {
|
|
695
|
+
const processIgnoreLine = ({ active, eslintActive, line, oxlintOff, result }) => {
|
|
697
696
|
eslintLineRe.lastIndex = 0;
|
|
698
697
|
oxlintLineRe.lastIndex = 0;
|
|
699
698
|
biomeLineRe.lastIndex = 0;
|
|
700
699
|
const eslintMatch = eslintLineRe.exec(line);
|
|
701
700
|
if (eslintMatch) return processMultiRuleLine({
|
|
702
|
-
active,
|
|
701
|
+
active: eslintActive ?? active,
|
|
703
702
|
line,
|
|
704
|
-
match:
|
|
703
|
+
match: {
|
|
704
|
+
prefix: eslintMatch.groups?.prefix,
|
|
705
|
+
rules: eslintMatch.groups?.rules,
|
|
706
|
+
suffix: eslintMatch.groups?.suffix
|
|
707
|
+
},
|
|
705
708
|
result
|
|
706
709
|
});
|
|
707
710
|
const oxlintMatch = oxlintLineRe.exec(line);
|
|
@@ -709,7 +712,11 @@ const processIgnoreLine = ({ active, line, oxlintOff, result }) => {
|
|
|
709
712
|
active,
|
|
710
713
|
isOxlint: true,
|
|
711
714
|
line,
|
|
712
|
-
match:
|
|
715
|
+
match: {
|
|
716
|
+
prefix: oxlintMatch.groups?.prefix,
|
|
717
|
+
rules: oxlintMatch.groups?.rules,
|
|
718
|
+
suffix: oxlintMatch.groups?.suffix
|
|
719
|
+
},
|
|
713
720
|
oxlintOff,
|
|
714
721
|
result
|
|
715
722
|
});
|
|
@@ -718,7 +725,7 @@ const processIgnoreLine = ({ active, line, oxlintOff, result }) => {
|
|
|
718
725
|
result.push(line);
|
|
719
726
|
return 0;
|
|
720
727
|
};
|
|
721
|
-
const cleanFileIgnores = async (filePath, active, oxlintOff) => {
|
|
728
|
+
const cleanFileIgnores = async (filePath, active, { eslintActive, oxlintOff } = {}) => {
|
|
722
729
|
const f = file(filePath);
|
|
723
730
|
if (!await f.exists()) return 0;
|
|
724
731
|
const lines = (await f.text()).split("\n");
|
|
@@ -726,6 +733,7 @@ const cleanFileIgnores = async (filePath, active, oxlintOff) => {
|
|
|
726
733
|
let removed = 0;
|
|
727
734
|
for (const line of lines) removed += processIgnoreLine({
|
|
728
735
|
active,
|
|
736
|
+
eslintActive,
|
|
729
737
|
line,
|
|
730
738
|
oxlintOff,
|
|
731
739
|
result
|
|
@@ -733,21 +741,42 @@ const cleanFileIgnores = async (filePath, active, oxlintOff) => {
|
|
|
733
741
|
if (removed > 0) await write(filePath, result.join("\n"));
|
|
734
742
|
return removed;
|
|
735
743
|
};
|
|
744
|
+
const buildEslintActiveRuleSet = (config, active) => {
|
|
745
|
+
const eslintActive = new Set(active);
|
|
746
|
+
if (typeof config !== "object" || config === null || !("rules" in config)) return eslintActive;
|
|
747
|
+
const rules = config.rules;
|
|
748
|
+
if (typeof rules !== "object" || rules === null) return eslintActive;
|
|
749
|
+
for (const [rule, value] of Object.entries(rules)) {
|
|
750
|
+
const severity = Array.isArray(value) ? value[0] : value;
|
|
751
|
+
if (severity !== 0 && severity !== "off") for (const variant of normalizeRule(rule)) eslintActive.add(variant);
|
|
752
|
+
}
|
|
753
|
+
return eslintActive;
|
|
754
|
+
};
|
|
755
|
+
const cleanConfiguredFile = async ({ active, eslint, filePath, oxlintOff }) => {
|
|
756
|
+
const config = await eslint.calculateConfigForFile(filePath);
|
|
757
|
+
if (!config) return 0;
|
|
758
|
+
const eslintActive = buildEslintActiveRuleSet(config, active);
|
|
759
|
+
return cleanFileIgnores(filePath, active, {
|
|
760
|
+
eslintActive,
|
|
761
|
+
oxlintOff
|
|
762
|
+
});
|
|
763
|
+
};
|
|
736
764
|
const cleanIgnores = async (filePaths) => {
|
|
737
|
-
const active = await buildActiveRuleSet();
|
|
765
|
+
const active = await buildActiveRuleSet({ excludeEslint: true });
|
|
738
766
|
const oxlintOff = await loadOxlintOffRules();
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
767
|
+
const eslint = new ESLint({
|
|
768
|
+
cwd: process.cwd(),
|
|
769
|
+
overrideConfigFile: joinPath(process.cwd(), cacheDir, "eslint.generated.mjs")
|
|
770
|
+
});
|
|
771
|
+
const counts = await Promise.all(filePaths.map(async (filePath) => cleanConfiguredFile({
|
|
772
|
+
active,
|
|
773
|
+
eslint,
|
|
774
|
+
filePath,
|
|
775
|
+
oxlintOff
|
|
776
|
+
})));
|
|
748
777
|
return {
|
|
749
|
-
cleaned,
|
|
750
|
-
files
|
|
778
|
+
cleaned: counts.reduce((total, count) => total + count, 0),
|
|
779
|
+
files: filePaths.filter((_, index) => (counts[index] ?? 0) > 0)
|
|
751
780
|
};
|
|
752
781
|
};
|
|
753
782
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as eslintImport, r as sync, t as defineConfig } from "./src-
|
|
1
|
+
import { n as eslintImport, r as sync, t as defineConfig } from "./src-gPY63Hnk.mjs";
|
|
2
2
|
export { defineConfig, eslintImport, sync };
|
|
@@ -585,10 +585,16 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
585
585
|
}) }
|
|
586
586
|
}, {
|
|
587
587
|
includes: ["**"],
|
|
588
|
-
linter: { rules: { nursery: {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
588
|
+
linter: { rules: { nursery: {
|
|
589
|
+
useLayeredStyles: {
|
|
590
|
+
level: "error",
|
|
591
|
+
options: { requireImportLayers: false }
|
|
592
|
+
},
|
|
593
|
+
useReactFunctionComponentDefinition: {
|
|
594
|
+
level: "error",
|
|
595
|
+
options: { namedComponents: "arrowFunction" }
|
|
596
|
+
}
|
|
597
|
+
} } }
|
|
592
598
|
}];
|
|
593
599
|
for (const override of BIOME_PATTERN_RULE_OVERRIDES) overrides.push({
|
|
594
600
|
includes: [...override.includes],
|
|
@@ -773,10 +779,50 @@ const sync = async (options) => {
|
|
|
773
779
|
})
|
|
774
780
|
}));
|
|
775
781
|
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
|
-
|
|
782
|
+
const importEntries = normalizedImportRefs.map((importRef, index) => [
|
|
783
|
+
` { exportName: ${JSON.stringify(importRef.exportName)}, `,
|
|
784
|
+
`files: ${JSON.stringify(importRef.files ?? null)}, `,
|
|
785
|
+
`ignores: ${JSON.stringify(importRef.ignores ?? null)}, module: __lintmaxAppendImport${index} }`
|
|
786
|
+
].join("")).join(",\n");
|
|
787
|
+
const importMarkerKey = JSON.stringify(ESLINT_IMPORT_MARKER_KEY);
|
|
788
|
+
const sharedOverrideSymbolKey = JSON.stringify(SHARED_OVERRIDE_SYMBOL_KEY);
|
|
789
|
+
const importExpansion = normalizedImportRefs.length === 0 ? "" : `
|
|
790
|
+
const appendImports = [
|
|
791
|
+
${importEntries}
|
|
792
|
+
]
|
|
793
|
+
const normalizedAppend = []
|
|
794
|
+
for (const entry of options.append ?? []) {
|
|
795
|
+
if (entry && typeof entry === 'object' && !Array.isArray(entry) && ${importMarkerKey} in entry) {
|
|
796
|
+
const importIndex = entry[${importMarkerKey}]
|
|
797
|
+
if (typeof importIndex !== 'number' || !Number.isInteger(importIndex))
|
|
798
|
+
throw new Error('Invalid eslint import marker index in generated config')
|
|
799
|
+
const importRef = appendImports[importIndex]
|
|
800
|
+
if (!importRef) throw new Error(\`Missing eslint import ref for index \${importIndex}\`)
|
|
801
|
+
const imported = importRef.module[importRef.exportName]
|
|
802
|
+
const importedEntries = Array.isArray(imported) ? imported : [imported]
|
|
803
|
+
for (const importedEntry of importedEntries) {
|
|
804
|
+
if (!importedEntry || typeof importedEntry !== 'object' || Array.isArray(importedEntry))
|
|
805
|
+
throw new Error(\`Imported eslint append from \${importRef.exportName} must resolve to config object(s)\`)
|
|
806
|
+
normalizedAppend.push({
|
|
807
|
+
...importedEntry,
|
|
808
|
+
...(Array.isArray(importRef.files) ? { files: [...importRef.files] } : {}),
|
|
809
|
+
...(Array.isArray(importRef.ignores) ? { ignores: [...importRef.ignores] } : {})
|
|
810
|
+
})
|
|
811
|
+
}
|
|
812
|
+
continue
|
|
813
|
+
}
|
|
814
|
+
normalizedAppend.push(entry)
|
|
815
|
+
}
|
|
816
|
+
options.append = normalizedAppend
|
|
817
|
+
`;
|
|
778
818
|
const importStatementsBlock = importStatements.length > 0 ? `${importStatements}\n` : "";
|
|
779
|
-
const eslintConfig = eslintOptions ? `${importStatementsBlock}import { eslint } from 'lintmax/eslint'
|
|
819
|
+
const eslintConfig = eslintOptions ? `${importStatementsBlock}import { eslint } from 'lintmax/eslint'
|
|
820
|
+
const options = ${JSON.stringify(eslintOptions)}
|
|
821
|
+
for (const index of ${JSON.stringify(sharedOverrideAppendIndexes)}) {
|
|
822
|
+
const entry = options.append?.[index]
|
|
823
|
+
if (entry && typeof entry === 'object') entry[Symbol.for(${sharedOverrideSymbolKey})] = true
|
|
824
|
+
}${importExpansion}export default await eslint(options)
|
|
825
|
+
` : "export { default } from 'lintmax/eslint'\n";
|
|
780
826
|
const runtimeConfig = {
|
|
781
827
|
comments: options?.comments !== false,
|
|
782
828
|
compact: options?.compact !== false
|