lintmax 0.1.106 → 0.1.108
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/README.md +1 -1
- package/dist/cli.mjs +781 -582
- package/dist/eslint.d.mts +1 -3
- package/dist/eslint.mjs +65 -39
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +1 -1
- package/dist/{lintmax-types-yjUuaLkM.d.mts → lintmax-types-Dj_XPbID.d.mts} +0 -2
- package/dist/{project-files-C4cvEhY7.mjs → project-files-DkcnsKmB.mjs} +148 -95
- package/dist/{src-DDkinCyR.mjs → src-Cu2vOuEp.mjs} +212 -126
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
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
1
|
import { file, write } from "bun";
|
|
3
2
|
import { lstat } from "node:fs/promises";
|
|
4
3
|
import { join, relative } from "node:path";
|
|
5
|
-
|
|
4
|
+
import { A as normalizeObjectListInput, C as joinPath, D as findUnknownRules, E as assertOptionalString, H as OXLINT_PATTERN_RULE_OVERRIDES, I as BIOME_IGNORE_PATTERNS, L as BIOME_PATTERN_RULE_OVERRIDES, M as normalizeRulesOffInput, N as normalizeTailwindOption, P as stripPluginNamespace, R as BIOME_RULES_OFF, T as assertObject, W as SHARED_OVERRIDE_SYMBOL_KEY, b as dirnamePath, j as normalizePathListInput, k as normalizeIgnorePattern, m as readRequiredJson, n as listProjectFiles, o as cacheDir, u as ensureDirectory, w as assertJsonSerializable, x as fromFileUrl, z as DEFAULT_SHARED_IGNORE_PATTERNS } from "./project-files-DkcnsKmB.mjs";
|
|
5
|
+
// src/index.ts
|
|
6
6
|
const SHARED_OVERRIDE_KEYS = [
|
|
7
7
|
"biome",
|
|
8
8
|
"eslint",
|
|
@@ -68,12 +68,16 @@ const assertKnownOxlintRuleNames = ({ label, rules, knownRules }) => {
|
|
|
68
68
|
};
|
|
69
69
|
const groupByCategory = ({ categoryMap, ruleNames }) => {
|
|
70
70
|
const result = {};
|
|
71
|
-
|
|
71
|
+
const categorized = ruleNames.flatMap((rule) => {
|
|
72
72
|
const cat = categoryMap.get(rule);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
73
|
+
return cat ? [{
|
|
74
|
+
cat,
|
|
75
|
+
rule
|
|
76
|
+
}] : [];
|
|
77
|
+
});
|
|
78
|
+
for (const { cat, rule } of categorized) {
|
|
79
|
+
result[cat] ??= {};
|
|
80
|
+
result[cat][rule] = "off";
|
|
77
81
|
}
|
|
78
82
|
return result;
|
|
79
83
|
};
|
|
@@ -115,7 +119,7 @@ const normalizeSharedOverrides = ({ label, value }) => {
|
|
|
115
119
|
label: `${label}.${pattern}`,
|
|
116
120
|
value: rawOverride
|
|
117
121
|
});
|
|
118
|
-
for (const key of Object.keys(override)) if (
|
|
122
|
+
for (const key of Object.keys(override)) if (SHARED_OVERRIDE_KEYS.every((k) => k !== key)) throw new Error(`${label}.${pattern}.${key} is not supported. Use biome, eslint, or oxlint.`);
|
|
119
123
|
entries.push({
|
|
120
124
|
...override,
|
|
121
125
|
files: [pattern]
|
|
@@ -139,29 +143,40 @@ const collectSharedRuleOverrides = ({ ruleKey, sharedOverrides }) => {
|
|
|
139
143
|
}
|
|
140
144
|
return out;
|
|
141
145
|
};
|
|
146
|
+
const parseLinterOffOverride = ({ assertKnownRules, fileKey, index, label, override, requireOff }) => {
|
|
147
|
+
const itemLabel = requireOff ? `${label}[${index}]` : label;
|
|
148
|
+
if (requireOff && override[fileKey] === void 0) throw new Error(`${label}[${index}].${fileKey} is required`);
|
|
149
|
+
if (requireOff && override.off === void 0) throw new Error(`${label}[${index}].off is required`);
|
|
150
|
+
const rules = normalizeRulesOffInput({
|
|
151
|
+
label: `${itemLabel}.off`,
|
|
152
|
+
value: override.off
|
|
153
|
+
});
|
|
154
|
+
if (!rules) return;
|
|
155
|
+
assertKnownRules?.(rules);
|
|
156
|
+
return {
|
|
157
|
+
files: normalizePathListInput({
|
|
158
|
+
label: `${itemLabel}.${fileKey}`,
|
|
159
|
+
value: override[fileKey]
|
|
160
|
+
}),
|
|
161
|
+
rules
|
|
162
|
+
};
|
|
163
|
+
};
|
|
142
164
|
const parseLinterOffOverrides = ({ assertKnownRules, fileKey, label, requireOff = false, value }) => {
|
|
143
165
|
const out = [];
|
|
144
|
-
|
|
166
|
+
const overrides = normalizeObjectListInput({
|
|
145
167
|
label,
|
|
146
168
|
value
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
169
|
+
});
|
|
170
|
+
for (const [i, override] of overrides.entries()) {
|
|
171
|
+
const normalizedOverride = parseLinterOffOverride({
|
|
172
|
+
assertKnownRules,
|
|
173
|
+
fileKey,
|
|
174
|
+
index: i,
|
|
175
|
+
label,
|
|
176
|
+
override,
|
|
177
|
+
requireOff
|
|
154
178
|
});
|
|
155
|
-
if (
|
|
156
|
-
assertKnownRules?.(normalizedOverrideRules);
|
|
157
|
-
out.push({
|
|
158
|
-
files: normalizePathListInput({
|
|
159
|
-
label: `${itemLabel}.${fileKey}`,
|
|
160
|
-
value: override[fileKey]
|
|
161
|
-
}),
|
|
162
|
-
rules: normalizedOverrideRules
|
|
163
|
-
});
|
|
164
|
-
}
|
|
179
|
+
if (normalizedOverride) out.push(normalizedOverride);
|
|
165
180
|
}
|
|
166
181
|
return out;
|
|
167
182
|
};
|
|
@@ -374,6 +389,36 @@ const buildEslintIgnorePatterns = ({ eslintSource, userIgnorePatterns }) => merg
|
|
|
374
389
|
label: "eslint.ignores",
|
|
375
390
|
value: eslintSource.ignores
|
|
376
391
|
})] });
|
|
392
|
+
const resolveAppendEntries = (entries, eslintImportRefs) => {
|
|
393
|
+
const appendEntries = [];
|
|
394
|
+
for (const entry of entries) if ("config" in entry) appendEntries.push(entry.config);
|
|
395
|
+
else {
|
|
396
|
+
const importRefIndex = eslintImportRefs.length;
|
|
397
|
+
eslintImportRefs.push({
|
|
398
|
+
exportName: entry.name,
|
|
399
|
+
files: entry.files,
|
|
400
|
+
ignores: entry.ignores,
|
|
401
|
+
source: entry.from
|
|
402
|
+
});
|
|
403
|
+
appendEntries.push({ [ESLINT_IMPORT_MARKER_KEY]: importRefIndex });
|
|
404
|
+
}
|
|
405
|
+
return appendEntries;
|
|
406
|
+
};
|
|
407
|
+
const assembleEslintOptions = ({ eslintIgnores, eslintImportRefs, eslintSource, sharedRuleOverrides, tailwind, tsconfigRootDir }) => {
|
|
408
|
+
const eslintOptions = {
|
|
409
|
+
off: eslintSource?.off,
|
|
410
|
+
tailwind: normalizeTailwindOption({
|
|
411
|
+
label: "tailwind",
|
|
412
|
+
value: tailwind
|
|
413
|
+
}) ?? true,
|
|
414
|
+
tsconfigRootDir
|
|
415
|
+
};
|
|
416
|
+
if (eslintIgnores.length > 0) eslintOptions.ignores = eslintIgnores;
|
|
417
|
+
const appendEntries = resolveAppendEntries(eslintSource?.append ?? [], eslintImportRefs);
|
|
418
|
+
const mergedAppend = [...sharedRuleOverrides, ...appendEntries];
|
|
419
|
+
if (mergedAppend.length > 0) eslintOptions.append = mergedAppend;
|
|
420
|
+
return eslintOptions;
|
|
421
|
+
};
|
|
377
422
|
const buildEslintOptions = ({ eslintSource, sharedOverrides, tailwind, tsconfigRootDir, userIgnorePatterns }) => {
|
|
378
423
|
const eslintIgnores = buildEslintIgnorePatterns({
|
|
379
424
|
eslintSource,
|
|
@@ -388,33 +433,18 @@ const buildEslintOptions = ({ eslintSource, sharedOverrides, tailwind, tsconfigR
|
|
|
388
433
|
}));
|
|
389
434
|
const sharedOverrideAppendIndexes = sharedRuleOverrides.map((_, index) => index);
|
|
390
435
|
const eslintImportRefs = [];
|
|
391
|
-
if (eslintSource || sharedOverrides.length > 0 || tailwind !== void 0 || tsconfigRootDir !== void 0) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
for (const entry of eslintSource?.append ?? []) if ("config" in entry) appendEntries.push(entry.config);
|
|
396
|
-
else {
|
|
397
|
-
const importRefIndex = eslintImportRefs.push({
|
|
398
|
-
exportName: entry.name,
|
|
399
|
-
files: entry.files,
|
|
400
|
-
ignores: entry.ignores,
|
|
401
|
-
source: entry.from
|
|
402
|
-
});
|
|
403
|
-
appendEntries.push({ [ESLINT_IMPORT_MARKER_KEY]: importRefIndex - 1 });
|
|
404
|
-
}
|
|
405
|
-
const mergedAppend = [...sharedRuleOverrides, ...appendEntries];
|
|
406
|
-
if (mergedAppend.length > 0) eslintOptions.append = mergedAppend;
|
|
407
|
-
eslintOptions.tailwind = normalizeTailwindOption({
|
|
408
|
-
label: "tailwind",
|
|
409
|
-
value: tailwind
|
|
410
|
-
}) ?? true;
|
|
411
|
-
eslintOptions.tsconfigRootDir = tsconfigRootDir;
|
|
412
|
-
return {
|
|
436
|
+
if (eslintSource || sharedOverrides.length > 0 || tailwind !== void 0 || tsconfigRootDir !== void 0) return {
|
|
437
|
+
eslintImportRefs,
|
|
438
|
+
eslintOptions: assembleEslintOptions({
|
|
439
|
+
eslintIgnores,
|
|
413
440
|
eslintImportRefs,
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
441
|
+
eslintSource,
|
|
442
|
+
sharedRuleOverrides,
|
|
443
|
+
tailwind,
|
|
444
|
+
tsconfigRootDir
|
|
445
|
+
}),
|
|
446
|
+
sharedOverrideAppendIndexes
|
|
447
|
+
};
|
|
418
448
|
if (eslintIgnores.length === 0) return {
|
|
419
449
|
eslintImportRefs,
|
|
420
450
|
eslintOptions: void 0,
|
|
@@ -444,8 +474,7 @@ const normalizeKnownOffRules = ({ assertKnownRules, label, value }) => {
|
|
|
444
474
|
assertKnownRules?.(normalizedRules);
|
|
445
475
|
return normalizedRules;
|
|
446
476
|
};
|
|
447
|
-
const
|
|
448
|
-
const { categories, ruleMap } = await resolveBiomeSchema({ cwd });
|
|
477
|
+
const biomeOffRules = (options, ruleMap) => {
|
|
449
478
|
const allRulesOff = [...BIOME_RULES_OFF];
|
|
450
479
|
const normalizedRules = normalizeKnownOffRules({
|
|
451
480
|
assertKnownRules: (rules) => assertKnownBiomeRuleNames({
|
|
@@ -460,6 +489,9 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
460
489
|
const ruleName = stripPluginNamespace({ rule: key });
|
|
461
490
|
if (!allRulesOff.includes(ruleName)) allRulesOff.push(ruleName);
|
|
462
491
|
}
|
|
492
|
+
return allRulesOff;
|
|
493
|
+
};
|
|
494
|
+
const biomeIgnorePatterns = (options, sharedIgnorePatterns) => {
|
|
463
495
|
const ignorePatterns = [...BIOME_IGNORE_PATTERNS];
|
|
464
496
|
const mergedIgnorePatterns = mergeIgnorePatternGroups({ groups: [sharedIgnorePatterns, options?.ignores === void 0 ? void 0 : normalizePathListInput({
|
|
465
497
|
label: "biome.ignores",
|
|
@@ -469,6 +501,9 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
469
501
|
const negated = normalizeBiomeIgnorePattern({ pattern });
|
|
470
502
|
if (!ignorePatterns.includes(negated)) ignorePatterns.push(negated);
|
|
471
503
|
}
|
|
504
|
+
return ignorePatterns;
|
|
505
|
+
};
|
|
506
|
+
const biomeOverrides = ({ allRulesOff, options, ruleMap }) => {
|
|
472
507
|
const overrides = [{
|
|
473
508
|
css: { parser: { tailwindDirectives: true } },
|
|
474
509
|
includes: ["**"],
|
|
@@ -502,7 +537,7 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
502
537
|
ruleNames: override.rules
|
|
503
538
|
}) }
|
|
504
539
|
});
|
|
505
|
-
|
|
540
|
+
const userOverrides = normalizeLinterOffOverrides({
|
|
506
541
|
assertKnownRules: (rules) => assertKnownBiomeRuleNames({
|
|
507
542
|
categoryMap: ruleMap,
|
|
508
543
|
label: "biome.overrides.off",
|
|
@@ -511,13 +546,25 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
511
546
|
fileKey: "includes",
|
|
512
547
|
label: "biome.overrides",
|
|
513
548
|
value: options?.overrides
|
|
514
|
-
})
|
|
549
|
+
});
|
|
550
|
+
for (const override of userOverrides) overrides.push({
|
|
515
551
|
includes: override.files,
|
|
516
552
|
linter: { rules: groupByCategory({
|
|
517
553
|
categoryMap: ruleMap,
|
|
518
554
|
ruleNames: extractRuleNames(override.rules)
|
|
519
555
|
}) }
|
|
520
556
|
});
|
|
557
|
+
return overrides;
|
|
558
|
+
};
|
|
559
|
+
const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
560
|
+
const { categories, ruleMap } = await resolveBiomeSchema({ cwd });
|
|
561
|
+
const allRulesOff = biomeOffRules(options, ruleMap);
|
|
562
|
+
const ignorePatterns = biomeIgnorePatterns(options, sharedIgnorePatterns);
|
|
563
|
+
const overrides = biomeOverrides({
|
|
564
|
+
allRulesOff,
|
|
565
|
+
options,
|
|
566
|
+
ruleMap
|
|
567
|
+
});
|
|
521
568
|
return {
|
|
522
569
|
$schema: "https://biomejs.dev/schemas/latest/schema.json",
|
|
523
570
|
assist: { actions: { source: { organizeImports: "off" } } },
|
|
@@ -562,30 +609,11 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
562
609
|
},
|
|
563
610
|
rules: Object.fromEntries(categories.map((c) => [c, "error"]))
|
|
564
611
|
},
|
|
565
|
-
overrides
|
|
612
|
+
overrides,
|
|
613
|
+
yaml: { formatter: { quoteStyle: "single" } }
|
|
566
614
|
};
|
|
567
615
|
};
|
|
568
|
-
const
|
|
569
|
-
const base = readRequiredJson(await file(joinPath(pkgRoot, "oxlintrc.json")).text());
|
|
570
|
-
const knownRules = /* @__PURE__ */ new Set([
|
|
571
|
-
...Object.keys(base.rules),
|
|
572
|
-
...(base.overrides ?? []).flatMap((override) => Object.keys(override.rules)),
|
|
573
|
-
...OXLINT_PATTERN_RULE_OVERRIDES.flatMap((override) => Object.keys(override.rules))
|
|
574
|
-
]);
|
|
575
|
-
const mergedIgnorePatterns = mergeIgnorePatternGroups({ groups: [sharedIgnorePatterns, options?.ignores === void 0 ? void 0 : normalizePathListInput({
|
|
576
|
-
label: "oxlint.ignores",
|
|
577
|
-
value: options.ignores
|
|
578
|
-
})] });
|
|
579
|
-
base.overrides ??= [];
|
|
580
|
-
for (const override of OXLINT_PATTERN_RULE_OVERRIDES) base.overrides.push({
|
|
581
|
-
files: [...override.files],
|
|
582
|
-
rules: { ...override.rules }
|
|
583
|
-
});
|
|
584
|
-
if (mergedIgnorePatterns.length > 0) {
|
|
585
|
-
base.ignorePatterns ??= [];
|
|
586
|
-
for (const pattern of mergedIgnorePatterns) if (!base.ignorePatterns.includes(pattern)) base.ignorePatterns.push(pattern);
|
|
587
|
-
}
|
|
588
|
-
if (!options) return base;
|
|
616
|
+
const applyOxlintOptions = (base, options, knownRules) => {
|
|
589
617
|
const normalizedRules = normalizeKnownOffRules({
|
|
590
618
|
assertKnownRules: (rules) => assertKnownOxlintRuleNames({
|
|
591
619
|
knownRules,
|
|
@@ -596,7 +624,7 @@ const createOxlintConfig = async ({ options, sharedIgnorePatterns }) => {
|
|
|
596
624
|
value: options.off
|
|
597
625
|
});
|
|
598
626
|
if (normalizedRules) for (const [key, value] of Object.entries(normalizedRules)) base.rules[key] = value;
|
|
599
|
-
|
|
627
|
+
const userOverrides = normalizeLinterOffOverrides({
|
|
600
628
|
assertKnownRules: (rules) => assertKnownOxlintRuleNames({
|
|
601
629
|
knownRules,
|
|
602
630
|
label: "oxlint.overrides.off",
|
|
@@ -605,10 +633,37 @@ const createOxlintConfig = async ({ options, sharedIgnorePatterns }) => {
|
|
|
605
633
|
fileKey: "files",
|
|
606
634
|
label: "oxlint.overrides",
|
|
607
635
|
value: options.overrides
|
|
608
|
-
})
|
|
636
|
+
});
|
|
637
|
+
for (const override of userOverrides) base.overrides?.push({
|
|
609
638
|
files: override.files,
|
|
610
639
|
rules: override.rules
|
|
611
640
|
});
|
|
641
|
+
};
|
|
642
|
+
const applyOxlintDefaults = (base, options, sharedIgnorePatterns) => {
|
|
643
|
+
const mergedIgnorePatterns = mergeIgnorePatternGroups({ groups: [sharedIgnorePatterns, options?.ignores === void 0 ? void 0 : normalizePathListInput({
|
|
644
|
+
label: "oxlint.ignores",
|
|
645
|
+
value: options.ignores
|
|
646
|
+
})] });
|
|
647
|
+
base.overrides ??= [];
|
|
648
|
+
for (const override of OXLINT_PATTERN_RULE_OVERRIDES) base.overrides.push({
|
|
649
|
+
files: [...override.files],
|
|
650
|
+
rules: { ...override.rules }
|
|
651
|
+
});
|
|
652
|
+
if (mergedIgnorePatterns.length > 0) {
|
|
653
|
+
base.ignorePatterns ??= [];
|
|
654
|
+
for (const pattern of mergedIgnorePatterns) if (!base.ignorePatterns.includes(pattern)) base.ignorePatterns.push(pattern);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
const createOxlintConfig = async ({ options, sharedIgnorePatterns }) => {
|
|
658
|
+
const base = readRequiredJson(await file(joinPath(pkgRoot, "oxlintrc.json")).text());
|
|
659
|
+
const knownRules = /* @__PURE__ */ new Set([
|
|
660
|
+
...Object.keys(base.rules),
|
|
661
|
+
...(base.overrides ?? []).flatMap((override) => Object.keys(override.rules)),
|
|
662
|
+
...OXLINT_PATTERN_RULE_OVERRIDES.flatMap((override) => Object.keys(override.rules))
|
|
663
|
+
]);
|
|
664
|
+
applyOxlintDefaults(base, options, sharedIgnorePatterns);
|
|
665
|
+
if (!options) return base;
|
|
666
|
+
applyOxlintOptions(base, options, knownRules);
|
|
612
667
|
return base;
|
|
613
668
|
};
|
|
614
669
|
const resolveSyncImportSource = ({ cwd, dir, source }) => {
|
|
@@ -627,45 +682,11 @@ const discoverSymlinkPatterns = async ({ root }) => {
|
|
|
627
682
|
}
|
|
628
683
|
}));
|
|
629
684
|
const out = [];
|
|
630
|
-
|
|
685
|
+
const indexedEntries = entries.entries();
|
|
686
|
+
for (const [index, entry] of indexedEntries) if (symlinkFlags[index]) out.push(entry);
|
|
631
687
|
return out;
|
|
632
688
|
};
|
|
633
|
-
const
|
|
634
|
-
const { biome, eslint, oxlint, sharedOverrides, tailwind, topLevelIgnores, tsconfigRootDir } = validateSyncOptions({ options });
|
|
635
|
-
const cwd = process.cwd();
|
|
636
|
-
const dir = joinPath(cwd, cacheDir);
|
|
637
|
-
const userIgnorePatterns = buildUserIgnorePatterns({ topLevelIgnores });
|
|
638
|
-
const symlinkIgnorePatterns = await discoverSymlinkPatterns({ root: cwd });
|
|
639
|
-
const sharedIgnorePatterns = mergeIgnorePatternGroups({ groups: [
|
|
640
|
-
DEFAULT_SHARED_IGNORE_PATTERNS,
|
|
641
|
-
symlinkIgnorePatterns,
|
|
642
|
-
userIgnorePatterns
|
|
643
|
-
] });
|
|
644
|
-
const biomeOptions = buildBiomeOptions({
|
|
645
|
-
biomeSource: biome,
|
|
646
|
-
sharedOverrides
|
|
647
|
-
});
|
|
648
|
-
const oxlintOptions = buildOxlintOptions({
|
|
649
|
-
oxlintSource: oxlint,
|
|
650
|
-
sharedOverrides
|
|
651
|
-
});
|
|
652
|
-
const { eslintImportRefs, eslintOptions, sharedOverrideAppendIndexes } = buildEslintOptions({
|
|
653
|
-
eslintSource: eslint,
|
|
654
|
-
sharedOverrides,
|
|
655
|
-
tailwind,
|
|
656
|
-
tsconfigRootDir,
|
|
657
|
-
userIgnorePatterns
|
|
658
|
-
});
|
|
659
|
-
await ensureDirectory({ directory: dir });
|
|
660
|
-
const biomeConfig = await createBiomeConfig({
|
|
661
|
-
cwd,
|
|
662
|
-
options: biomeOptions,
|
|
663
|
-
sharedIgnorePatterns
|
|
664
|
-
});
|
|
665
|
-
const oxlintConfig = await createOxlintConfig({
|
|
666
|
-
options: oxlintOptions,
|
|
667
|
-
sharedIgnorePatterns
|
|
668
|
-
});
|
|
689
|
+
const buildEslintModule = ({ cwd, dir, eslintImportRefs, eslintOptions, sharedOverrideAppendIndexes }) => {
|
|
669
690
|
const normalizedImportRefs = eslintImportRefs.map((importRef) => ({
|
|
670
691
|
exportName: importRef.exportName,
|
|
671
692
|
files: importRef.files,
|
|
@@ -679,8 +700,9 @@ const sync = async (options) => {
|
|
|
679
700
|
const importStatements = normalizedImportRefs.map((importRef, index) => `import * as __lintmaxAppendImport${index} from ${JSON.stringify(importRef.source)}`).join("\n");
|
|
680
701
|
const importEntries = normalizedImportRefs.map((importRef, index) => [
|
|
681
702
|
` { exportName: ${JSON.stringify(importRef.exportName)}, `,
|
|
682
|
-
`files: ${JSON.stringify(importRef.files
|
|
683
|
-
`ignores: ${JSON.stringify(importRef.ignores
|
|
703
|
+
`files: ${importRef.files === void 0 ? "undefined" : JSON.stringify(importRef.files)}, `,
|
|
704
|
+
`ignores: ${importRef.ignores === void 0 ? "undefined" : JSON.stringify(importRef.ignores)}, `,
|
|
705
|
+
`module: __lintmaxAppendImport${index} }`
|
|
684
706
|
].join("")).join(",\n");
|
|
685
707
|
const importMarkerKey = JSON.stringify(ESLINT_IMPORT_MARKER_KEY);
|
|
686
708
|
const sharedOverrideSymbolKey = JSON.stringify(SHARED_OVERRIDE_SYMBOL_KEY);
|
|
@@ -714,21 +736,86 @@ for (const entry of options.append ?? []) {
|
|
|
714
736
|
options.append = normalizedAppend
|
|
715
737
|
`;
|
|
716
738
|
const importStatementsBlock = importStatements.length > 0 ? `${importStatements}\n` : "";
|
|
717
|
-
|
|
739
|
+
return eslintOptions ? `${importStatementsBlock}import { eslint } from 'lintmax/eslint'
|
|
718
740
|
const options = ${JSON.stringify(eslintOptions)}
|
|
719
741
|
for (const index of ${JSON.stringify(sharedOverrideAppendIndexes)}) {
|
|
720
742
|
const entry = options.append?.[index]
|
|
721
743
|
if (entry && typeof entry === 'object') entry[Symbol.for(${sharedOverrideSymbolKey})] = true
|
|
722
744
|
}${importExpansion}export default await eslint(options)
|
|
723
745
|
` : "export { default } from 'lintmax/eslint'\n";
|
|
746
|
+
};
|
|
747
|
+
const prepareSyncOptions = async (options, cwd) => {
|
|
748
|
+
const { biome, eslint, oxlint, sharedOverrides, tailwind, topLevelIgnores, tsconfigRootDir } = validateSyncOptions({ options });
|
|
749
|
+
const userIgnorePatterns = buildUserIgnorePatterns({ topLevelIgnores });
|
|
750
|
+
const symlinkIgnorePatterns = await discoverSymlinkPatterns({ root: cwd });
|
|
751
|
+
const sharedIgnorePatterns = mergeIgnorePatternGroups({ groups: [
|
|
752
|
+
DEFAULT_SHARED_IGNORE_PATTERNS,
|
|
753
|
+
symlinkIgnorePatterns,
|
|
754
|
+
userIgnorePatterns
|
|
755
|
+
] });
|
|
756
|
+
const biomeOptions = buildBiomeOptions({
|
|
757
|
+
biomeSource: biome,
|
|
758
|
+
sharedOverrides
|
|
759
|
+
});
|
|
760
|
+
const oxlintOptions = buildOxlintOptions({
|
|
761
|
+
oxlintSource: oxlint,
|
|
762
|
+
sharedOverrides
|
|
763
|
+
});
|
|
764
|
+
const { eslintImportRefs, eslintOptions, sharedOverrideAppendIndexes } = buildEslintOptions({
|
|
765
|
+
eslintSource: eslint,
|
|
766
|
+
sharedOverrides,
|
|
767
|
+
tailwind,
|
|
768
|
+
tsconfigRootDir,
|
|
769
|
+
userIgnorePatterns
|
|
770
|
+
});
|
|
771
|
+
return {
|
|
772
|
+
biomeOptions,
|
|
773
|
+
eslintImportRefs,
|
|
774
|
+
eslintOptions,
|
|
775
|
+
oxlintOptions,
|
|
776
|
+
sharedIgnorePatterns,
|
|
777
|
+
sharedOverrideAppendIndexes
|
|
778
|
+
};
|
|
779
|
+
};
|
|
780
|
+
const writeSyncConfigs = async ({ biomeConfig, comments, compact, dir, eslintConfig, oxlintConfig }) => {
|
|
724
781
|
const runtimeConfig = {
|
|
725
|
-
comments
|
|
726
|
-
compact
|
|
782
|
+
comments,
|
|
783
|
+
compact
|
|
727
784
|
};
|
|
728
|
-
await write(joinPath(dir, "biome.json"), `${JSON.stringify(biomeConfig,
|
|
729
|
-
await write(joinPath(dir, ".oxlintrc.json"), `${JSON.stringify(oxlintConfig,
|
|
785
|
+
await write(joinPath(dir, "biome.json"), `${JSON.stringify(biomeConfig, void 0, 2)}\n`);
|
|
786
|
+
await write(joinPath(dir, ".oxlintrc.json"), `${JSON.stringify(oxlintConfig, void 0, 2)}\n`);
|
|
730
787
|
await write(joinPath(dir, "eslint.generated.mjs"), eslintConfig);
|
|
731
|
-
await write(joinPath(dir, "lintmax.json"), `${JSON.stringify(runtimeConfig,
|
|
788
|
+
await write(joinPath(dir, "lintmax.json"), `${JSON.stringify(runtimeConfig, void 0, 2)}\n`);
|
|
789
|
+
};
|
|
790
|
+
const sync = async (options) => {
|
|
791
|
+
const cwd = process.cwd();
|
|
792
|
+
const dir = joinPath(cwd, cacheDir);
|
|
793
|
+
const { biomeOptions, eslintImportRefs, eslintOptions, oxlintOptions, sharedIgnorePatterns, sharedOverrideAppendIndexes } = await prepareSyncOptions(options, cwd);
|
|
794
|
+
await ensureDirectory({ directory: dir });
|
|
795
|
+
const biomeConfig = await createBiomeConfig({
|
|
796
|
+
cwd,
|
|
797
|
+
options: biomeOptions,
|
|
798
|
+
sharedIgnorePatterns
|
|
799
|
+
});
|
|
800
|
+
const oxlintConfig = await createOxlintConfig({
|
|
801
|
+
options: oxlintOptions,
|
|
802
|
+
sharedIgnorePatterns
|
|
803
|
+
});
|
|
804
|
+
const eslintConfig = buildEslintModule({
|
|
805
|
+
cwd,
|
|
806
|
+
dir,
|
|
807
|
+
eslintImportRefs,
|
|
808
|
+
eslintOptions,
|
|
809
|
+
sharedOverrideAppendIndexes
|
|
810
|
+
});
|
|
811
|
+
await writeSyncConfigs({
|
|
812
|
+
biomeConfig,
|
|
813
|
+
comments: options?.comments !== false,
|
|
814
|
+
compact: options?.compact !== false,
|
|
815
|
+
dir,
|
|
816
|
+
eslintConfig,
|
|
817
|
+
oxlintConfig
|
|
818
|
+
});
|
|
732
819
|
};
|
|
733
820
|
const eslintImport = ({ files, from, ignores, name }) => {
|
|
734
821
|
const entry = {
|
|
@@ -744,5 +831,4 @@ const defineConfig = (options) => {
|
|
|
744
831
|
validateSyncOptions({ options });
|
|
745
832
|
return options;
|
|
746
833
|
};
|
|
747
|
-
//#endregion
|
|
748
834
|
export { eslintImport as n, sync as r, defineConfig as t };
|