lintmax 0.1.106 → 0.1.107
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 +618 -497
- package/dist/eslint.d.mts +1 -3
- package/dist/eslint.mjs +64 -38
- 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-BJWR09gY.mjs} +145 -92
- package/dist/{src-DDkinCyR.mjs → src-C2vei_sO.mjs} +203 -121
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
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, l as ensureDirectory, m as readRequiredJson, n as listProjectFiles, o as cacheDir, w as assertJsonSerializable, x as fromFileUrl, z as DEFAULT_SHARED_IGNORE_PATTERNS } from "./project-files-BJWR09gY.mjs";
|
|
2
2
|
import { file, write } from "bun";
|
|
3
3
|
import { lstat } from "node:fs/promises";
|
|
4
4
|
import { join, relative } from "node:path";
|
|
5
|
-
|
|
5
|
+
// src/index.ts
|
|
6
6
|
const SHARED_OVERRIDE_KEYS = [
|
|
7
7
|
"biome",
|
|
8
8
|
"eslint",
|
|
@@ -115,7 +115,7 @@ const normalizeSharedOverrides = ({ label, value }) => {
|
|
|
115
115
|
label: `${label}.${pattern}`,
|
|
116
116
|
value: rawOverride
|
|
117
117
|
});
|
|
118
|
-
for (const key of Object.keys(override)) if (
|
|
118
|
+
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
119
|
entries.push({
|
|
120
120
|
...override,
|
|
121
121
|
files: [pattern]
|
|
@@ -139,29 +139,40 @@ const collectSharedRuleOverrides = ({ ruleKey, sharedOverrides }) => {
|
|
|
139
139
|
}
|
|
140
140
|
return out;
|
|
141
141
|
};
|
|
142
|
+
const parseLinterOffOverride = ({ assertKnownRules, fileKey, index, label, override, requireOff }) => {
|
|
143
|
+
const itemLabel = requireOff ? `${label}[${index}]` : label;
|
|
144
|
+
if (requireOff && override[fileKey] === void 0) throw new Error(`${label}[${index}].${fileKey} is required`);
|
|
145
|
+
if (requireOff && override.off === void 0) throw new Error(`${label}[${index}].off is required`);
|
|
146
|
+
const rules = normalizeRulesOffInput({
|
|
147
|
+
label: `${itemLabel}.off`,
|
|
148
|
+
value: override.off
|
|
149
|
+
});
|
|
150
|
+
if (!rules) return;
|
|
151
|
+
assertKnownRules?.(rules);
|
|
152
|
+
return {
|
|
153
|
+
files: normalizePathListInput({
|
|
154
|
+
label: `${itemLabel}.${fileKey}`,
|
|
155
|
+
value: override[fileKey]
|
|
156
|
+
}),
|
|
157
|
+
rules
|
|
158
|
+
};
|
|
159
|
+
};
|
|
142
160
|
const parseLinterOffOverrides = ({ assertKnownRules, fileKey, label, requireOff = false, value }) => {
|
|
143
161
|
const out = [];
|
|
144
|
-
|
|
162
|
+
const overrides = normalizeObjectListInput({
|
|
145
163
|
label,
|
|
146
164
|
value
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
165
|
+
});
|
|
166
|
+
for (const [i, override] of overrides.entries()) {
|
|
167
|
+
const normalizedOverride = parseLinterOffOverride({
|
|
168
|
+
assertKnownRules,
|
|
169
|
+
fileKey,
|
|
170
|
+
index: i,
|
|
171
|
+
label,
|
|
172
|
+
override,
|
|
173
|
+
requireOff
|
|
154
174
|
});
|
|
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
|
-
}
|
|
175
|
+
if (normalizedOverride) out.push(normalizedOverride);
|
|
165
176
|
}
|
|
166
177
|
return out;
|
|
167
178
|
};
|
|
@@ -374,6 +385,36 @@ const buildEslintIgnorePatterns = ({ eslintSource, userIgnorePatterns }) => merg
|
|
|
374
385
|
label: "eslint.ignores",
|
|
375
386
|
value: eslintSource.ignores
|
|
376
387
|
})] });
|
|
388
|
+
const resolveAppendEntries = (entries, eslintImportRefs) => {
|
|
389
|
+
const appendEntries = [];
|
|
390
|
+
for (const entry of entries) if ("config" in entry) appendEntries.push(entry.config);
|
|
391
|
+
else {
|
|
392
|
+
const importRefIndex = eslintImportRefs.length;
|
|
393
|
+
eslintImportRefs.push({
|
|
394
|
+
exportName: entry.name,
|
|
395
|
+
files: entry.files,
|
|
396
|
+
ignores: entry.ignores,
|
|
397
|
+
source: entry.from
|
|
398
|
+
});
|
|
399
|
+
appendEntries.push({ [ESLINT_IMPORT_MARKER_KEY]: importRefIndex });
|
|
400
|
+
}
|
|
401
|
+
return appendEntries;
|
|
402
|
+
};
|
|
403
|
+
const assembleEslintOptions = ({ eslintIgnores, eslintImportRefs, eslintSource, sharedRuleOverrides, tailwind, tsconfigRootDir }) => {
|
|
404
|
+
const eslintOptions = {
|
|
405
|
+
off: eslintSource?.off,
|
|
406
|
+
tailwind: normalizeTailwindOption({
|
|
407
|
+
label: "tailwind",
|
|
408
|
+
value: tailwind
|
|
409
|
+
}) ?? true,
|
|
410
|
+
tsconfigRootDir
|
|
411
|
+
};
|
|
412
|
+
if (eslintIgnores.length > 0) eslintOptions.ignores = eslintIgnores;
|
|
413
|
+
const appendEntries = resolveAppendEntries(eslintSource?.append ?? [], eslintImportRefs);
|
|
414
|
+
const mergedAppend = [...sharedRuleOverrides, ...appendEntries];
|
|
415
|
+
if (mergedAppend.length > 0) eslintOptions.append = mergedAppend;
|
|
416
|
+
return eslintOptions;
|
|
417
|
+
};
|
|
377
418
|
const buildEslintOptions = ({ eslintSource, sharedOverrides, tailwind, tsconfigRootDir, userIgnorePatterns }) => {
|
|
378
419
|
const eslintIgnores = buildEslintIgnorePatterns({
|
|
379
420
|
eslintSource,
|
|
@@ -388,33 +429,18 @@ const buildEslintOptions = ({ eslintSource, sharedOverrides, tailwind, tsconfigR
|
|
|
388
429
|
}));
|
|
389
430
|
const sharedOverrideAppendIndexes = sharedRuleOverrides.map((_, index) => index);
|
|
390
431
|
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 {
|
|
432
|
+
if (eslintSource || sharedOverrides.length > 0 || tailwind !== void 0 || tsconfigRootDir !== void 0) return {
|
|
433
|
+
eslintImportRefs,
|
|
434
|
+
eslintOptions: assembleEslintOptions({
|
|
435
|
+
eslintIgnores,
|
|
413
436
|
eslintImportRefs,
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
437
|
+
eslintSource,
|
|
438
|
+
sharedRuleOverrides,
|
|
439
|
+
tailwind,
|
|
440
|
+
tsconfigRootDir
|
|
441
|
+
}),
|
|
442
|
+
sharedOverrideAppendIndexes
|
|
443
|
+
};
|
|
418
444
|
if (eslintIgnores.length === 0) return {
|
|
419
445
|
eslintImportRefs,
|
|
420
446
|
eslintOptions: void 0,
|
|
@@ -444,8 +470,7 @@ const normalizeKnownOffRules = ({ assertKnownRules, label, value }) => {
|
|
|
444
470
|
assertKnownRules?.(normalizedRules);
|
|
445
471
|
return normalizedRules;
|
|
446
472
|
};
|
|
447
|
-
const
|
|
448
|
-
const { categories, ruleMap } = await resolveBiomeSchema({ cwd });
|
|
473
|
+
const biomeOffRules = (options, ruleMap) => {
|
|
449
474
|
const allRulesOff = [...BIOME_RULES_OFF];
|
|
450
475
|
const normalizedRules = normalizeKnownOffRules({
|
|
451
476
|
assertKnownRules: (rules) => assertKnownBiomeRuleNames({
|
|
@@ -460,6 +485,9 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
460
485
|
const ruleName = stripPluginNamespace({ rule: key });
|
|
461
486
|
if (!allRulesOff.includes(ruleName)) allRulesOff.push(ruleName);
|
|
462
487
|
}
|
|
488
|
+
return allRulesOff;
|
|
489
|
+
};
|
|
490
|
+
const biomeIgnorePatterns = (options, sharedIgnorePatterns) => {
|
|
463
491
|
const ignorePatterns = [...BIOME_IGNORE_PATTERNS];
|
|
464
492
|
const mergedIgnorePatterns = mergeIgnorePatternGroups({ groups: [sharedIgnorePatterns, options?.ignores === void 0 ? void 0 : normalizePathListInput({
|
|
465
493
|
label: "biome.ignores",
|
|
@@ -469,6 +497,9 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
469
497
|
const negated = normalizeBiomeIgnorePattern({ pattern });
|
|
470
498
|
if (!ignorePatterns.includes(negated)) ignorePatterns.push(negated);
|
|
471
499
|
}
|
|
500
|
+
return ignorePatterns;
|
|
501
|
+
};
|
|
502
|
+
const biomeOverrides = ({ allRulesOff, options, ruleMap }) => {
|
|
472
503
|
const overrides = [{
|
|
473
504
|
css: { parser: { tailwindDirectives: true } },
|
|
474
505
|
includes: ["**"],
|
|
@@ -502,7 +533,7 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
502
533
|
ruleNames: override.rules
|
|
503
534
|
}) }
|
|
504
535
|
});
|
|
505
|
-
|
|
536
|
+
const userOverrides = normalizeLinterOffOverrides({
|
|
506
537
|
assertKnownRules: (rules) => assertKnownBiomeRuleNames({
|
|
507
538
|
categoryMap: ruleMap,
|
|
508
539
|
label: "biome.overrides.off",
|
|
@@ -511,13 +542,25 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
511
542
|
fileKey: "includes",
|
|
512
543
|
label: "biome.overrides",
|
|
513
544
|
value: options?.overrides
|
|
514
|
-
})
|
|
545
|
+
});
|
|
546
|
+
for (const override of userOverrides) overrides.push({
|
|
515
547
|
includes: override.files,
|
|
516
548
|
linter: { rules: groupByCategory({
|
|
517
549
|
categoryMap: ruleMap,
|
|
518
550
|
ruleNames: extractRuleNames(override.rules)
|
|
519
551
|
}) }
|
|
520
552
|
});
|
|
553
|
+
return overrides;
|
|
554
|
+
};
|
|
555
|
+
const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
556
|
+
const { categories, ruleMap } = await resolveBiomeSchema({ cwd });
|
|
557
|
+
const allRulesOff = biomeOffRules(options, ruleMap);
|
|
558
|
+
const ignorePatterns = biomeIgnorePatterns(options, sharedIgnorePatterns);
|
|
559
|
+
const overrides = biomeOverrides({
|
|
560
|
+
allRulesOff,
|
|
561
|
+
options,
|
|
562
|
+
ruleMap
|
|
563
|
+
});
|
|
521
564
|
return {
|
|
522
565
|
$schema: "https://biomejs.dev/schemas/latest/schema.json",
|
|
523
566
|
assist: { actions: { source: { organizeImports: "off" } } },
|
|
@@ -562,30 +605,11 @@ const createBiomeConfig = async ({ cwd, options, sharedIgnorePatterns }) => {
|
|
|
562
605
|
},
|
|
563
606
|
rules: Object.fromEntries(categories.map((c) => [c, "error"]))
|
|
564
607
|
},
|
|
565
|
-
overrides
|
|
608
|
+
overrides,
|
|
609
|
+
yaml: { formatter: { quoteStyle: "single" } }
|
|
566
610
|
};
|
|
567
611
|
};
|
|
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;
|
|
612
|
+
const applyOxlintOptions = (base, options, knownRules) => {
|
|
589
613
|
const normalizedRules = normalizeKnownOffRules({
|
|
590
614
|
assertKnownRules: (rules) => assertKnownOxlintRuleNames({
|
|
591
615
|
knownRules,
|
|
@@ -596,7 +620,7 @@ const createOxlintConfig = async ({ options, sharedIgnorePatterns }) => {
|
|
|
596
620
|
value: options.off
|
|
597
621
|
});
|
|
598
622
|
if (normalizedRules) for (const [key, value] of Object.entries(normalizedRules)) base.rules[key] = value;
|
|
599
|
-
|
|
623
|
+
const userOverrides = normalizeLinterOffOverrides({
|
|
600
624
|
assertKnownRules: (rules) => assertKnownOxlintRuleNames({
|
|
601
625
|
knownRules,
|
|
602
626
|
label: "oxlint.overrides.off",
|
|
@@ -605,10 +629,37 @@ const createOxlintConfig = async ({ options, sharedIgnorePatterns }) => {
|
|
|
605
629
|
fileKey: "files",
|
|
606
630
|
label: "oxlint.overrides",
|
|
607
631
|
value: options.overrides
|
|
608
|
-
})
|
|
632
|
+
});
|
|
633
|
+
for (const override of userOverrides) base.overrides?.push({
|
|
609
634
|
files: override.files,
|
|
610
635
|
rules: override.rules
|
|
611
636
|
});
|
|
637
|
+
};
|
|
638
|
+
const applyOxlintDefaults = (base, options, sharedIgnorePatterns) => {
|
|
639
|
+
const mergedIgnorePatterns = mergeIgnorePatternGroups({ groups: [sharedIgnorePatterns, options?.ignores === void 0 ? void 0 : normalizePathListInput({
|
|
640
|
+
label: "oxlint.ignores",
|
|
641
|
+
value: options.ignores
|
|
642
|
+
})] });
|
|
643
|
+
base.overrides ??= [];
|
|
644
|
+
for (const override of OXLINT_PATTERN_RULE_OVERRIDES) base.overrides.push({
|
|
645
|
+
files: [...override.files],
|
|
646
|
+
rules: { ...override.rules }
|
|
647
|
+
});
|
|
648
|
+
if (mergedIgnorePatterns.length > 0) {
|
|
649
|
+
base.ignorePatterns ??= [];
|
|
650
|
+
for (const pattern of mergedIgnorePatterns) if (!base.ignorePatterns.includes(pattern)) base.ignorePatterns.push(pattern);
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
const createOxlintConfig = async ({ options, sharedIgnorePatterns }) => {
|
|
654
|
+
const base = readRequiredJson(await file(joinPath(pkgRoot, "oxlintrc.json")).text());
|
|
655
|
+
const knownRules = /* @__PURE__ */ new Set([
|
|
656
|
+
...Object.keys(base.rules),
|
|
657
|
+
...(base.overrides ?? []).flatMap((override) => Object.keys(override.rules)),
|
|
658
|
+
...OXLINT_PATTERN_RULE_OVERRIDES.flatMap((override) => Object.keys(override.rules))
|
|
659
|
+
]);
|
|
660
|
+
applyOxlintDefaults(base, options, sharedIgnorePatterns);
|
|
661
|
+
if (!options) return base;
|
|
662
|
+
applyOxlintOptions(base, options, knownRules);
|
|
612
663
|
return base;
|
|
613
664
|
};
|
|
614
665
|
const resolveSyncImportSource = ({ cwd, dir, source }) => {
|
|
@@ -627,45 +678,11 @@ const discoverSymlinkPatterns = async ({ root }) => {
|
|
|
627
678
|
}
|
|
628
679
|
}));
|
|
629
680
|
const out = [];
|
|
630
|
-
|
|
681
|
+
const indexedEntries = entries.entries();
|
|
682
|
+
for (const [index, entry] of indexedEntries) if (symlinkFlags[index]) out.push(entry);
|
|
631
683
|
return out;
|
|
632
684
|
};
|
|
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
|
-
});
|
|
685
|
+
const buildEslintModule = ({ cwd, dir, eslintImportRefs, eslintOptions, sharedOverrideAppendIndexes }) => {
|
|
669
686
|
const normalizedImportRefs = eslintImportRefs.map((importRef) => ({
|
|
670
687
|
exportName: importRef.exportName,
|
|
671
688
|
files: importRef.files,
|
|
@@ -679,8 +696,9 @@ const sync = async (options) => {
|
|
|
679
696
|
const importStatements = normalizedImportRefs.map((importRef, index) => `import * as __lintmaxAppendImport${index} from ${JSON.stringify(importRef.source)}`).join("\n");
|
|
680
697
|
const importEntries = normalizedImportRefs.map((importRef, index) => [
|
|
681
698
|
` { exportName: ${JSON.stringify(importRef.exportName)}, `,
|
|
682
|
-
`files: ${JSON.stringify(importRef.files
|
|
683
|
-
`ignores: ${JSON.stringify(importRef.ignores
|
|
699
|
+
`files: ${importRef.files === void 0 ? "undefined" : JSON.stringify(importRef.files)}, `,
|
|
700
|
+
`ignores: ${importRef.ignores === void 0 ? "undefined" : JSON.stringify(importRef.ignores)}, `,
|
|
701
|
+
`module: __lintmaxAppendImport${index} }`
|
|
684
702
|
].join("")).join(",\n");
|
|
685
703
|
const importMarkerKey = JSON.stringify(ESLINT_IMPORT_MARKER_KEY);
|
|
686
704
|
const sharedOverrideSymbolKey = JSON.stringify(SHARED_OVERRIDE_SYMBOL_KEY);
|
|
@@ -714,21 +732,86 @@ for (const entry of options.append ?? []) {
|
|
|
714
732
|
options.append = normalizedAppend
|
|
715
733
|
`;
|
|
716
734
|
const importStatementsBlock = importStatements.length > 0 ? `${importStatements}\n` : "";
|
|
717
|
-
|
|
735
|
+
return eslintOptions ? `${importStatementsBlock}import { eslint } from 'lintmax/eslint'
|
|
718
736
|
const options = ${JSON.stringify(eslintOptions)}
|
|
719
737
|
for (const index of ${JSON.stringify(sharedOverrideAppendIndexes)}) {
|
|
720
738
|
const entry = options.append?.[index]
|
|
721
739
|
if (entry && typeof entry === 'object') entry[Symbol.for(${sharedOverrideSymbolKey})] = true
|
|
722
740
|
}${importExpansion}export default await eslint(options)
|
|
723
741
|
` : "export { default } from 'lintmax/eslint'\n";
|
|
742
|
+
};
|
|
743
|
+
const prepareSyncOptions = async (options, cwd) => {
|
|
744
|
+
const { biome, eslint, oxlint, sharedOverrides, tailwind, topLevelIgnores, tsconfigRootDir } = validateSyncOptions({ options });
|
|
745
|
+
const userIgnorePatterns = buildUserIgnorePatterns({ topLevelIgnores });
|
|
746
|
+
const symlinkIgnorePatterns = await discoverSymlinkPatterns({ root: cwd });
|
|
747
|
+
const sharedIgnorePatterns = mergeIgnorePatternGroups({ groups: [
|
|
748
|
+
DEFAULT_SHARED_IGNORE_PATTERNS,
|
|
749
|
+
symlinkIgnorePatterns,
|
|
750
|
+
userIgnorePatterns
|
|
751
|
+
] });
|
|
752
|
+
const biomeOptions = buildBiomeOptions({
|
|
753
|
+
biomeSource: biome,
|
|
754
|
+
sharedOverrides
|
|
755
|
+
});
|
|
756
|
+
const oxlintOptions = buildOxlintOptions({
|
|
757
|
+
oxlintSource: oxlint,
|
|
758
|
+
sharedOverrides
|
|
759
|
+
});
|
|
760
|
+
const { eslintImportRefs, eslintOptions, sharedOverrideAppendIndexes } = buildEslintOptions({
|
|
761
|
+
eslintSource: eslint,
|
|
762
|
+
sharedOverrides,
|
|
763
|
+
tailwind,
|
|
764
|
+
tsconfigRootDir,
|
|
765
|
+
userIgnorePatterns
|
|
766
|
+
});
|
|
767
|
+
return {
|
|
768
|
+
biomeOptions,
|
|
769
|
+
eslintImportRefs,
|
|
770
|
+
eslintOptions,
|
|
771
|
+
oxlintOptions,
|
|
772
|
+
sharedIgnorePatterns,
|
|
773
|
+
sharedOverrideAppendIndexes
|
|
774
|
+
};
|
|
775
|
+
};
|
|
776
|
+
const writeSyncConfigs = async ({ biomeConfig, comments, compact, dir, eslintConfig, oxlintConfig }) => {
|
|
724
777
|
const runtimeConfig = {
|
|
725
|
-
comments
|
|
726
|
-
compact
|
|
778
|
+
comments,
|
|
779
|
+
compact
|
|
727
780
|
};
|
|
728
|
-
await write(joinPath(dir, "biome.json"), `${JSON.stringify(biomeConfig,
|
|
729
|
-
await write(joinPath(dir, ".oxlintrc.json"), `${JSON.stringify(oxlintConfig,
|
|
781
|
+
await write(joinPath(dir, "biome.json"), `${JSON.stringify(biomeConfig, void 0, 2)}\n`);
|
|
782
|
+
await write(joinPath(dir, ".oxlintrc.json"), `${JSON.stringify(oxlintConfig, void 0, 2)}\n`);
|
|
730
783
|
await write(joinPath(dir, "eslint.generated.mjs"), eslintConfig);
|
|
731
|
-
await write(joinPath(dir, "lintmax.json"), `${JSON.stringify(runtimeConfig,
|
|
784
|
+
await write(joinPath(dir, "lintmax.json"), `${JSON.stringify(runtimeConfig, void 0, 2)}\n`);
|
|
785
|
+
};
|
|
786
|
+
const sync = async (options) => {
|
|
787
|
+
const cwd = process.cwd();
|
|
788
|
+
const dir = joinPath(cwd, cacheDir);
|
|
789
|
+
const { biomeOptions, eslintImportRefs, eslintOptions, oxlintOptions, sharedIgnorePatterns, sharedOverrideAppendIndexes } = await prepareSyncOptions(options, cwd);
|
|
790
|
+
await ensureDirectory({ directory: dir });
|
|
791
|
+
const biomeConfig = await createBiomeConfig({
|
|
792
|
+
cwd,
|
|
793
|
+
options: biomeOptions,
|
|
794
|
+
sharedIgnorePatterns
|
|
795
|
+
});
|
|
796
|
+
const oxlintConfig = await createOxlintConfig({
|
|
797
|
+
options: oxlintOptions,
|
|
798
|
+
sharedIgnorePatterns
|
|
799
|
+
});
|
|
800
|
+
const eslintConfig = buildEslintModule({
|
|
801
|
+
cwd,
|
|
802
|
+
dir,
|
|
803
|
+
eslintImportRefs,
|
|
804
|
+
eslintOptions,
|
|
805
|
+
sharedOverrideAppendIndexes
|
|
806
|
+
});
|
|
807
|
+
await writeSyncConfigs({
|
|
808
|
+
biomeConfig,
|
|
809
|
+
comments: options?.comments !== false,
|
|
810
|
+
compact: options?.compact !== false,
|
|
811
|
+
dir,
|
|
812
|
+
eslintConfig,
|
|
813
|
+
oxlintConfig
|
|
814
|
+
});
|
|
732
815
|
};
|
|
733
816
|
const eslintImport = ({ files, from, ignores, name }) => {
|
|
734
817
|
const entry = {
|
|
@@ -744,5 +827,4 @@ const defineConfig = (options) => {
|
|
|
744
827
|
validateSyncOptions({ options });
|
|
745
828
|
return options;
|
|
746
829
|
};
|
|
747
|
-
//#endregion
|
|
748
830
|
export { eslintImport as n, sync as r, defineConfig as t };
|