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 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-DlUsR71K.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-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
- /** biome-ignore-all lint/performance/noAwaitInLoops: sequential file writes */
547
- /** biome-ignore-all lint/nursery/useNamedCaptureGroup: not needed */
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[1] ?? "";
683
- const rulesStr = match[2] ?? "";
684
- const suffix = match[3] ?? "";
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: eslintMatch,
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: oxlintMatch,
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
- let cleaned = 0;
740
- const files = [];
741
- for (const fp of filePaths) {
742
- const count = await cleanFileIgnores(fp, active, oxlintOff);
743
- if (count > 0) {
744
- cleaned += count;
745
- files.push(fp);
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-DlUsR71K.mjs";
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: { useReactFunctionComponentDefinition: {
589
- level: "error",
590
- options: { namedComponents: "arrowFunction" }
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) => ` { exportName: ${JSON.stringify(importRef.exportName)}, files: ${JSON.stringify(importRef.files ?? null)}, ignores: ${JSON.stringify(importRef.ignores ?? null)}, module: __lintmaxAppendImport${index} }`).join(",\n");
777
- const importExpansion = normalizedImportRefs.length === 0 ? "" : `\nconst appendImports = [\n${importEntries}\n]\nconst normalizedAppend = []\nfor (const entry of options.append ?? []) {\n if (entry && typeof entry === 'object' && !Array.isArray(entry) && ${JSON.stringify(ESLINT_IMPORT_MARKER_KEY)} in entry) {\n const importIndex = entry[${JSON.stringify(ESLINT_IMPORT_MARKER_KEY)}]\n if (typeof importIndex !== 'number' || !Number.isInteger(importIndex))\n throw new Error('Invalid eslint import marker index in generated config')\n const importRef = appendImports[importIndex]\n if (!importRef) throw new Error(\`Missing eslint import ref for index \${importIndex}\`)\n const imported = importRef.module[importRef.exportName]\n const importedEntries = Array.isArray(imported) ? imported : [imported]\n for (const importedEntry of importedEntries) {\n if (!importedEntry || typeof importedEntry !== 'object' || Array.isArray(importedEntry))\n throw new Error(\`Imported eslint append from \${importRef.exportName} must resolve to config object(s)\`)\n normalizedAppend.push({\n ...importedEntry,\n ...(Array.isArray(importRef.files) ? { files: [...importRef.files] } : {}),\n ...(Array.isArray(importRef.ignores) ? { ignores: [...importRef.ignores] } : {})\n })\n }\n continue\n }\n normalizedAppend.push(entry)\n}\noptions.append = normalizedAppend\n`;
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'\nconst options = ${JSON.stringify(eslintOptions)}\nfor (const index of ${JSON.stringify(sharedOverrideAppendIndexes)}) {\n const entry = options.append?.[index]\n if (entry && typeof entry === 'object') entry[Symbol.for(${JSON.stringify(SHARED_OVERRIDE_SYMBOL_KEY)})] = true\n}${importExpansion}export default await eslint(options)\n` : "export { default } from 'lintmax/eslint'\n";
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lintmax",
3
- "version": "0.1.102",
3
+ "version": "0.1.103",
4
4
  "description": "The #1 anti AI slop typescript tooling. Designed for coding agents, not humans.",
5
5
  "keywords": [
6
6
  "agent",