@moso/eslint-config 3.6.1 → 3.7.0
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 +67 -33
- package/dist/index.d.mts +3161 -810
- package/dist/index.mjs +435 -531
- package/package.json +52 -49
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
2
|
import { getPackageInfo, isPackageExists } from "local-pkg";
|
|
3
|
+
import { globalIgnores } from "eslint/config";
|
|
3
4
|
import assert from "node:assert/strict";
|
|
4
5
|
import { AST_NODE_TYPES, AST_TOKEN_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
5
6
|
import { isIdentifier } from "@typescript-eslint/utils/ast-utils";
|
|
@@ -61,30 +62,6 @@ const checkFilePath = (path) => {
|
|
|
61
62
|
*/
|
|
62
63
|
const flattenRules = (configs) => configs.reduce((acc, config) => Object.assign(acc, config.rules), {});
|
|
63
64
|
/**
|
|
64
|
-
* Auto-numbering for unnamed `globalIgnores` items.
|
|
65
|
-
*/
|
|
66
|
-
const nextGlobalIgnoresName = (() => {
|
|
67
|
-
const mut_counter = { count: 0 };
|
|
68
|
-
return () => `globalIgnores ${String(mut_counter.count++)}`;
|
|
69
|
-
})();
|
|
70
|
-
/**
|
|
71
|
-
* Build a global-ignores config item (an item with only `ignores`,
|
|
72
|
-
* which ESLint applies to the entire run).
|
|
73
|
-
*
|
|
74
|
-
* @param ignorePatterns - Glob patterns to ignore; must contain at least one entry.
|
|
75
|
-
* @param name - Config item name; auto-numbered when omitted.
|
|
76
|
-
* @returns A flat config item carrying only the ignore patterns.
|
|
77
|
-
* @throws TypeError when `ignorePatterns` is not a non-empty array.
|
|
78
|
-
*/
|
|
79
|
-
const globalIgnores = (ignorePatterns, name) => {
|
|
80
|
-
if (!Array.isArray(ignorePatterns)) throw new TypeError("`ignorePatterns` must be an array");
|
|
81
|
-
if (ignorePatterns.length === 0) throw new TypeError("`ignorePatterns` must contain at least one pattern");
|
|
82
|
-
return {
|
|
83
|
-
name: name ?? nextGlobalIgnoresName(),
|
|
84
|
-
ignores: ignorePatterns
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
65
|
* Await a value and unwrap its `default` export when present.
|
|
89
66
|
*
|
|
90
67
|
* Smooths over the CJS/ESM interop difference where `import()` of a CJS module
|
|
@@ -148,8 +125,9 @@ const getOverrides = (options, key) => {
|
|
|
148
125
|
* @returns The first instance ever registered under `key`.
|
|
149
126
|
*/
|
|
150
127
|
const memoize = (plugin, key) => {
|
|
151
|
-
|
|
152
|
-
|
|
128
|
+
const mut_realm = globalThis;
|
|
129
|
+
mut_realm.__ESLINT_PLUGIN_MEMO__ ??= /* @__PURE__ */ new Map();
|
|
130
|
+
const mut_memo = mut_realm.__ESLINT_PLUGIN_MEMO__;
|
|
153
131
|
const existing = mut_memo.get(key);
|
|
154
132
|
if (existing !== void 0) return existing;
|
|
155
133
|
mut_memo.set(key, plugin);
|
|
@@ -219,7 +197,7 @@ const isPackageInScope = (name) => isPackageExists(name, { paths: [scopeURL] });
|
|
|
219
197
|
const isInteractive = () => !Boolean(process.env.CI) && process.stdout.isTTY;
|
|
220
198
|
/**
|
|
221
199
|
* Offer to install missing packages through an interactive prompt.
|
|
222
|
-
* Only
|
|
200
|
+
* Only reached from `loadPackages`, through the install queue, after the session is verified interactive
|
|
223
201
|
* and the packages are genuinely missing.
|
|
224
202
|
*
|
|
225
203
|
* @param missingPackages - Package names to offer for installation.
|
|
@@ -231,9 +209,27 @@ const ensurePackages = async (missingPackages) => {
|
|
|
231
209
|
}
|
|
232
210
|
};
|
|
233
211
|
/**
|
|
212
|
+
* Tail of the install queue: config factories run concurrently,
|
|
213
|
+
* so each "check → prompt → install" step waits for the previous one.
|
|
214
|
+
*/
|
|
215
|
+
const mut_installQueue = { tail: Promise.resolve() };
|
|
216
|
+
/**
|
|
217
|
+
* Once the previous queue entry has settled, offer to install whichever optional peers are still missing.
|
|
218
|
+
* Checking only now means a package an earlier caller installed is not offered again.
|
|
219
|
+
*
|
|
220
|
+
* @param packageIds - Package names the caller is about to import.
|
|
221
|
+
* @param previous - The queue entry to wait for; its failure is the earlier caller's to handle.
|
|
222
|
+
*/
|
|
223
|
+
const ensureMissingPackages = async (packageIds, previous) => {
|
|
224
|
+
await Promise.allSettled([previous]);
|
|
225
|
+
const missing = packageIds.filter((id) => optionalPeers.has(id) && !isPackageInScope(id));
|
|
226
|
+
if (missing.length > 0) await ensurePackages(missing);
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
234
229
|
* Dynamically import a list of packages, unwrapping default exports.
|
|
235
230
|
*
|
|
236
|
-
* In interactive sessions, missing packages trigger an install prompt first
|
|
231
|
+
* In interactive sessions, missing packages trigger an install prompt first,
|
|
232
|
+
* one prompt at a time across concurrent calls.
|
|
237
233
|
* The package-name literals are mapped to module types through `PackageTypes`,
|
|
238
234
|
* so call sites destructure a fully typed tuple without casts:
|
|
239
235
|
* `const [plugin] = await loadPackages(['pkg'])`.
|
|
@@ -243,8 +239,9 @@ const ensurePackages = async (missingPackages) => {
|
|
|
243
239
|
*/
|
|
244
240
|
const loadPackages = async (packageIds) => {
|
|
245
241
|
if (isInteractive()) {
|
|
246
|
-
const
|
|
247
|
-
|
|
242
|
+
const turn = ensureMissingPackages(packageIds, mut_installQueue.tail);
|
|
243
|
+
mut_installQueue.tail = turn;
|
|
244
|
+
await turn;
|
|
248
245
|
}
|
|
249
246
|
return Promise.all(packageIds.map(async (id) => interopDefault(import(id))));
|
|
250
247
|
};
|
|
@@ -271,10 +268,7 @@ const astro = async (options) => {
|
|
|
271
268
|
parserOptions: {
|
|
272
269
|
extraFileExtensions: [".astro"],
|
|
273
270
|
parser: typescript ? typescriptParser : void 0,
|
|
274
|
-
...typescript &&
|
|
275
|
-
...typeAwareParserOptions,
|
|
276
|
-
...Boolean(projectService) && { project: true }
|
|
277
|
-
}
|
|
271
|
+
...typescript && typeAwareParserOptions
|
|
278
272
|
},
|
|
279
273
|
sourceType: "module"
|
|
280
274
|
},
|
|
@@ -311,14 +305,13 @@ const astro = async (options) => {
|
|
|
311
305
|
}];
|
|
312
306
|
};
|
|
313
307
|
// src/configs/baseline.ts
|
|
314
|
-
const defaultIgnoreFeatures = ["functions-caller-arguments"];
|
|
315
308
|
const baseline = async (options) => {
|
|
316
309
|
const { baseline = "widely", files, filesTypeAware, hasDOM, ignoreFeatures, ignoreNodeTypes, ignoresTypeAware, overrides, overridesTypeAware, parserOptions, projectRoot, typescript } = options;
|
|
317
310
|
const isTypeAware = typescript && typeof projectRoot === "string" && parserOptions?.projectService !== false;
|
|
318
311
|
const [baselinePlugin] = await loadPackages(["eslint-plugin-baseline-js"]);
|
|
319
312
|
const baselineRule = (typeAware) => ({ "baseline-js/use-baseline": ["warn", {
|
|
320
313
|
available: baseline,
|
|
321
|
-
ignoreFeatures
|
|
314
|
+
ignoreFeatures,
|
|
322
315
|
ignoreNodeTypes,
|
|
323
316
|
includeJsBuiltins: { preset: typeAware ? "type-aware" : "auto" },
|
|
324
317
|
includeWebApis: hasDOM !== false && { preset: typeAware ? "type-aware" : "auto" }
|
|
@@ -350,6 +343,7 @@ const baseline = async (options) => {
|
|
|
350
343
|
// src/globs.ts
|
|
351
344
|
const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
|
|
352
345
|
const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
|
|
346
|
+
const GLOB_SCRIPT = "**/*.{?([cm])[jt]s?(x),astro,svelte,vue}";
|
|
353
347
|
const GLOB_JS = "**/*.?([cm])js";
|
|
354
348
|
const GLOB_JSX = "**/*.?([cm])jsx";
|
|
355
349
|
const GLOB_TS = "**/*.?([cm])ts";
|
|
@@ -489,8 +483,11 @@ const disables = async (functionalEnabled = false) => {
|
|
|
489
483
|
name: "moso/disables/dts",
|
|
490
484
|
files: ["**/*.d.?([cm])ts"],
|
|
491
485
|
rules: {
|
|
486
|
+
"no-duplicate-imports": "off",
|
|
492
487
|
"no-restricted-syntax": "off",
|
|
493
488
|
"@eslint-community/eslint-comments/no-unlimited-disable": "off",
|
|
489
|
+
"@stylistic/quote-props": "off",
|
|
490
|
+
"@typescript-eslint/consistent-type-definitions": "off",
|
|
494
491
|
"import-lite/no-duplicates": "off",
|
|
495
492
|
"unused-imports/no-unused-vars": "off"
|
|
496
493
|
}
|
|
@@ -564,11 +561,13 @@ const disables = async (functionalEnabled = false) => {
|
|
|
564
561
|
"@typescript-eslint/no-unsafe-argument": "off",
|
|
565
562
|
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
566
563
|
"@typescript-eslint/no-unsafe-call": "off",
|
|
564
|
+
"@typescript-eslint/no-unsafe-class-instance-assignment": "off",
|
|
567
565
|
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
568
566
|
"@typescript-eslint/no-unsafe-return": "off",
|
|
569
567
|
"@typescript-eslint/no-unused-expressions": "off",
|
|
570
568
|
"@typescript-eslint/no-unused-vars": "off",
|
|
571
|
-
"@typescript-eslint/strict-boolean-expressions": "off"
|
|
569
|
+
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
570
|
+
"@typescript-eslint/triple-slash-reference": "off"
|
|
572
571
|
}
|
|
573
572
|
},
|
|
574
573
|
{
|
|
@@ -576,7 +575,6 @@ const disables = async (functionalEnabled = false) => {
|
|
|
576
575
|
files: [GLOB_TYPINGS],
|
|
577
576
|
rules: {
|
|
578
577
|
...functionalPlugin !== void 0 && (assert.ok(!Array.isArray(functionalPlugin.configs.off)), functionalPlugin.configs.off.rules),
|
|
579
|
-
"jsdoc/check-examples": "off",
|
|
580
578
|
"jsdoc/check-indentation": "off",
|
|
581
579
|
"jsdoc/check-line-alignment": "off",
|
|
582
580
|
"jsdoc/check-param-names": "off",
|
|
@@ -624,6 +622,7 @@ const e18e = async (options) => {
|
|
|
624
622
|
const enablePerformanceImprovements = performanceImprovements !== false;
|
|
625
623
|
return [{
|
|
626
624
|
name: "moso/e18e/rules",
|
|
625
|
+
files: [GLOB_SCRIPT],
|
|
627
626
|
plugins: { "e18e": memoize(e18ePlugin, "@e18e/eslint-plugin") },
|
|
628
627
|
rules: {
|
|
629
628
|
...enableModernization && { ...(assert.ok(!Array.isArray(e18ePlugin.configs.modernization)), e18ePlugin.configs.modernization.rules) },
|
|
@@ -680,12 +679,48 @@ const functional = async (options) => {
|
|
|
680
679
|
};
|
|
681
680
|
const commonStylisticRules = {
|
|
682
681
|
"functional/prefer-property-signatures": stylisticEnabled ? "error" : "off",
|
|
683
|
-
"functional/prefer-tacit": stylisticEnabled ? "warn" : "off",
|
|
684
682
|
"functional/readonly-type": stylisticEnabled ? "error" : "off"
|
|
685
683
|
};
|
|
684
|
+
const typeDeclarationRules = mode === "library" ? {} : { "functional/type-declaration-immutability": ["error", { rules: [
|
|
685
|
+
{
|
|
686
|
+
identifiers: "I?Immutable.+",
|
|
687
|
+
immutability: "Immutable",
|
|
688
|
+
comparator: "AtLeast"
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
identifiers: "I?ReadonlyDeep.+",
|
|
692
|
+
immutability: "ReadonlyDeep",
|
|
693
|
+
comparator: "AtLeast"
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
identifiers: "I?Readonly.+",
|
|
697
|
+
immutability: "ReadonlyShallow",
|
|
698
|
+
comparator: "AtLeast",
|
|
699
|
+
fixer: [{
|
|
700
|
+
pattern: "^(Array|Map|Set)<(.+)>$",
|
|
701
|
+
replace: "Readonly$1<$2>"
|
|
702
|
+
}, {
|
|
703
|
+
pattern: "^(.+)$",
|
|
704
|
+
replace: "Readonly<$1>"
|
|
705
|
+
}]
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
identifiers: "I?Mutable.+",
|
|
709
|
+
immutability: "Mutable",
|
|
710
|
+
comparator: "AtMost",
|
|
711
|
+
fixer: [{
|
|
712
|
+
pattern: "^Readonly(Array|Map|Set)<(.+)>$",
|
|
713
|
+
replace: "$1<$2>"
|
|
714
|
+
}, {
|
|
715
|
+
pattern: "^Readonly<(.+)>$",
|
|
716
|
+
replace: "$1"
|
|
717
|
+
}]
|
|
718
|
+
}
|
|
719
|
+
] }] };
|
|
686
720
|
const strictRules = {
|
|
687
721
|
...(assert.ok(!Array.isArray(functionalPlugin.configs.strict)), functionalPlugin.configs.strict.rules),
|
|
688
722
|
"functional/no-conditional-statements": ["error", { ignoreCodePattern: ["import.meta.vitest"] }],
|
|
723
|
+
...typeDeclarationRules,
|
|
689
724
|
...commonStylisticRules
|
|
690
725
|
};
|
|
691
726
|
const recommendedRules = {
|
|
@@ -712,28 +747,27 @@ const functional = async (options) => {
|
|
|
712
747
|
ignoreSelfReturning: true,
|
|
713
748
|
ignoreVoid: true
|
|
714
749
|
}],
|
|
715
|
-
"functional/no-loop-statements": "error",
|
|
716
750
|
"functional/no-return-void": "off",
|
|
717
|
-
"functional/no-throw-statements": ["error", { allowToRejectPromises: true }],
|
|
718
751
|
"@typescript-eslint/prefer-readonly-parameter-types": "off",
|
|
719
752
|
"functional/prefer-immutable-types": "off",
|
|
720
753
|
"functional/type-declaration-immutability": "off",
|
|
754
|
+
...typeDeclarationRules,
|
|
721
755
|
...commonStylisticRules
|
|
722
756
|
};
|
|
723
757
|
const liteRules = {
|
|
724
758
|
...(assert.ok(!Array.isArray(functionalPlugin.configs.lite)), functionalPlugin.configs.lite.rules),
|
|
725
759
|
...commonRules,
|
|
726
|
-
"functional/no-loop-statements": "error",
|
|
727
760
|
"functional/no-mixed-types": mode === "library" ? "off" : "error",
|
|
728
761
|
"functional/no-return-void": "off",
|
|
729
|
-
"functional/no-throw-statements": ["error", { allowToRejectPromises: true }],
|
|
730
762
|
"@typescript-eslint/prefer-readonly-parameter-types": "off",
|
|
731
763
|
"functional/prefer-immutable-types": "off",
|
|
732
764
|
"functional/type-declaration-immutability": "off",
|
|
765
|
+
...typeDeclarationRules,
|
|
733
766
|
...commonStylisticRules
|
|
734
767
|
};
|
|
735
768
|
return [{
|
|
736
769
|
name: "moso/functional",
|
|
770
|
+
files: [GLOB_SCRIPT],
|
|
737
771
|
settings: { immutability: { overrides: [
|
|
738
772
|
{
|
|
739
773
|
type: "^Readonly<.+>$",
|
|
@@ -756,14 +790,9 @@ const functional = async (options) => {
|
|
|
756
790
|
}
|
|
757
791
|
}, {
|
|
758
792
|
name: "moso/functional/disable-type-aware",
|
|
793
|
+
files: [GLOB_SCRIPT],
|
|
759
794
|
...isTypeAware && { ignores: filesTypeAware },
|
|
760
|
-
rules: {
|
|
761
|
-
...(assert.ok(!Array.isArray(functionalPlugin.configs.disableTypeChecked)), functionalPlugin.configs.disableTypeChecked.rules),
|
|
762
|
-
"functional/no-let": ["error", {
|
|
763
|
-
allowInForLoopInit: true,
|
|
764
|
-
ignoreIdentifierPattern: ignoreNamePattern
|
|
765
|
-
}]
|
|
766
|
-
}
|
|
795
|
+
rules: { ...(assert.ok(!Array.isArray(functionalPlugin.configs.disableTypeChecked)), functionalPlugin.configs.disableTypeChecked.rules) }
|
|
767
796
|
}];
|
|
768
797
|
};
|
|
769
798
|
// src/configs/ignores.ts
|
|
@@ -771,13 +800,16 @@ const ignores = async (options) => {
|
|
|
771
800
|
const { gitignore = true, ignoreTypeScript, userIgnores } = options;
|
|
772
801
|
const [eslintConfigFlatGitIgnore] = await loadPackages(["eslint-config-flat-gitignore"]);
|
|
773
802
|
const mut_configs = [];
|
|
774
|
-
const mut_ignores = userIgnores === false || userIgnores === void 0 ? [...GLOB_EXCLUDE] : typeof userIgnores === "function" ? userIgnores(GLOB_EXCLUDE) : typeof userIgnores === "string" ? [...GLOB_EXCLUDE, userIgnores] : [...GLOB_EXCLUDE, ...userIgnores];
|
|
803
|
+
const mut_ignores = userIgnores === false || userIgnores === void 0 ? [...GLOB_EXCLUDE] : typeof userIgnores === "function" ? userIgnores([...GLOB_EXCLUDE]) : typeof userIgnores === "string" ? [...GLOB_EXCLUDE, userIgnores] : [...GLOB_EXCLUDE, ...userIgnores];
|
|
775
804
|
if (ignoreTypeScript) mut_ignores.push(GLOB_TS, GLOB_TSX);
|
|
776
|
-
mut_configs.push(
|
|
805
|
+
mut_configs.push({
|
|
806
|
+
name: "moso/ignores/globals",
|
|
807
|
+
ignores: mut_ignores
|
|
808
|
+
});
|
|
777
809
|
if (gitignore !== false) mut_configs.push(eslintConfigFlatGitIgnore({
|
|
778
810
|
name: "moso/ignores/gitignore",
|
|
779
811
|
strict: false,
|
|
780
|
-
...typeof gitignore === "string" ? { files: [gitignore] } : typeof gitignore === "object" ? gitignore : {
|
|
812
|
+
...typeof gitignore === "string" ? { files: [gitignore] } : typeof gitignore === "object" ? gitignore : {}
|
|
781
813
|
}));
|
|
782
814
|
return mut_configs;
|
|
783
815
|
};
|
|
@@ -789,17 +821,9 @@ const ignores = async (options) => {
|
|
|
789
821
|
* and the rule name doubles as its documentation URL slug.
|
|
790
822
|
*/
|
|
791
823
|
const createRule = ESLintUtils.RuleCreator((name) => name);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
* Basically the AST equivalent of `Element#closest`.
|
|
796
|
-
*/
|
|
797
|
-
const closest = (node, type) => {
|
|
798
|
-
const findClosest = (current) => {
|
|
799
|
-
if (!current) return void 0;
|
|
800
|
-
return current.type === type ? current : findClosest(current.parent);
|
|
801
|
-
};
|
|
802
|
-
return findClosest(node);
|
|
824
|
+
const escapeTail = (match) => {
|
|
825
|
+
const point = match.codePointAt(0);
|
|
826
|
+
return typeof point === "number" && point > 65535 ? `u{${point.toString(16).padStart(4, "0").toUpperCase()}}` : `u${point?.toString(16).padStart(4, "0").toUpperCase()}`;
|
|
803
827
|
};
|
|
804
828
|
/**
|
|
805
829
|
* Replace every `pattern` match in `input` with its unicode escape sequence
|
|
@@ -810,62 +834,54 @@ const closest = (node, type) => {
|
|
|
810
834
|
* @param pattern - Which characters to escape; pass a `/g` regex to escape all occurrences.
|
|
811
835
|
* @returns The text with matched characters replaced by their escape sequences.
|
|
812
836
|
*/
|
|
813
|
-
const escape = (input, pattern) => input.replace(pattern, (match) => {
|
|
814
|
-
|
|
815
|
-
|
|
837
|
+
const escape = (input, pattern) => input.replace(pattern, (match) => `\\${escapeTail(match)}`);
|
|
838
|
+
const escapeSource = (input, pattern) => input.replace(pattern, (match, ...rest) => {
|
|
839
|
+
const before = input.slice(0, rest.findLast((argument) => typeof argument === "number"));
|
|
840
|
+
return (before.length - before.replace(/\\+$/u, "").length) % 2 === 1 ? escapeTail(match) : `\\${escapeTail(match)}`;
|
|
816
841
|
});
|
|
842
|
+
const astralPattern = /[\u{10000}-\u{10FFFF}]/u;
|
|
843
|
+
const isTaggedQuasi = (token, sourceCode) => {
|
|
844
|
+
const template = sourceCode.getNodeByRangeIndex(token.range[0])?.parent;
|
|
845
|
+
return template?.parent?.type === AST_NODE_TYPES.TaggedTemplateExpression && template.parent.quasi === template;
|
|
846
|
+
};
|
|
817
847
|
/**
|
|
818
848
|
* Fixer that rewrites `pattern` matches inside a token to a safe,
|
|
819
849
|
* escaped form dispatched on token type:
|
|
820
850
|
* - HTML entities for JSXText
|
|
821
|
-
* -
|
|
851
|
+
* - Unicode escapes for RegularExpression, keeping its flags
|
|
822
852
|
* - Unicode escapes for String/Template tokens
|
|
823
853
|
*
|
|
854
|
+
* No fix where escaping would change the runtime value: the quasi of a tagged
|
|
855
|
+
* template (tags read `.raw`), or an astral character in a regex without `u`/`v`.
|
|
856
|
+
*
|
|
824
857
|
* @param token - The offending token to rewrite.
|
|
825
|
-
* @param pattern - Which characters to escape;
|
|
826
|
-
* @
|
|
858
|
+
* @param pattern - Which characters to escape; must be a `/g` regex.
|
|
859
|
+
* @param sourceCode - The source code the token belongs to.
|
|
860
|
+
* @returns A fix function, or `undefined` for tokens that cannot be fixed safely.
|
|
827
861
|
*/
|
|
828
|
-
const getFixer = (token, pattern) => {
|
|
862
|
+
const getFixer = (token, pattern, sourceCode) => {
|
|
829
863
|
switch (token.type) {
|
|
830
864
|
case AST_TOKEN_TYPES.JSXText: return (fixer) => {
|
|
831
865
|
const modified = token.value.replace(pattern, (match) => `&#x${match.codePointAt(0)?.toString(16).padStart(4, "0").toUpperCase()};`);
|
|
832
866
|
return fixer.replaceText(token, modified);
|
|
833
867
|
};
|
|
834
|
-
case AST_TOKEN_TYPES.RegularExpression:
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
const re = new RegExp(escape(token.regex.pattern, pattern), [...mut_flags].join(""));
|
|
839
|
-
return fixer.replaceText(token, re.toString());
|
|
840
|
-
} catch {
|
|
841
|
-
return null;
|
|
842
|
-
}
|
|
843
|
-
};
|
|
868
|
+
case AST_TOKEN_TYPES.RegularExpression: {
|
|
869
|
+
const { flags, pattern: source } = token.regex;
|
|
870
|
+
return !/[uv]/u.test(flags) && source.matchAll(pattern).some(([match]) => astralPattern.test(match)) ? void 0 : (fixer) => fixer.replaceText(token, `/${escapeSource(source, pattern)}/${flags}`);
|
|
871
|
+
}
|
|
844
872
|
case AST_TOKEN_TYPES.String:
|
|
845
|
-
case AST_TOKEN_TYPES.Template:
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
873
|
+
case AST_TOKEN_TYPES.Template:
|
|
874
|
+
if (token.type === AST_TOKEN_TYPES.Template && isTaggedQuasi(token, sourceCode)) return void 0;
|
|
875
|
+
return (fixer) => {
|
|
876
|
+
const prefix = token.value.slice(0, 1);
|
|
877
|
+
const suffix = token.value.slice(-1);
|
|
878
|
+
const modified = escapeSource(token.value.slice(1, -1), pattern);
|
|
879
|
+
return fixer.replaceText(token, `${prefix}${modified}${suffix}`);
|
|
880
|
+
};
|
|
851
881
|
default: return;
|
|
852
882
|
}
|
|
853
883
|
};
|
|
854
884
|
/**
|
|
855
|
-
* Resolve the expression a `return` should carry when inlining a variable.
|
|
856
|
-
*
|
|
857
|
-
* Unwraps `await` (the classic no-return-await optimization - `return promise`
|
|
858
|
-
* flattens identically for the caller) except inside `try` blocks,
|
|
859
|
-
* where the `await` is needed for `catch` to observe rejections.
|
|
860
|
-
*
|
|
861
|
-
* @param node - The variable initializer being inlined.
|
|
862
|
-
* @returns `node.argument` for safe-to-unwrap awaits, otherwise `node` itself.
|
|
863
|
-
*/
|
|
864
|
-
const getReturnExpression = (node) => {
|
|
865
|
-
if (node.type !== AST_NODE_TYPES.AwaitExpression) return node;
|
|
866
|
-
return closest(node, AST_NODE_TYPES.TryStatement) ? node : node.argument;
|
|
867
|
-
};
|
|
868
|
-
/**
|
|
869
885
|
* Extract the user-visible text of a token for pattern scanning:
|
|
870
886
|
* string/template contents without quotes, regex pattern source,
|
|
871
887
|
* identifier names or `false` for token types that carry no scannable text.
|
|
@@ -907,9 +923,10 @@ const isSameIdentifier = (a, b) => a?.type === AST_NODE_TYPES.Identifier && b?.t
|
|
|
907
923
|
/**
|
|
908
924
|
* Whether `node` is an identity function: a single-parameter function that
|
|
909
925
|
* returns its own parameter unchanged, in either expression form (`(x) => x`)
|
|
910
|
-
* or block form (`(x) => { return x }`).
|
|
926
|
+
* or block form (`(x) => { return x }`). Async and generator functions never
|
|
927
|
+
* qualify: they return a promise or an iterator, not the parameter.
|
|
911
928
|
*/
|
|
912
|
-
const isIdentifierFunction = (node) => isFunctionLike(node) && node.params.length === 1 && node.params[0].type === AST_NODE_TYPES.Identifier && (isSameIdentifier(node.params[0], node.body) || node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 1 && node.body.body[0].type === AST_NODE_TYPES.ReturnStatement && isSameIdentifier(node.params[0], node.body.body[0].argument));
|
|
929
|
+
const isIdentifierFunction = (node) => isFunctionLike(node) && !node.async && !node.generator && node.params.length === 1 && node.params[0].type === AST_NODE_TYPES.Identifier && (isSameIdentifier(node.params[0], node.body) || node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 1 && node.body.body[0].type === AST_NODE_TYPES.ReturnStatement && isSameIdentifier(node.params[0], node.body.body[0].argument));
|
|
913
930
|
const isLiteralValue = (node, value) => {
|
|
914
931
|
if (node?.type !== AST_NODE_TYPES.Literal) return false;
|
|
915
932
|
return typeof value === "string" ? node.value === value : typeof node.value === "string" && value.test(node.value);
|
|
@@ -981,7 +998,7 @@ const ruleAvoidBarrelFiles = createRule({
|
|
|
981
998
|
};
|
|
982
999
|
return {
|
|
983
1000
|
declarationCount,
|
|
984
|
-
exportCount: exportCount + (statement.declaration.type === AST_NODE_TYPES.ObjectExpression ? statement.declaration.properties.length : 1)
|
|
1001
|
+
exportCount: exportCount + (statement.declaration.type === AST_NODE_TYPES.ObjectExpression ? statement.declaration.properties.filter((property) => property.type === AST_NODE_TYPES.Property && property.shorthand).length : 1)
|
|
985
1002
|
};
|
|
986
1003
|
}
|
|
987
1004
|
return {
|
|
@@ -1022,7 +1039,7 @@ const ruleNoBidi = createRule({
|
|
|
1022
1039
|
text: escape(node.value, BIDI_PATTERN_GLOBAL)
|
|
1023
1040
|
},
|
|
1024
1041
|
messageId: "noBidi",
|
|
1025
|
-
fix: getFixer(node, BIDI_PATTERN_GLOBAL)
|
|
1042
|
+
fix: getFixer(node, BIDI_PATTERN_GLOBAL, context.sourceCode)
|
|
1026
1043
|
});
|
|
1027
1044
|
})
|
|
1028
1045
|
});
|
|
@@ -1152,12 +1169,15 @@ const ruleNoImportNodeModulesByPath = createRule({
|
|
|
1152
1169
|
})
|
|
1153
1170
|
});
|
|
1154
1171
|
// src/rules/no-invisible-characters/no-invisible-characters.ts
|
|
1155
|
-
const combinePattern = (...patterns) => {
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1172
|
+
const combinePattern = (...patterns) => `[${patterns.map((pattern) => pattern.source).join("")}]`;
|
|
1173
|
+
const INVISIBLE_SOURCE = [
|
|
1174
|
+
combinePattern(/\u{AD}\u{34F}\u{17B4}\u{17B5}\u{FEFF}\u{FFFC}/u, /\u{180B}-\u{180E}/u, /\u{200B}\u{200C}\u{200E}\u{200F}/u, /\u{2060}-\u{2065}\u{206A}-\u{206F}/u, /\u{FE00}-\u{FE0D}/u, /\u{FFF0}-\u{FFF8}/u, /\u{1D173}-\u{1D17A}/u, /\u{E0000}-\u{E001F}/u, /\u{E0100}-\u{E01EF}/u),
|
|
1175
|
+
/(?<![\p{Extended_Pictographic}\p{Emoji_Modifier}]\u{FE0F}?)\u{200D}|\u{200D}(?!\p{Extended_Pictographic})/u.source,
|
|
1176
|
+
/(?<![\p{Extended_Pictographic}#*0-9])[\u{FE0E}\u{FE0F}]/u.source,
|
|
1177
|
+
/(?<!\u{1F3F4}[\u{E0020}-\u{E007E}]{0,6})[\u{E0020}-\u{E007F}]/u.source
|
|
1178
|
+
].join("|");
|
|
1179
|
+
const INVISIBLE_PATTERN = new RegExp(INVISIBLE_SOURCE, "u");
|
|
1180
|
+
const INVISIBLE_PATTERN_GLOBAL = new RegExp(INVISIBLE_SOURCE, "gu");
|
|
1161
1181
|
const ruleNoInvisibleCharacters = createRule({
|
|
1162
1182
|
name: "no-invisible-characters",
|
|
1163
1183
|
meta: {
|
|
@@ -1175,23 +1195,18 @@ const ruleNoInvisibleCharacters = createRule({
|
|
|
1175
1195
|
context.report({
|
|
1176
1196
|
node,
|
|
1177
1197
|
messageId: "noInvisibleCharacter",
|
|
1178
|
-
fix: getFixer(node, INVISIBLE_PATTERN_GLOBAL)
|
|
1198
|
+
fix: getFixer(node, INVISIBLE_PATTERN_GLOBAL, context.sourceCode)
|
|
1179
1199
|
});
|
|
1180
1200
|
})
|
|
1181
1201
|
});
|
|
1182
1202
|
// src/rules/no-redundant-variable/no-redundant-variable.ts
|
|
1183
1203
|
const isRedundantVariable = (node, exit) => node?.type === AST_NODE_TYPES.VariableDeclaration && node.declarations.length === 1 && node.declarations[0].init !== null && isSameIdentifier(exit.argument, node.declarations[0].id);
|
|
1184
1204
|
const isRedundantVariableFixer = (source, variable, id, init, exit) => (fixer) => {
|
|
1185
|
-
const
|
|
1186
|
-
const modified = wrap(source.getText(replaced), (input) => {
|
|
1187
|
-
if (!id.typeAnnotation) return input;
|
|
1188
|
-
const annotation = source.getText(id.typeAnnotation.typeAnnotation);
|
|
1189
|
-
return `(${input}) as ${replaced === init ? annotation : `Promise<${annotation}>`}`;
|
|
1190
|
-
});
|
|
1205
|
+
const modified = wrap(source.getText(init), (input) => id.typeAnnotation ? `(${input}) as ${source.getText(id.typeAnnotation.typeAnnotation)}` : input);
|
|
1191
1206
|
return [fixer.remove(variable), fixer.replaceText(exit.argument, modified)];
|
|
1192
1207
|
};
|
|
1193
1208
|
const isReturnStatement = (node) => node.type === AST_NODE_TYPES.ReturnStatement && isIdentifier(node.argument);
|
|
1194
|
-
const
|
|
1209
|
+
const isOnlyReturned = (source, declarator, exit) => source.getDeclaredVariables(declarator).every(({ references }) => references.every(({ identifier }) => identifier === declarator.id || identifier === exit.argument));
|
|
1195
1210
|
const ruleNoRedundantVariables = createRule({
|
|
1196
1211
|
name: "no-redundant-variable",
|
|
1197
1212
|
meta: {
|
|
@@ -1213,8 +1228,9 @@ const ruleNoRedundantVariables = createRule({
|
|
|
1213
1228
|
continue;
|
|
1214
1229
|
}
|
|
1215
1230
|
if (isRedundantVariable(mut_previous, statement)) {
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1231
|
+
const [declarator] = mut_previous.declarations;
|
|
1232
|
+
const { id, init } = declarator;
|
|
1233
|
+
if (init && isOnlyReturned(context.sourceCode, declarator, statement)) context.report({
|
|
1218
1234
|
node: statement,
|
|
1219
1235
|
messageId: "noRedundantVar",
|
|
1220
1236
|
fix: isRedundantVariableFixer(context.sourceCode, mut_previous, id, init, statement)
|
|
@@ -1238,8 +1254,9 @@ const ruleNoStringInterpolation = createRule({
|
|
|
1238
1254
|
schema: [],
|
|
1239
1255
|
messages: { noStringInterpolation: "Please extract this expression into its own variable." }
|
|
1240
1256
|
},
|
|
1241
|
-
create: (context) => ({ TemplateLiteral: (
|
|
1242
|
-
|
|
1257
|
+
create: (context) => ({ TemplateLiteral: (node) => {
|
|
1258
|
+
if (node.parent.type === AST_NODE_TYPES.TaggedTemplateExpression && node.parent.quasi === node) return;
|
|
1259
|
+
for (const expression of node.expressions) if (isMultiline(expression)) context.report({
|
|
1243
1260
|
node: expression,
|
|
1244
1261
|
messageId: "noStringInterpolation"
|
|
1245
1262
|
});
|
|
@@ -1320,13 +1337,20 @@ const ruleNoUnneededArrayFlatMap = createRule({
|
|
|
1320
1337
|
} })
|
|
1321
1338
|
});
|
|
1322
1339
|
// src/rules/package.json
|
|
1323
|
-
var version = "3.
|
|
1340
|
+
var version = "3.7.0";
|
|
1324
1341
|
// src/rules/prefer-early-return/prefer-early-return.ts
|
|
1325
1342
|
const isTriggering = (node, maximumStatements) => {
|
|
1326
1343
|
if (node.type !== AST_NODE_TYPES.IfStatement || node.alternate !== null) return false;
|
|
1327
1344
|
const { consequent } = node;
|
|
1328
1345
|
return consequent.type === AST_NODE_TYPES.ExpressionStatement && maximumStatements === 0 || consequent.type === AST_NODE_TYPES.BlockStatement && consequent.body.length > maximumStatements;
|
|
1329
1346
|
};
|
|
1347
|
+
const hasHoistingClash = (sourceCode, node) => {
|
|
1348
|
+
const { consequent, test } = node;
|
|
1349
|
+
if (consequent.type !== AST_NODE_TYPES.BlockStatement) return false;
|
|
1350
|
+
const functionScope = sourceCode.getScope(node);
|
|
1351
|
+
const isInTest = ({ range }) => range[0] >= test.range[0] && range[1] <= test.range[1];
|
|
1352
|
+
return sourceCode.getScope(consequent).variables.some(({ name }) => functionScope.set.has(name) || functionScope.through.some(({ identifier }) => identifier.name === name && isInTest(identifier)));
|
|
1353
|
+
};
|
|
1330
1354
|
const makeFixer = (context, parent) => (fixer) => {
|
|
1331
1355
|
const { test, consequent } = parent;
|
|
1332
1356
|
const bodyText = consequent.type === AST_NODE_TYPES.BlockStatement ? context.sourceCode.getText(consequent).slice(1, -1).trim() : context.sourceCode.getText(consequent);
|
|
@@ -1365,7 +1389,7 @@ const rulePreferEarlyReturns = createRule({
|
|
|
1365
1389
|
context.report({
|
|
1366
1390
|
node: statement,
|
|
1367
1391
|
messageId: "preferEarlyReturn",
|
|
1368
|
-
fix: makeFixer(context, statement)
|
|
1392
|
+
fix: hasHoistingClash(context.sourceCode, statement) ? null : makeFixer(context, statement)
|
|
1369
1393
|
});
|
|
1370
1394
|
} })
|
|
1371
1395
|
});
|
|
@@ -1505,6 +1529,14 @@ const isMathCall = (node, methods) => {
|
|
|
1505
1529
|
const { callee } = node;
|
|
1506
1530
|
return callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && isIdentifierName(callee.object, "Math") && (methods === void 0 || isIdentifierName(callee.property, methods));
|
|
1507
1531
|
};
|
|
1532
|
+
const isNumericConstant = (node) => {
|
|
1533
|
+
switch (node.type) {
|
|
1534
|
+
case AST_NODE_TYPES.BinaryExpression: return arithmeticOperators.has(node.operator) && isNumericConstant(node.left) && isNumericConstant(node.right);
|
|
1535
|
+
case AST_NODE_TYPES.Literal: return typeof node.value === "number";
|
|
1536
|
+
case AST_NODE_TYPES.UnaryExpression: return node.operator === "-" && isNumericConstant(node.argument);
|
|
1537
|
+
default: return false;
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1508
1540
|
const isWriteTarget = (node) => {
|
|
1509
1541
|
const { parent } = node;
|
|
1510
1542
|
return parent.type === AST_NODE_TYPES.AssignmentExpression && parent.left === node || parent.type === AST_NODE_TYPES.UpdateExpression || parent.type === AST_NODE_TYPES.UnaryExpression && parent.operator === "delete";
|
|
@@ -1591,6 +1623,7 @@ const rulePreferStrictNumberGuards = createRule({
|
|
|
1591
1623
|
if (node.operator !== "/" && node.operator !== "%") return;
|
|
1592
1624
|
const divisor = node.right;
|
|
1593
1625
|
if (divisor.type === AST_NODE_TYPES.BinaryExpression && arithmeticOperators.has(divisor.operator)) {
|
|
1626
|
+
if (isNumericConstant(divisor)) return;
|
|
1594
1627
|
const nested = divisor.operator === "/";
|
|
1595
1628
|
const guard = nested ? "use-direct-operands" : "guard-derived-value";
|
|
1596
1629
|
if (!enabled.has(guard)) return;
|
|
@@ -1623,7 +1656,7 @@ const rulePreferStrictNumberGuards = createRule({
|
|
|
1623
1656
|
"FunctionExpression": enterFunction,
|
|
1624
1657
|
"FunctionExpression:exit": exitFunction,
|
|
1625
1658
|
"LogicalExpression": (node) => {
|
|
1626
|
-
if (!enabled.has("write-explicit-condition") || node.operator !== "||" || node.right.type !== AST_NODE_TYPES.Literal || typeof node.right.value !== "number") return;
|
|
1659
|
+
if (!enabled.has("write-explicit-condition") || node.operator !== "||" || node.right.type !== AST_NODE_TYPES.Literal || typeof node.right.value !== "number" || node.right.value === 0) return;
|
|
1627
1660
|
context.report({
|
|
1628
1661
|
node,
|
|
1629
1662
|
messageId: "writeExplicitCondition"
|
|
@@ -1690,6 +1723,7 @@ const imports = async (options) => {
|
|
|
1690
1723
|
const stylisticEnabled = stylistic !== false;
|
|
1691
1724
|
return [{
|
|
1692
1725
|
name: "moso/imports",
|
|
1726
|
+
files: [GLOB_SCRIPT],
|
|
1693
1727
|
plugins: {
|
|
1694
1728
|
"@moso": memoize(rules_default, "@moso/eslint-plugin"),
|
|
1695
1729
|
"import-lite": memoize(importLite, "eslint-plugin-import-lite")
|
|
@@ -2110,8 +2144,7 @@ const jsdoc = async (options) => {
|
|
|
2110
2144
|
"jsdoc/require-hyphen-before-param-description": "warn",
|
|
2111
2145
|
"jsdoc/require-throws": "warn",
|
|
2112
2146
|
"jsdoc/require-throws-description": "warn",
|
|
2113
|
-
"jsdoc/require-yields-description": "error"
|
|
2114
|
-
"jsdoc/sort-tags": "off"
|
|
2147
|
+
"jsdoc/require-yields-description": "error"
|
|
2115
2148
|
},
|
|
2116
2149
|
...overrides
|
|
2117
2150
|
}
|
|
@@ -2131,6 +2164,8 @@ const jsonc = async (options) => {
|
|
|
2131
2164
|
files,
|
|
2132
2165
|
languageOptions: { parser: memoize(jsoncParser, "jsonc-eslint-parser") },
|
|
2133
2166
|
rules: {
|
|
2167
|
+
"@stylistic/lines-around-comment": "off",
|
|
2168
|
+
"@stylistic/list-style": "off",
|
|
2134
2169
|
"jsonc/no-bigint-literals": "error",
|
|
2135
2170
|
"jsonc/no-binary-expression": "error",
|
|
2136
2171
|
"jsonc/no-binary-numeric-literals": "error",
|
|
@@ -2177,6 +2212,46 @@ const jsonc = async (options) => {
|
|
|
2177
2212
|
}
|
|
2178
2213
|
}];
|
|
2179
2214
|
};
|
|
2215
|
+
// src/configs/jsx-a11y-rules.ts
|
|
2216
|
+
const jsxA11yRules = (jsxA11yPlugin, lessOpinionated) => {
|
|
2217
|
+
if (lessOpinionated) {
|
|
2218
|
+
assert.ok(!Array.isArray(jsxA11yPlugin.flatConfigs.recommended));
|
|
2219
|
+
return jsxA11yPlugin.flatConfigs.recommended.rules;
|
|
2220
|
+
}
|
|
2221
|
+
return {
|
|
2222
|
+
"jsx-a11y/alt-text": ["warn", {
|
|
2223
|
+
elements: ["img"],
|
|
2224
|
+
img: ["Image"]
|
|
2225
|
+
}],
|
|
2226
|
+
"jsx-a11y/aria-props": "warn",
|
|
2227
|
+
"jsx-a11y/aria-proptypes": "warn",
|
|
2228
|
+
"jsx-a11y/aria-role": "warn",
|
|
2229
|
+
"jsx-a11y/aria-unsupported-elements": "warn",
|
|
2230
|
+
"jsx-a11y/iframe-has-title": "warn",
|
|
2231
|
+
"jsx-a11y/no-access-key": "warn",
|
|
2232
|
+
"jsx-a11y/no-static-element-interactions": "warn",
|
|
2233
|
+
"jsx-a11y/role-has-required-aria-props": "warn",
|
|
2234
|
+
"jsx-a11y/role-supports-aria-props": "warn",
|
|
2235
|
+
"jsx-a11y/tabindex-no-positive": "warn",
|
|
2236
|
+
"jsx-a11y/anchor-ambiguous-text": "off",
|
|
2237
|
+
"jsx-a11y/interactive-supports-focus": ["error", { tabbable: [
|
|
2238
|
+
"button",
|
|
2239
|
+
"checkbox",
|
|
2240
|
+
"link",
|
|
2241
|
+
"progressbar",
|
|
2242
|
+
"searchbox",
|
|
2243
|
+
"slider",
|
|
2244
|
+
"spinbutton",
|
|
2245
|
+
"switch",
|
|
2246
|
+
"textbox"
|
|
2247
|
+
] }],
|
|
2248
|
+
"jsx-a11y/no-noninteractive-element-interactions": ["error", {
|
|
2249
|
+
body: ["onError", "onLoad"],
|
|
2250
|
+
iframe: ["onError", "onLoad"],
|
|
2251
|
+
img: ["onError", "onLoad"]
|
|
2252
|
+
}]
|
|
2253
|
+
};
|
|
2254
|
+
};
|
|
2180
2255
|
// src/configs/jsx.ts
|
|
2181
2256
|
const jsx = async (options) => {
|
|
2182
2257
|
const { a11y, files, lessOpinionated, overrides, overridesA11y, stylistic } = options;
|
|
@@ -2200,40 +2275,7 @@ const jsx = async (options) => {
|
|
|
2200
2275
|
"@stylistic/jsx-one-expression-per-line": "off"
|
|
2201
2276
|
},
|
|
2202
2277
|
...jsxA11yPlugin && {
|
|
2203
|
-
...
|
|
2204
|
-
"jsx-a11y/alt-text": ["warn", {
|
|
2205
|
-
elements: ["img"],
|
|
2206
|
-
img: ["Image"]
|
|
2207
|
-
}],
|
|
2208
|
-
"jsx-a11y/aria-props": "warn",
|
|
2209
|
-
"jsx-a11y/aria-proptypes": "warn",
|
|
2210
|
-
"jsx-a11y/aria-role": "warn",
|
|
2211
|
-
"jsx-a11y/aria-unsupported-elements": "warn",
|
|
2212
|
-
"jsx-a11y/iframe-has-title": "warn",
|
|
2213
|
-
"jsx-a11y/no-access-key": "warn",
|
|
2214
|
-
"jsx-a11y/no-static-element-interactions": "warn",
|
|
2215
|
-
"jsx-a11y/role-has-required-aria-props": "warn",
|
|
2216
|
-
"jsx-a11y/role-supports-aria-props": "warn",
|
|
2217
|
-
"jsx-a11y/tabindex-no-positive": "warn",
|
|
2218
|
-
"jsx-a11y/anchor-ambiguous-text": "off",
|
|
2219
|
-
"jsx-a11y/interactive-supports-focus": ["error", { tabbable: [
|
|
2220
|
-
"button",
|
|
2221
|
-
"checkbox",
|
|
2222
|
-
"link",
|
|
2223
|
-
"progressbar",
|
|
2224
|
-
"searchbox",
|
|
2225
|
-
"slider",
|
|
2226
|
-
"spinbutton",
|
|
2227
|
-
"switch",
|
|
2228
|
-
"textbox"
|
|
2229
|
-
] }],
|
|
2230
|
-
"jsx-a11y/label-has-for": "off",
|
|
2231
|
-
"jsx-a11y/no-noninteractive-element-interactions": ["error", {
|
|
2232
|
-
body: ["onError", "onLoad"],
|
|
2233
|
-
iframe: ["onError", "onLoad"],
|
|
2234
|
-
img: ["onError", "onLoad"]
|
|
2235
|
-
}]
|
|
2236
|
-
},
|
|
2278
|
+
...jsxA11yRules(jsxA11yPlugin, lessOpinionated),
|
|
2237
2279
|
...overridesA11y
|
|
2238
2280
|
},
|
|
2239
2281
|
...overrides
|
|
@@ -2254,10 +2296,7 @@ const nextjs = async (options) => {
|
|
|
2254
2296
|
parserOptions: { ecmaFeatures: { jsx: true } },
|
|
2255
2297
|
sourceType: "module"
|
|
2256
2298
|
},
|
|
2257
|
-
settings: {
|
|
2258
|
-
react: { version: "detect" },
|
|
2259
|
-
...rootDir !== void 0 && { next: { rootDir } }
|
|
2260
|
-
},
|
|
2299
|
+
settings: { ...rootDir !== void 0 && { next: { rootDir } } },
|
|
2261
2300
|
rules: {
|
|
2262
2301
|
...(assert.ok(!Array.isArray(nextjsPlugin.configs.recommended)), nextjsPlugin.configs.recommended.rules),
|
|
2263
2302
|
...(assert.ok(!Array.isArray(nextjsPlugin.configs["core-web-vitals"])), nextjsPlugin.configs["core-web-vitals"].rules),
|
|
@@ -2351,16 +2390,15 @@ const node = async (options) => {
|
|
|
2351
2390
|
name: "moso/node/rules",
|
|
2352
2391
|
files: files ?? ["**/*.?([cm])[jt]s?(x)"],
|
|
2353
2392
|
languageOptions: { globals: { ...globals.node } },
|
|
2354
|
-
settings: { node: { version: "^22.22.3 || >=24" } },
|
|
2355
2393
|
rules: {
|
|
2356
2394
|
...(assert.ok(!Array.isArray(nodePlugin.configs["flat/recommended"])), renameNodeRules(nodePlugin.configs["flat/recommended"].rules ?? {}, "n", "node")),
|
|
2357
2395
|
"node/no-unpublished-import": "warn",
|
|
2396
|
+
"node/no-unsupported-features/node-builtins": ["error", { allowUnflagged: true }],
|
|
2358
2397
|
"node/prefer-global/process": options.hasReact ? "off" : ["error", "never"],
|
|
2359
2398
|
"node/prefer-global/text-decoder": ["error", "never"],
|
|
2360
2399
|
"node/prefer-global/text-encoder": ["error", "never"],
|
|
2361
2400
|
"node/prefer-global/url-search-params": ["error", "always"],
|
|
2362
2401
|
...!lessOpinionated && {
|
|
2363
|
-
"node/no-top-level-await": "off",
|
|
2364
2402
|
"node/callback-return": "error",
|
|
2365
2403
|
"node/handle-callback-err": ["error", "^(err|error)$"],
|
|
2366
2404
|
"node/no-callback-literal": "error",
|
|
@@ -2413,6 +2451,7 @@ const perfectionist = async (options) => {
|
|
|
2413
2451
|
const [perfectionistPlugin] = await loadPackages(["eslint-plugin-perfectionist"]);
|
|
2414
2452
|
return [{
|
|
2415
2453
|
name: "moso/perfectionist",
|
|
2454
|
+
files: [GLOB_SCRIPT],
|
|
2416
2455
|
plugins: { "perfectionist": memoize(perfectionistPlugin, "eslint-plugin-perfectionist") },
|
|
2417
2456
|
rules: {
|
|
2418
2457
|
"perfectionist/sort-array-includes": ["error", {
|
|
@@ -2688,6 +2727,8 @@ const preact = async (options) => {
|
|
|
2688
2727
|
ignore: []
|
|
2689
2728
|
}],
|
|
2690
2729
|
"@stylistic/jsx-self-closing-comp": "error",
|
|
2730
|
+
"@stylistic/jsx-shorthand-boolean": "error",
|
|
2731
|
+
"@stylistic/jsx-shorthand-fragment": "error",
|
|
2691
2732
|
"@stylistic/jsx-tag-spacing": ["error", {
|
|
2692
2733
|
afterOpening: "never",
|
|
2693
2734
|
closingSlash: "never",
|
|
@@ -2703,7 +2744,10 @@ const preact = async (options) => {
|
|
|
2703
2744
|
prop: "ignore",
|
|
2704
2745
|
return: "parens-new-line"
|
|
2705
2746
|
}],
|
|
2706
|
-
"@stylistic/no-multi-spaces": "error"
|
|
2747
|
+
"@stylistic/no-multi-spaces": ["error", { exceptions: {
|
|
2748
|
+
ImportAttribute: true,
|
|
2749
|
+
Property: true
|
|
2750
|
+
} }]
|
|
2707
2751
|
}
|
|
2708
2752
|
},
|
|
2709
2753
|
...(assert.ok(!Array.isArray(reactHooksPlugin.configs?.["recommended-latest"])), reactHooksPlugin.configs?.["recommended-latest"].rules),
|
|
@@ -2712,38 +2756,7 @@ const preact = async (options) => {
|
|
|
2712
2756
|
allowConstantExport: true
|
|
2713
2757
|
}],
|
|
2714
2758
|
...jsxA11yPlugin && {
|
|
2715
|
-
|
|
2716
|
-
elements: ["img"],
|
|
2717
|
-
img: ["Image"]
|
|
2718
|
-
}],
|
|
2719
|
-
"jsx-a11y/aria-props": "warn",
|
|
2720
|
-
"jsx-a11y/aria-proptypes": "warn",
|
|
2721
|
-
"jsx-a11y/aria-role": "warn",
|
|
2722
|
-
"jsx-a11y/aria-unsupported-elements": "warn",
|
|
2723
|
-
"jsx-a11y/iframe-has-title": "warn",
|
|
2724
|
-
"jsx-a11y/no-access-key": "warn",
|
|
2725
|
-
"jsx-a11y/no-static-element-interactions": "warn",
|
|
2726
|
-
"jsx-a11y/role-has-required-aria-props": "warn",
|
|
2727
|
-
"jsx-a11y/role-supports-aria-props": "warn",
|
|
2728
|
-
"jsx-a11y/tabindex-no-positive": "warn",
|
|
2729
|
-
"jsx-a11y/anchor-ambiguous-text": "off",
|
|
2730
|
-
"jsx-a11y/interactive-supports-focus": ["error", { tabbable: [
|
|
2731
|
-
"button",
|
|
2732
|
-
"checkbox",
|
|
2733
|
-
"link",
|
|
2734
|
-
"progressbar",
|
|
2735
|
-
"searchbox",
|
|
2736
|
-
"slider",
|
|
2737
|
-
"spinbutton",
|
|
2738
|
-
"switch",
|
|
2739
|
-
"textbox"
|
|
2740
|
-
] }],
|
|
2741
|
-
"jsx-a11y/label-has-for": "off",
|
|
2742
|
-
"jsx-a11y/no-noninteractive-element-interactions": ["error", {
|
|
2743
|
-
body: ["onError", "onLoad"],
|
|
2744
|
-
iframe: ["onError", "onLoad"],
|
|
2745
|
-
img: ["onError", "onLoad"]
|
|
2746
|
-
}],
|
|
2759
|
+
...jsxA11yRules(jsxA11yPlugin, lessOpinionated),
|
|
2747
2760
|
...overridesA11y
|
|
2748
2761
|
},
|
|
2749
2762
|
...overrides
|
|
@@ -2754,7 +2767,8 @@ const preact = async (options) => {
|
|
|
2754
2767
|
files: filesTypeAware,
|
|
2755
2768
|
ignores: ignoresTypeAware,
|
|
2756
2769
|
rules: {
|
|
2757
|
-
|
|
2770
|
+
"@eslint-react/no-leaked-conditional-rendering": "error",
|
|
2771
|
+
...!lessOpinionated && { "@eslint-react/no-unused-props": "warn" },
|
|
2758
2772
|
...overridesTypeAware
|
|
2759
2773
|
}
|
|
2760
2774
|
}] : []
|
|
@@ -2766,6 +2780,7 @@ const promise = async (options) => {
|
|
|
2766
2780
|
const [promisePlugin] = await loadPackages(["eslint-plugin-promise"]);
|
|
2767
2781
|
return [{
|
|
2768
2782
|
name: "moso/promise",
|
|
2783
|
+
files: [GLOB_SCRIPT],
|
|
2769
2784
|
plugins: { "promise": memoize(promisePlugin, "eslint-plugin-promise") },
|
|
2770
2785
|
rules: {
|
|
2771
2786
|
"promise/no-callback-in-promise": "error",
|
|
@@ -2778,7 +2793,6 @@ const promise = async (options) => {
|
|
|
2778
2793
|
"promise/valid-params": "error",
|
|
2779
2794
|
...!lessOpinionated && {
|
|
2780
2795
|
"promise/always-return": typescript ? "off" : ["error", { ignoreLastCallback: true }],
|
|
2781
|
-
"promise/avoid-new": "off",
|
|
2782
2796
|
"promise/catch-or-return": ["error", {
|
|
2783
2797
|
allowFinally: true,
|
|
2784
2798
|
terminationMethod: [
|
|
@@ -2786,8 +2800,7 @@ const promise = async (options) => {
|
|
|
2786
2800
|
"asCallback",
|
|
2787
2801
|
"finally"
|
|
2788
2802
|
]
|
|
2789
|
-
}]
|
|
2790
|
-
"promise/no-native": "off"
|
|
2803
|
+
}]
|
|
2791
2804
|
},
|
|
2792
2805
|
...overrides
|
|
2793
2806
|
}
|
|
@@ -2874,6 +2887,8 @@ const react = async (options) => {
|
|
|
2874
2887
|
ignore: []
|
|
2875
2888
|
}],
|
|
2876
2889
|
"@stylistic/jsx-self-closing-comp": "error",
|
|
2890
|
+
"@stylistic/jsx-shorthand-boolean": "error",
|
|
2891
|
+
"@stylistic/jsx-shorthand-fragment": "error",
|
|
2877
2892
|
"@stylistic/jsx-tag-spacing": ["error", {
|
|
2878
2893
|
afterOpening: "never",
|
|
2879
2894
|
closingSlash: "never",
|
|
@@ -2889,9 +2904,13 @@ const react = async (options) => {
|
|
|
2889
2904
|
prop: "ignore",
|
|
2890
2905
|
return: "parens-new-line"
|
|
2891
2906
|
}],
|
|
2892
|
-
"@stylistic/no-multi-spaces": "error"
|
|
2907
|
+
"@stylistic/no-multi-spaces": ["error", { exceptions: {
|
|
2908
|
+
ImportAttribute: true,
|
|
2909
|
+
Property: true
|
|
2910
|
+
} }]
|
|
2893
2911
|
}
|
|
2894
2912
|
},
|
|
2913
|
+
"@eslint-react/set-state-in-effect": "off",
|
|
2895
2914
|
"react-hooks/exhaustive-deps": ["error", { "additionalHooks": `(${reactHooks})` }],
|
|
2896
2915
|
"react-hooks/rules-of-hooks": "error",
|
|
2897
2916
|
"react-refresh/only-export-components": ["warn", {
|
|
@@ -2928,38 +2947,7 @@ const react = async (options) => {
|
|
|
2928
2947
|
] : []]
|
|
2929
2948
|
}],
|
|
2930
2949
|
...jsxA11yPlugin && {
|
|
2931
|
-
|
|
2932
|
-
elements: ["img"],
|
|
2933
|
-
img: ["Image"]
|
|
2934
|
-
}],
|
|
2935
|
-
"jsx-a11y/aria-props": "warn",
|
|
2936
|
-
"jsx-a11y/aria-proptypes": "warn",
|
|
2937
|
-
"jsx-a11y/aria-role": "warn",
|
|
2938
|
-
"jsx-a11y/aria-unsupported-elements": "warn",
|
|
2939
|
-
"jsx-a11y/iframe-has-title": "warn",
|
|
2940
|
-
"jsx-a11y/no-access-key": "warn",
|
|
2941
|
-
"jsx-a11y/no-static-element-interactions": "warn",
|
|
2942
|
-
"jsx-a11y/role-has-required-aria-props": "warn",
|
|
2943
|
-
"jsx-a11y/role-supports-aria-props": "warn",
|
|
2944
|
-
"jsx-a11y/tabindex-no-positive": "warn",
|
|
2945
|
-
"jsx-a11y/anchor-ambiguous-text": "off",
|
|
2946
|
-
"jsx-a11y/interactive-supports-focus": ["error", { tabbable: [
|
|
2947
|
-
"button",
|
|
2948
|
-
"checkbox",
|
|
2949
|
-
"link",
|
|
2950
|
-
"progressbar",
|
|
2951
|
-
"searchbox",
|
|
2952
|
-
"slider",
|
|
2953
|
-
"spinbutton",
|
|
2954
|
-
"switch",
|
|
2955
|
-
"textbox"
|
|
2956
|
-
] }],
|
|
2957
|
-
"jsx-a11y/label-has-for": "off",
|
|
2958
|
-
"jsx-a11y/no-noninteractive-element-interactions": ["error", {
|
|
2959
|
-
body: ["onError", "onLoad"],
|
|
2960
|
-
iframe: ["onError", "onLoad"],
|
|
2961
|
-
img: ["onError", "onLoad"]
|
|
2962
|
-
}],
|
|
2950
|
+
...jsxA11yRules(jsxA11yPlugin, lessOpinionated),
|
|
2963
2951
|
...overridesA11y
|
|
2964
2952
|
},
|
|
2965
2953
|
...overrides
|
|
@@ -2978,10 +2966,8 @@ const react = async (options) => {
|
|
|
2978
2966
|
files: filesTypeAware,
|
|
2979
2967
|
ignores: ignoresTypeAware,
|
|
2980
2968
|
rules: {
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
"@eslint-react/no-leaked-conditional-rendering": "error"
|
|
2984
|
-
},
|
|
2969
|
+
"@eslint-react/no-leaked-conditional-rendering": "error",
|
|
2970
|
+
...!lessOpinionated && { "@eslint-react/no-unused-props": "warn" },
|
|
2985
2971
|
"react-hooks/exhaustive-deps": ["error", { "additionalHooks": `(${reactHooks}|useAbortableEffect)` }],
|
|
2986
2972
|
"@typescript-eslint/class-methods-use-this": ["error", {
|
|
2987
2973
|
exceptMethods: [
|
|
@@ -3015,13 +3001,10 @@ const regexp = async (options) => {
|
|
|
3015
3001
|
const [regexpPlugin] = await loadPackages(["eslint-plugin-regexp"]);
|
|
3016
3002
|
return [{
|
|
3017
3003
|
name: "moso/regexp",
|
|
3004
|
+
files: [GLOB_SCRIPT],
|
|
3018
3005
|
plugins: { "regexp": memoize(regexpPlugin, "eslint-plugin-regexp") },
|
|
3019
3006
|
rules: {
|
|
3020
|
-
"no-empty-character-class": "off",
|
|
3021
|
-
"no-invalid-regexp": "off",
|
|
3022
|
-
"no-useless-backreference": "off",
|
|
3023
3007
|
...(assert.ok(!Array.isArray(regexpPlugin.configs["flat/recommended"])), regexpPlugin.configs["flat/recommended"].rules),
|
|
3024
|
-
"regexp/no-super-linear-backtracking": "error",
|
|
3025
3008
|
"regexp/strict": "off",
|
|
3026
3009
|
...overrides
|
|
3027
3010
|
}
|
|
@@ -3035,6 +3018,7 @@ const security = async (options) => {
|
|
|
3035
3018
|
const baseRules = severity === "lite" ? recommended?.rules : Object.fromEntries(Object.keys(recommended?.rules ?? {}).map((key) => [key, "error"]));
|
|
3036
3019
|
return [{
|
|
3037
3020
|
name: "moso/security",
|
|
3021
|
+
files: [GLOB_SCRIPT],
|
|
3038
3022
|
plugins: { security: memoize(securityPlugin, "eslint-plugin-security") },
|
|
3039
3023
|
rules: {
|
|
3040
3024
|
...baseRules,
|
|
@@ -3060,10 +3044,6 @@ const sortPackageJson = (options = {}) => {
|
|
|
3060
3044
|
name: "moso/sort/package-json",
|
|
3061
3045
|
files: ["**/package.json"],
|
|
3062
3046
|
rules: {
|
|
3063
|
-
"jsonc/sort-array-values": ["error", {
|
|
3064
|
-
order: { type: "asc" },
|
|
3065
|
-
pathPattern: "^files$"
|
|
3066
|
-
}],
|
|
3067
3047
|
"jsonc/sort-keys": [
|
|
3068
3048
|
"error",
|
|
3069
3049
|
{
|
|
@@ -3316,21 +3296,6 @@ const stylistic = async (options) => {
|
|
|
3316
3296
|
rules: {
|
|
3317
3297
|
...config.rules,
|
|
3318
3298
|
...!lessOpinionated && {
|
|
3319
|
-
...!experimental && {
|
|
3320
|
-
"@stylistic/array-element-newline": ["error", {
|
|
3321
|
-
consistent: true,
|
|
3322
|
-
minItems: 4,
|
|
3323
|
-
multiline: true
|
|
3324
|
-
}],
|
|
3325
|
-
"@stylistic/function-call-argument-newline": ["error", "consistent"],
|
|
3326
|
-
"@stylistic/function-paren-newline": ["error", "consistent"],
|
|
3327
|
-
"@stylistic/object-curly-newline": ["error", {
|
|
3328
|
-
consistent: true,
|
|
3329
|
-
minProperties: 4,
|
|
3330
|
-
multiline: true
|
|
3331
|
-
}],
|
|
3332
|
-
"@stylistic/object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }]
|
|
3333
|
-
},
|
|
3334
3299
|
"@stylistic/arrow-parens": ["error", "always"],
|
|
3335
3300
|
"@stylistic/block-spacing": ["error", "always"],
|
|
3336
3301
|
"@stylistic/brace-style": [
|
|
@@ -3356,7 +3321,7 @@ const stylistic = async (options) => {
|
|
|
3356
3321
|
"@stylistic/dot-location": ["error", "property"],
|
|
3357
3322
|
"@stylistic/eol-last": ["error", "always"],
|
|
3358
3323
|
"@stylistic/generator-star-spacing": ["error", "after"],
|
|
3359
|
-
"@stylistic/indent":
|
|
3324
|
+
"@stylistic/indent": [
|
|
3360
3325
|
"error",
|
|
3361
3326
|
indent,
|
|
3362
3327
|
{
|
|
@@ -3451,7 +3416,13 @@ const stylistic = async (options) => {
|
|
|
3451
3416
|
["in", "instanceof"]
|
|
3452
3417
|
]
|
|
3453
3418
|
}],
|
|
3454
|
-
"@stylistic/no-multi-spaces": ["error", {
|
|
3419
|
+
"@stylistic/no-multi-spaces": ["error", {
|
|
3420
|
+
exceptions: {
|
|
3421
|
+
ImportAttribute: true,
|
|
3422
|
+
Property: true
|
|
3423
|
+
},
|
|
3424
|
+
ignoreEOLComments: true
|
|
3425
|
+
}],
|
|
3455
3426
|
"@stylistic/no-tabs": "error",
|
|
3456
3427
|
"@stylistic/no-trailing-spaces": ["error", {
|
|
3457
3428
|
ignoreComments: true,
|
|
@@ -3532,6 +3503,7 @@ const stylistic = async (options) => {
|
|
|
3532
3503
|
"@stylistic/type-annotation-spacing": "error"
|
|
3533
3504
|
}
|
|
3534
3505
|
},
|
|
3506
|
+
...typescript && { "@stylistic/indent": "off" },
|
|
3535
3507
|
...overrides
|
|
3536
3508
|
}
|
|
3537
3509
|
}];
|
|
@@ -3621,7 +3593,7 @@ const tailwind = async (options) => {
|
|
|
3621
3593
|
const stylisticEnabled = stylistic !== false;
|
|
3622
3594
|
return [{
|
|
3623
3595
|
name: "moso/tailwind",
|
|
3624
|
-
settings: { "better-tailwindcss": version === 4 ? { entryPoint } : { config } },
|
|
3596
|
+
settings: { "better-tailwindcss": version === 4 ? { entryPoint } : { tailwindConfig: config } },
|
|
3625
3597
|
plugins: { "tailwind-better": memoize(tailwindPlugin, "eslint-plugin-better-tailwindcss") },
|
|
3626
3598
|
rules: {
|
|
3627
3599
|
"tailwind-better/no-conflicting-classes": "error",
|
|
@@ -3664,7 +3636,6 @@ const test = async (options) => {
|
|
|
3664
3636
|
const vitestPlugin = await interopDefault(import("@vitest/eslint-plugin"));
|
|
3665
3637
|
return [{
|
|
3666
3638
|
name: "moso/test/setup",
|
|
3667
|
-
languageOptions: { globals: { ...vitestPlugin.environments.env.globals } },
|
|
3668
3639
|
settings: { vitest: { typecheck: true } },
|
|
3669
3640
|
plugins: {
|
|
3670
3641
|
"no-only-tests": memoize(noOnlyTestsPlugin, "eslint-plugin-no-only-tests"),
|
|
@@ -3673,6 +3644,7 @@ const test = async (options) => {
|
|
|
3673
3644
|
}, {
|
|
3674
3645
|
name: "moso/test/rules",
|
|
3675
3646
|
files,
|
|
3647
|
+
languageOptions: { globals: { ...vitestPlugin.environments.env.globals } },
|
|
3676
3648
|
rules: {
|
|
3677
3649
|
...(assert.ok(!Array.isArray(functionalPlugin?.configs.off)), functionalPlugin?.configs.off.rules),
|
|
3678
3650
|
"no-only-tests/no-only-tests": isInEditor ? "warn" : "error",
|
|
@@ -3681,6 +3653,7 @@ const test = async (options) => {
|
|
|
3681
3653
|
fn: "it",
|
|
3682
3654
|
withinDescribe: "it"
|
|
3683
3655
|
}],
|
|
3656
|
+
"vitest/no-focused-tests": "off",
|
|
3684
3657
|
"vitest/prefer-hooks-in-order": "error",
|
|
3685
3658
|
"vitest/prefer-lowercase-title": "error",
|
|
3686
3659
|
"vitest/valid-expect": "off",
|
|
@@ -3737,7 +3710,7 @@ const toml = async (options) => {
|
|
|
3737
3710
|
};
|
|
3738
3711
|
// src/configs/typescript.ts
|
|
3739
3712
|
const typescript = async (options) => {
|
|
3740
|
-
const { componentExts,
|
|
3713
|
+
const { componentExts, erasableOnly, files, filesTypeAware, functionalEnforcement, hasSvelte, ignoresTypeAware, lessOpinionated, mode, overrides, overridesTypeAware, parserOptions, projectRoot, stylistic, unsafe = "warn" } = options;
|
|
3741
3714
|
const [tsEslintPlugin, tsEslintParser] = await loadPackages(["@typescript-eslint/eslint-plugin", "@typescript-eslint/parser"]);
|
|
3742
3715
|
const [erasableSyntaxPlugin] = erasableOnly === false || lessOpinionated ? [void 0] : await loadPackages(["eslint-plugin-erasable-syntax-only"]);
|
|
3743
3716
|
const isTypeAware = typeof projectRoot === "string" && parserOptions.projectService !== false;
|
|
@@ -3856,8 +3829,8 @@ const typescript = async (options) => {
|
|
|
3856
3829
|
extraFileExtensions: componentExts.map((ext) => `.${ext}`),
|
|
3857
3830
|
jsxPragma: void 0,
|
|
3858
3831
|
sourceType: "module",
|
|
3859
|
-
|
|
3860
|
-
|
|
3832
|
+
...parserOptions,
|
|
3833
|
+
projectService: false
|
|
3861
3834
|
}
|
|
3862
3835
|
},
|
|
3863
3836
|
plugins: { "@typescript-eslint": memoize(tsEslintPlugin, "@typescript-eslint/eslint-plugin") }
|
|
@@ -3889,8 +3862,7 @@ const typescript = async (options) => {
|
|
|
3889
3862
|
"@typescript-eslint/unified-signatures": "off"
|
|
3890
3863
|
} : {
|
|
3891
3864
|
...(assert.ok(!Array.isArray(tsEslintPlugin.configs?.strict)), tsEslintPlugin.configs?.strict.rules),
|
|
3892
|
-
"@moso/no-force-cast-via-top-type": "error"
|
|
3893
|
-
"@typescript-eslint/consistent-type-definitions": ["error", "type"]
|
|
3865
|
+
"@moso/no-force-cast-via-top-type": "error"
|
|
3894
3866
|
},
|
|
3895
3867
|
...stylisticEnabled && {
|
|
3896
3868
|
...(assert.ok(!Array.isArray(tsEslintPlugin.configs?.stylistic)), tsEslintPlugin.configs?.stylistic.rules),
|
|
@@ -3942,211 +3914,171 @@ const typescript = async (options) => {
|
|
|
3942
3914
|
}],
|
|
3943
3915
|
"@typescript-eslint/no-useless-constructor": "error",
|
|
3944
3916
|
"@typescript-eslint/parameter-properties": "off",
|
|
3945
|
-
...functionalEnforcement !== "none" && mode !== "library" && {
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
"
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
identifiers: "I?Immutable.+",
|
|
3953
|
-
immutability: "Immutable",
|
|
3954
|
-
comparator: "AtLeast"
|
|
3955
|
-
},
|
|
3956
|
-
{
|
|
3957
|
-
identifiers: "I?ReadonlyDeep.+",
|
|
3958
|
-
immutability: "ReadonlyDeep",
|
|
3959
|
-
comparator: "AtLeast"
|
|
3960
|
-
},
|
|
3961
|
-
{
|
|
3962
|
-
identifiers: "I?Readonly.+",
|
|
3963
|
-
immutability: "ReadonlyShallow",
|
|
3964
|
-
comparator: "AtLeast",
|
|
3965
|
-
fixer: [{
|
|
3966
|
-
pattern: "^(Array|Map|Set)<(.+)>$",
|
|
3967
|
-
replace: "Readonly$1<$2>"
|
|
3968
|
-
}, {
|
|
3969
|
-
pattern: "^(.+)$",
|
|
3970
|
-
replace: "Readonly<$1>"
|
|
3971
|
-
}]
|
|
3972
|
-
},
|
|
3973
|
-
{
|
|
3974
|
-
identifiers: "I?Mutable.+",
|
|
3975
|
-
immutability: "Mutable",
|
|
3976
|
-
comparator: "AtMost",
|
|
3977
|
-
fixer: [{
|
|
3978
|
-
pattern: "^Readonly(Array|Map|Set)<(.+)>$",
|
|
3979
|
-
replace: "$1<$2>"
|
|
3980
|
-
}, {
|
|
3981
|
-
pattern: "^Readonly<(.+)>$",
|
|
3982
|
-
replace: "$1"
|
|
3983
|
-
}]
|
|
3984
|
-
}
|
|
3985
|
-
] }]
|
|
3917
|
+
...functionalEnforcement !== "none" && mode !== "library" && { "@typescript-eslint/naming-convention": [
|
|
3918
|
+
"error",
|
|
3919
|
+
{
|
|
3920
|
+
selector: "default",
|
|
3921
|
+
format: ["camelCase", "PascalCase"],
|
|
3922
|
+
leadingUnderscore: "allow",
|
|
3923
|
+
trailingUnderscore: "forbid"
|
|
3986
3924
|
},
|
|
3987
|
-
|
|
3988
|
-
"
|
|
3989
|
-
{
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
leadingUnderscore: "allow",
|
|
3993
|
-
trailingUnderscore: "forbid"
|
|
3994
|
-
},
|
|
3995
|
-
{
|
|
3996
|
-
selector: "variableLike",
|
|
3997
|
-
filter: {
|
|
3998
|
-
regex: "_[^_]+",
|
|
3999
|
-
match: true
|
|
4000
|
-
},
|
|
4001
|
-
format: ["camelCase", "PascalCase"],
|
|
4002
|
-
prefix: ["mut_", "Mut_"],
|
|
4003
|
-
leadingUnderscore: "forbid",
|
|
4004
|
-
trailingUnderscore: "forbid"
|
|
4005
|
-
},
|
|
4006
|
-
{
|
|
4007
|
-
selector: "variableLike",
|
|
4008
|
-
format: ["camelCase", "PascalCase"],
|
|
4009
|
-
leadingUnderscore: "allow",
|
|
4010
|
-
trailingUnderscore: "forbid"
|
|
4011
|
-
},
|
|
4012
|
-
{
|
|
4013
|
-
selector: "variable",
|
|
4014
|
-
format: [
|
|
4015
|
-
"camelCase",
|
|
4016
|
-
"PascalCase",
|
|
4017
|
-
"UPPER_CASE"
|
|
4018
|
-
],
|
|
4019
|
-
prefix: ["mut_", "Mut_"],
|
|
4020
|
-
leadingUnderscore: "forbid",
|
|
4021
|
-
trailingUnderscore: "forbid"
|
|
4022
|
-
},
|
|
4023
|
-
{
|
|
4024
|
-
selector: "variable",
|
|
4025
|
-
filter: {
|
|
4026
|
-
regex: "^[A-Z0-9_]+$",
|
|
4027
|
-
match: true
|
|
4028
|
-
},
|
|
4029
|
-
format: ["UPPER_CASE"],
|
|
4030
|
-
modifiers: ["const"],
|
|
4031
|
-
leadingUnderscore: "forbid",
|
|
4032
|
-
trailingUnderscore: "forbid"
|
|
4033
|
-
},
|
|
4034
|
-
{
|
|
4035
|
-
selector: "variable",
|
|
4036
|
-
filter: {
|
|
4037
|
-
regex: "^[mM]ut_[^_]+",
|
|
4038
|
-
match: true
|
|
4039
|
-
},
|
|
4040
|
-
format: ["camelCase", "PascalCase"],
|
|
4041
|
-
modifiers: ["const"],
|
|
4042
|
-
prefix: ["mut_", "Mut_"],
|
|
4043
|
-
leadingUnderscore: "forbid",
|
|
4044
|
-
trailingUnderscore: "forbid"
|
|
4045
|
-
},
|
|
4046
|
-
{
|
|
4047
|
-
selector: "variable",
|
|
4048
|
-
format: [
|
|
4049
|
-
"camelCase",
|
|
4050
|
-
"PascalCase",
|
|
4051
|
-
"UPPER_CASE"
|
|
4052
|
-
],
|
|
4053
|
-
modifiers: ["const"],
|
|
4054
|
-
leadingUnderscore: "allow",
|
|
4055
|
-
trailingUnderscore: "forbid"
|
|
4056
|
-
},
|
|
4057
|
-
{
|
|
4058
|
-
selector: "variable",
|
|
4059
|
-
format: null,
|
|
4060
|
-
modifiers: ["destructured"]
|
|
4061
|
-
},
|
|
4062
|
-
{
|
|
4063
|
-
selector: [
|
|
4064
|
-
"autoAccessor",
|
|
4065
|
-
"parameterProperty",
|
|
4066
|
-
"property"
|
|
4067
|
-
],
|
|
4068
|
-
filter: {
|
|
4069
|
-
regex: "^[A-Z0-9_]+$",
|
|
4070
|
-
match: true
|
|
4071
|
-
},
|
|
4072
|
-
format: ["UPPER_CASE"],
|
|
4073
|
-
leadingUnderscore: "forbid",
|
|
4074
|
-
trailingUnderscore: "forbid"
|
|
4075
|
-
},
|
|
4076
|
-
{
|
|
4077
|
-
selector: [
|
|
4078
|
-
"autoAccessor",
|
|
4079
|
-
"parameterProperty",
|
|
4080
|
-
"property"
|
|
4081
|
-
],
|
|
4082
|
-
filter: {
|
|
4083
|
-
regex: "^[mM]ut_[^_]+",
|
|
4084
|
-
match: true
|
|
4085
|
-
},
|
|
4086
|
-
format: ["camelCase", "PascalCase"],
|
|
4087
|
-
prefix: ["mut_", "Mut_"],
|
|
4088
|
-
leadingUnderscore: "forbid",
|
|
4089
|
-
trailingUnderscore: "forbid"
|
|
3925
|
+
{
|
|
3926
|
+
selector: "variableLike",
|
|
3927
|
+
filter: {
|
|
3928
|
+
regex: "_[^_]+",
|
|
3929
|
+
match: true
|
|
4090
3930
|
},
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
3931
|
+
format: ["camelCase", "PascalCase"],
|
|
3932
|
+
prefix: ["mut_", "Mut_"],
|
|
3933
|
+
leadingUnderscore: "forbid",
|
|
3934
|
+
trailingUnderscore: "forbid"
|
|
3935
|
+
},
|
|
3936
|
+
{
|
|
3937
|
+
selector: "variableLike",
|
|
3938
|
+
format: ["camelCase", "PascalCase"],
|
|
3939
|
+
leadingUnderscore: "allow",
|
|
3940
|
+
trailingUnderscore: "forbid"
|
|
3941
|
+
},
|
|
3942
|
+
{
|
|
3943
|
+
selector: "variable",
|
|
3944
|
+
format: [
|
|
3945
|
+
"camelCase",
|
|
3946
|
+
"PascalCase",
|
|
3947
|
+
"UPPER_CASE"
|
|
3948
|
+
],
|
|
3949
|
+
prefix: ["mut_", "Mut_"],
|
|
3950
|
+
leadingUnderscore: "forbid",
|
|
3951
|
+
trailingUnderscore: "forbid"
|
|
3952
|
+
},
|
|
3953
|
+
{
|
|
3954
|
+
selector: "variable",
|
|
3955
|
+
filter: {
|
|
3956
|
+
regex: "^[A-Z0-9_]+$",
|
|
3957
|
+
match: true
|
|
4105
3958
|
},
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
"UPPER_CASE"
|
|
4117
|
-
],
|
|
4118
|
-
leadingUnderscore: "allow",
|
|
4119
|
-
trailingUnderscore: "forbid"
|
|
3959
|
+
format: ["UPPER_CASE"],
|
|
3960
|
+
modifiers: ["const"],
|
|
3961
|
+
leadingUnderscore: "forbid",
|
|
3962
|
+
trailingUnderscore: "forbid"
|
|
3963
|
+
},
|
|
3964
|
+
{
|
|
3965
|
+
selector: "variable",
|
|
3966
|
+
filter: {
|
|
3967
|
+
regex: "^[mM]ut_[^_]+",
|
|
3968
|
+
match: true
|
|
4120
3969
|
},
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
3970
|
+
format: ["camelCase", "PascalCase"],
|
|
3971
|
+
modifiers: ["const"],
|
|
3972
|
+
prefix: ["mut_", "Mut_"],
|
|
3973
|
+
leadingUnderscore: "forbid",
|
|
3974
|
+
trailingUnderscore: "forbid"
|
|
3975
|
+
},
|
|
3976
|
+
{
|
|
3977
|
+
selector: "variable",
|
|
3978
|
+
format: [
|
|
3979
|
+
"camelCase",
|
|
3980
|
+
"PascalCase",
|
|
3981
|
+
"UPPER_CASE"
|
|
3982
|
+
],
|
|
3983
|
+
modifiers: ["const"],
|
|
3984
|
+
leadingUnderscore: "allow",
|
|
3985
|
+
trailingUnderscore: "forbid"
|
|
3986
|
+
},
|
|
3987
|
+
{
|
|
3988
|
+
selector: "variable",
|
|
3989
|
+
format: null,
|
|
3990
|
+
modifiers: ["destructured"]
|
|
3991
|
+
},
|
|
3992
|
+
{
|
|
3993
|
+
selector: [
|
|
3994
|
+
"autoAccessor",
|
|
3995
|
+
"parameterProperty",
|
|
3996
|
+
"property"
|
|
3997
|
+
],
|
|
3998
|
+
filter: {
|
|
3999
|
+
regex: "^[A-Z0-9_]+$",
|
|
4000
|
+
match: true
|
|
4126
4001
|
},
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4002
|
+
format: ["UPPER_CASE"],
|
|
4003
|
+
leadingUnderscore: "forbid",
|
|
4004
|
+
trailingUnderscore: "forbid"
|
|
4005
|
+
},
|
|
4006
|
+
{
|
|
4007
|
+
selector: [
|
|
4008
|
+
"autoAccessor",
|
|
4009
|
+
"parameterProperty",
|
|
4010
|
+
"property"
|
|
4011
|
+
],
|
|
4012
|
+
filter: {
|
|
4013
|
+
regex: "^[mM]ut_[^_]+",
|
|
4014
|
+
match: true
|
|
4132
4015
|
},
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4016
|
+
format: ["camelCase", "PascalCase"],
|
|
4017
|
+
prefix: ["mut_", "Mut_"],
|
|
4018
|
+
leadingUnderscore: "forbid",
|
|
4019
|
+
trailingUnderscore: "forbid"
|
|
4020
|
+
},
|
|
4021
|
+
{
|
|
4022
|
+
selector: [
|
|
4023
|
+
"autoAccessor",
|
|
4024
|
+
"parameterProperty",
|
|
4025
|
+
"property"
|
|
4026
|
+
],
|
|
4027
|
+
format: [
|
|
4028
|
+
"camelCase",
|
|
4029
|
+
"PascalCase",
|
|
4030
|
+
"UPPER_CASE"
|
|
4031
|
+
],
|
|
4032
|
+
modifiers: ["readonly"],
|
|
4033
|
+
leadingUnderscore: "allow",
|
|
4034
|
+
trailingUnderscore: "forbid"
|
|
4035
|
+
},
|
|
4036
|
+
{
|
|
4037
|
+
selector: [
|
|
4038
|
+
"accessor",
|
|
4039
|
+
"classMethod",
|
|
4040
|
+
"typeMethod",
|
|
4041
|
+
"typeProperty"
|
|
4042
|
+
],
|
|
4043
|
+
format: [
|
|
4044
|
+
"camelCase",
|
|
4045
|
+
"PascalCase",
|
|
4046
|
+
"UPPER_CASE"
|
|
4047
|
+
],
|
|
4048
|
+
leadingUnderscore: "allow",
|
|
4049
|
+
trailingUnderscore: "forbid"
|
|
4050
|
+
},
|
|
4051
|
+
{
|
|
4052
|
+
selector: "enumMember",
|
|
4053
|
+
format: ["PascalCase", "UPPER_CASE"],
|
|
4054
|
+
leadingUnderscore: "allow",
|
|
4055
|
+
trailingUnderscore: "forbid"
|
|
4056
|
+
},
|
|
4057
|
+
{
|
|
4058
|
+
selector: "typeLike",
|
|
4059
|
+
format: ["PascalCase"],
|
|
4060
|
+
leadingUnderscore: "allow",
|
|
4061
|
+
trailingUnderscore: "forbid"
|
|
4062
|
+
},
|
|
4063
|
+
{
|
|
4064
|
+
selector: ["objectLiteralProperty", "objectLiteralMethod"],
|
|
4065
|
+
format: null
|
|
4066
|
+
}
|
|
4067
|
+
] },
|
|
4139
4068
|
...overrides
|
|
4140
4069
|
}
|
|
4141
4070
|
},
|
|
4142
4071
|
...erasableSyntaxPlugin ? [{
|
|
4143
4072
|
name: "moso/typescript/erasable-syntax",
|
|
4073
|
+
files: [GLOB_SCRIPT],
|
|
4074
|
+
ignores: [GLOB_DTS],
|
|
4144
4075
|
plugins: { "erasable-syntax-only": memoize(erasableSyntaxPlugin, "eslint-plugin-erasable-syntax-only") },
|
|
4145
4076
|
rules: { ...(assert.ok(!Array.isArray(erasableSyntaxPlugin.configs?.recommended)), erasableSyntaxPlugin.configs?.recommended.rules) }
|
|
4146
4077
|
}] : [],
|
|
4147
4078
|
...isTypeAware ? [{
|
|
4148
4079
|
name: "moso/typescript/rules-type-aware",
|
|
4149
4080
|
files: filesTypeAware,
|
|
4081
|
+
ignores: ignoresTypeAware,
|
|
4150
4082
|
languageOptions: {
|
|
4151
4083
|
parser: tsEslintParser,
|
|
4152
4084
|
parserOptions: {
|
|
@@ -4157,7 +4089,6 @@ const typescript = async (options) => {
|
|
|
4157
4089
|
projectService: true,
|
|
4158
4090
|
sourceType: "module",
|
|
4159
4091
|
tsconfigRootDir: projectRoot,
|
|
4160
|
-
warnOnUnsupportedTypeScriptVersion: true,
|
|
4161
4092
|
...parserOptions
|
|
4162
4093
|
}
|
|
4163
4094
|
},
|
|
@@ -4189,7 +4120,6 @@ const typescript = async (options) => {
|
|
|
4189
4120
|
"@typescript-eslint/no-unsafe-unary-minus": unsafe
|
|
4190
4121
|
} : {
|
|
4191
4122
|
...(assert.ok(!Array.isArray(tsEslintPlugin.configs?.["strict-type-checked-only"])), tsEslintPlugin.configs?.["strict-type-checked-only"]?.rules),
|
|
4192
|
-
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
|
|
4193
4123
|
"@typescript-eslint/no-confusing-void-expression": ["error", {
|
|
4194
4124
|
ignoreArrowShorthand: false,
|
|
4195
4125
|
ignoreVoidOperator: true,
|
|
@@ -4253,14 +4183,9 @@ const typescript = async (options) => {
|
|
|
4253
4183
|
...overridesTypeAware
|
|
4254
4184
|
}
|
|
4255
4185
|
}] : [],
|
|
4256
|
-
...disableTypeAwareRules ? [{
|
|
4257
|
-
name: "moso/typescript/rules-disable-type-aware",
|
|
4258
|
-
files,
|
|
4259
|
-
ignores: filesTypeAware,
|
|
4260
|
-
rules: { ...(assert.ok(!Array.isArray(tsEslintPlugin.configs?.["disable-type-checked"])), tsEslintPlugin.configs?.["disable-type-checked"]?.rules) }
|
|
4261
|
-
}] : [],
|
|
4262
4186
|
...mode === "application" ? [{
|
|
4263
4187
|
name: "moso/typescript/application-mode",
|
|
4188
|
+
files,
|
|
4264
4189
|
rules: { "@typescript-eslint/no-empty-object-type": ["error", { allowInterfaces: "with-single-extends" }] }
|
|
4265
4190
|
}] : [],
|
|
4266
4191
|
...hasSvelte && functionalEnforcement !== "none" && mode !== "library" ? [{
|
|
@@ -4268,27 +4193,6 @@ const typescript = async (options) => {
|
|
|
4268
4193
|
files: [GLOB_SVELTE_MODULE],
|
|
4269
4194
|
rules: { ...namingConventionRules }
|
|
4270
4195
|
}] : [],
|
|
4271
|
-
{
|
|
4272
|
-
name: "moso/typescript/dts-overrides",
|
|
4273
|
-
files: [GLOB_DTS],
|
|
4274
|
-
rules: {
|
|
4275
|
-
"@eslint-community/eslint-comments/no-unlimited-disable": "off",
|
|
4276
|
-
"@stylistic/quote-props": "off",
|
|
4277
|
-
"no-duplicate-imports": "off",
|
|
4278
|
-
"no-restricted-syntax": "off",
|
|
4279
|
-
"unused-imports/no-unused-vars": "off"
|
|
4280
|
-
}
|
|
4281
|
-
},
|
|
4282
|
-
{
|
|
4283
|
-
name: "moso/typescript/test-overrides",
|
|
4284
|
-
files: [GLOB_TESTS],
|
|
4285
|
-
rules: {
|
|
4286
|
-
"@typescript-eslint/consistent-type-definitions": "off",
|
|
4287
|
-
"@typescript-eslint/no-unused-expressions": "off",
|
|
4288
|
-
"@typescript-eslint/triple-slash-reference": "off",
|
|
4289
|
-
"no-unused-expressions": "off"
|
|
4290
|
-
}
|
|
4291
|
-
},
|
|
4292
4196
|
{
|
|
4293
4197
|
name: "moso/typescript/javascript-overrides",
|
|
4294
4198
|
files: [GLOB_JS, GLOB_JSX],
|
|
@@ -4337,19 +4241,21 @@ const unicorn = async (options) => {
|
|
|
4337
4241
|
files,
|
|
4338
4242
|
rules: {
|
|
4339
4243
|
...(assert.ok(!Array.isArray(unicornPlugin.configs.unopinionated)), unicornPlugin.configs.unopinionated.rules),
|
|
4244
|
+
"@moso/no-unneeded-array-flat-map": "off",
|
|
4340
4245
|
...!lessOpinionated && {
|
|
4341
4246
|
...(assert.ok(!Array.isArray(unicornPlugin.configs.recommended)), unicornPlugin.configs.recommended.rules),
|
|
4342
4247
|
"unicorn/custom-error-definition": "error",
|
|
4343
4248
|
"unicorn/iteration-fallback-style": ["error", "fallback"],
|
|
4344
4249
|
"unicorn/no-instanceof-builtins": ["error", {
|
|
4345
|
-
|
|
4346
|
-
|
|
4250
|
+
exclude: ["Error"],
|
|
4251
|
+
strategy: "strict"
|
|
4347
4252
|
}],
|
|
4348
4253
|
"unicorn/no-unsafe-dom-html": "error",
|
|
4349
|
-
"unicorn/prefer-at":
|
|
4254
|
+
"unicorn/prefer-at": "error",
|
|
4350
4255
|
"unicorn/prefer-short-arrow-method": "error",
|
|
4351
4256
|
"unicorn/try-complexity": ["error", { max: 3 }],
|
|
4352
4257
|
"unicorn/consistent-boolean-name": "off",
|
|
4258
|
+
"unicorn/consistent-class-member-order": "off",
|
|
4353
4259
|
"unicorn/consistent-compound-words": "off",
|
|
4354
4260
|
"unicorn/consistent-conditional-object-spread": "off",
|
|
4355
4261
|
"unicorn/consistent-export-decorator-position": "off",
|
|
@@ -4371,7 +4277,6 @@ const unicorn = async (options) => {
|
|
|
4371
4277
|
"unicorn/no-array-sort": "off",
|
|
4372
4278
|
"unicorn/no-array-sort-for-min-max": "off",
|
|
4373
4279
|
"unicorn/no-array-splice": "off",
|
|
4374
|
-
"unicorn/no-async-promise-finally": "off",
|
|
4375
4280
|
"unicorn/no-break-in-nested-loop": "off",
|
|
4376
4281
|
"unicorn/no-chained-comparison": "off",
|
|
4377
4282
|
"unicorn/no-empty-file": "off",
|
|
@@ -4400,7 +4305,6 @@ const unicorn = async (options) => {
|
|
|
4400
4305
|
"unicorn/operator-assignment": "off",
|
|
4401
4306
|
"unicorn/prefer-array-from-async": "off",
|
|
4402
4307
|
"unicorn/prefer-array-slice": "off",
|
|
4403
|
-
"unicorn/prefer-dispose": "off",
|
|
4404
4308
|
"unicorn/prefer-dom-node-remove": "off",
|
|
4405
4309
|
"unicorn/prefer-early-return": "off",
|
|
4406
4310
|
"unicorn/prefer-flat-math-min-max": "off",
|
|
@@ -4440,7 +4344,7 @@ const unicorn = async (options) => {
|
|
|
4440
4344
|
// src/configs/vue.ts
|
|
4441
4345
|
const NuxtPackages = ["nuxt"];
|
|
4442
4346
|
const vue = async (options) => {
|
|
4443
|
-
const { a11y, files, overrides, overridesA11y, parserOptions, stylistic, typescript } = options;
|
|
4347
|
+
const { a11y, files, lessOpinionated, overrides, overridesA11y, parserOptions, stylistic, typescript } = options;
|
|
4444
4348
|
const { braceStyle = "1tbs", indent = 4 } = typeof stylistic === "boolean" ? {} : stylistic;
|
|
4445
4349
|
const [vuePlugin, vueParser, processorVueBlocks, { mergeProcessors }] = await loadPackages([
|
|
4446
4350
|
"eslint-plugin-vue",
|
|
@@ -4541,16 +4445,12 @@ const vue = async (options) => {
|
|
|
4541
4445
|
ignoreConstructors: false
|
|
4542
4446
|
}
|
|
4543
4447
|
],
|
|
4448
|
+
"vue/one-component-per-file": "off",
|
|
4544
4449
|
"vue/prefer-separate-static-class": "error",
|
|
4545
4450
|
"vue/prefer-template": "error",
|
|
4546
4451
|
"vue/prop-name-casing": ["error", "camelCase"],
|
|
4547
|
-
"vue/
|
|
4548
|
-
"vue/space-unary-ops": ["error", {
|
|
4549
|
-
nonwords: false,
|
|
4550
|
-
words: true
|
|
4551
|
-
}],
|
|
4452
|
+
"vue/require-default-prop": "off",
|
|
4552
4453
|
...stylisticEnabled && {
|
|
4553
|
-
"vue/array-bracket-spacing": ["error", "never"],
|
|
4554
4454
|
"vue/arrow-spacing": ["error", {
|
|
4555
4455
|
after: true,
|
|
4556
4456
|
before: true
|
|
@@ -4605,13 +4505,9 @@ const vue = async (options) => {
|
|
|
4605
4505
|
],
|
|
4606
4506
|
ignoreWhenEmpty: true
|
|
4607
4507
|
}],
|
|
4608
|
-
"vue/object-curly-spacing": ["error", "always"],
|
|
4609
|
-
"vue/object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }],
|
|
4610
|
-
"vue/one-component-per-file": "off",
|
|
4611
4508
|
"vue/operator-linebreak": ["error", "before"],
|
|
4612
4509
|
"vue/padding-line-between-blocks": ["error", "always"],
|
|
4613
4510
|
"vue/quote-props": ["error", "consistent-as-needed"],
|
|
4614
|
-
"vue/require-default-prop": "off",
|
|
4615
4511
|
"vue/singleline-html-element-content-newline": ["error", {
|
|
4616
4512
|
externalIgnores: [],
|
|
4617
4513
|
ignores: [
|
|
@@ -4629,8 +4525,14 @@ const vue = async (options) => {
|
|
|
4629
4525
|
ignoreWhenNoAttributes: true
|
|
4630
4526
|
}],
|
|
4631
4527
|
"vue/space-in-parens": ["error", "never"],
|
|
4528
|
+
"vue/space-infix-ops": "error",
|
|
4529
|
+
"vue/space-unary-ops": ["error", {
|
|
4530
|
+
nonwords: false,
|
|
4531
|
+
words: true
|
|
4532
|
+
}],
|
|
4632
4533
|
"vue/template-curly-spacing": "error"
|
|
4633
4534
|
},
|
|
4535
|
+
...!lessOpinionated && { "vue/no-deprecated-html-elements": "error" },
|
|
4634
4536
|
...vueA11yPlugin && {
|
|
4635
4537
|
...flattenRules(vueA11yPlugin.configs["flat/recommended"]),
|
|
4636
4538
|
...overridesA11y
|
|
@@ -4737,13 +4639,15 @@ const VuePackages = [
|
|
|
4737
4639
|
/**
|
|
4738
4640
|
* Construct an array of ESLint flat config items.
|
|
4739
4641
|
*
|
|
4740
|
-
* @param
|
|
4741
|
-
* @param
|
|
4742
|
-
* @returns
|
|
4642
|
+
* @param options - Options for generating the ESLint configurations.
|
|
4643
|
+
* @param userConfigs - User configurations to be merged with the generated configurations.
|
|
4644
|
+
* @returns The merged ESLint configurations.
|
|
4743
4645
|
*/
|
|
4744
4646
|
async function moso(options = {}, ...userConfigs) {
|
|
4745
4647
|
const { componentExts: componentExtsOption = [], isInEditor = isInEditorEnv(), jsdoc: jsdocOptions = false, jsonc: jsoncOptions = false, jsx: jsxOptions = true } = options;
|
|
4746
4648
|
if ("files" in options) throw new Error("[@moso/eslint-config] The first argument should not contain the \"files\" property as the options are supposed to be global. Place it in the second or later config instead.");
|
|
4649
|
+
if ("projectRoot" in options) throw new Error("[@moso/eslint-config] The top-level `projectRoot` option was removed. Move it inside the `typescript` options instead: `typescript: { projectRoot: import.meta.dirname }`.");
|
|
4650
|
+
if (Array.isArray(options.ignores)) throw new TypeError("[@moso/eslint-config] The `ignores` option takes an object: `ignores: { userIgnores: ['**/dist'] }`.");
|
|
4747
4651
|
const mut_packageExistsCache = /* @__PURE__ */ new Map();
|
|
4748
4652
|
const packageExists = (name) => {
|
|
4749
4653
|
const cached = mut_packageExistsCache.get(name);
|
|
@@ -4775,19 +4679,16 @@ async function moso(options = {}, ...userConfigs) {
|
|
|
4775
4679
|
const functionalEnforcement = typeof options.functional === "string" ? options.functional : typeof options.functional === "object" ? options.functional.functionalEnforcement ?? "lite" : options.functional ? "recommended" : options.functional === false || options.lessOpinionated === true ? "none" : "lite";
|
|
4776
4680
|
const hasTypeScript = Boolean(typescriptOptions);
|
|
4777
4681
|
const hasDOM = options.mode !== "library" || Boolean(astroOptions) || Boolean(nextjsOptions) || Boolean(preactOptions) || Boolean(reactOptions) || Boolean(svelteOptions) || Boolean(vueOptions);
|
|
4778
|
-
const
|
|
4779
|
-
const
|
|
4780
|
-
const perfectionistOptions = typeof options.perfectionist === "boolean" ? options.perfectionist : options.lessOpinionated !== true;
|
|
4682
|
+
const modeOptions = options.mode ?? "none";
|
|
4683
|
+
const perfectionistOptions = options.perfectionist === void 0 ? options.lessOpinionated !== true : options.perfectionist !== false;
|
|
4781
4684
|
const securityOptions = typeof options.security === "string" ? options.security : typeof options.security === "object" ? options.security.severity ?? "moderate" : options.security === false ? "none" : "moderate";
|
|
4782
4685
|
const stylisticOptions = options.stylistic !== false && {
|
|
4783
4686
|
...StylisticConfigDefaults,
|
|
4784
4687
|
jsx: jsxOptions !== false,
|
|
4785
4688
|
...typeof options.stylistic === "object" && options.stylistic
|
|
4786
4689
|
};
|
|
4787
|
-
const { filesTypeAware, ignoresTypeAware, parserOptions, projectRoot: typescriptProjectRoot, unsafe: typescriptUnsafe = "warn", useDefaultDefaultProject, ...typescriptSubOptions } = resolveSubOptions(options, "typescript");
|
|
4788
|
-
const
|
|
4789
|
-
if (deprecatedProjectRoot !== void 0) console.warn("[@moso/eslint-config] The top-level `projectRoot` option is deprecated. Move it inside the `typescript` options instead: `typescript: { projectRoot: import.meta.dirname }`.");
|
|
4790
|
-
const projectRootOptions = typeof typescriptProjectRoot === "string" ? checkFilePath(typescriptProjectRoot) : typeof deprecatedProjectRoot === "string" ? checkFilePath(deprecatedProjectRoot) : void 0;
|
|
4690
|
+
const { disableTypeAwareRules, filesTypeAware, ignoresTypeAware, parserOptions, projectRoot: typescriptProjectRoot, unsafe: typescriptUnsafe = "warn", useDefaultDefaultProject, ...typescriptSubOptions } = resolveSubOptions(options, "typescript");
|
|
4691
|
+
const projectRootOptions = typeof typescriptProjectRoot === "string" ? checkFilePath(typescriptProjectRoot) : void 0;
|
|
4791
4692
|
const projectServiceUserConfig = {
|
|
4792
4693
|
defaultProject: "./tsconfig.json",
|
|
4793
4694
|
loadTypeScriptPlugins: isInEditor,
|
|
@@ -4801,11 +4702,11 @@ async function moso(options = {}, ...userConfigs) {
|
|
|
4801
4702
|
const typescriptConfigOptions = {
|
|
4802
4703
|
...typescriptSubOptions,
|
|
4803
4704
|
filesTypeAware: filesTypeAware ?? defaultFilesTypesAware,
|
|
4804
|
-
ignoresTypeAware: ignoresTypeAware ?? [],
|
|
4705
|
+
ignoresTypeAware: ignoresTypeAware ?? ["**/*.astro/*.ts", `**/*.md/**`],
|
|
4805
4706
|
parserOptions: {
|
|
4806
4707
|
tsconfigRootDir: projectRootOptions,
|
|
4807
4708
|
...parserOptions,
|
|
4808
|
-
projectService: projectRootOptions !== void 0 && parserOptions?.projectService !== false && (useDefaultDefaultProject === false ? projectServiceUserConfig : {
|
|
4709
|
+
projectService: projectRootOptions !== void 0 && parserOptions?.projectService !== false && disableTypeAwareRules !== true && (useDefaultDefaultProject === false ? projectServiceUserConfig : {
|
|
4809
4710
|
allowDefaultProject: ["?(.)*.?([cm])js", "?(.)*.?([cm])jsx"],
|
|
4810
4711
|
...projectServiceUserConfig
|
|
4811
4712
|
})
|
|
@@ -4818,10 +4719,7 @@ async function moso(options = {}, ...userConfigs) {
|
|
|
4818
4719
|
};
|
|
4819
4720
|
const mut_configs = [];
|
|
4820
4721
|
if (options.comments !== false) mut_configs.push(comments({ overrides: getOverrides(options, "comments") }));
|
|
4821
|
-
if (options.ignores !== false) mut_configs.push(ignores(
|
|
4822
|
-
...ignoreOptions,
|
|
4823
|
-
...resolveSubOptions(options, "ignores")
|
|
4824
|
-
}));
|
|
4722
|
+
if (options.ignores !== false) mut_configs.push(ignores(resolveSubOptions(options, "ignores")));
|
|
4825
4723
|
if (options.imports !== false) mut_configs.push(imports({
|
|
4826
4724
|
...typescriptConfigOptions,
|
|
4827
4725
|
files: [
|
|
@@ -4925,6 +4823,7 @@ async function moso(options = {}, ...userConfigs) {
|
|
|
4925
4823
|
overrides: getOverrides(options, "jsonc"),
|
|
4926
4824
|
stylistic: stylisticOptions
|
|
4927
4825
|
}), sortPackageJson(), sortTsconfig());
|
|
4826
|
+
const jsxOverridesA11y = resolveSubOptions(options, "jsx").overridesA11y;
|
|
4928
4827
|
if (jsxOptions !== false) mut_configs.push(jsx({
|
|
4929
4828
|
files: [GLOB_JSX, GLOB_TSX],
|
|
4930
4829
|
lessOpinionated: options.lessOpinionated,
|
|
@@ -4942,27 +4841,31 @@ async function moso(options = {}, ...userConfigs) {
|
|
|
4942
4841
|
if (preactOptions !== false) mut_configs.push(preact({
|
|
4943
4842
|
...typescriptConfigOptions,
|
|
4944
4843
|
files: [GLOB_SRC],
|
|
4945
|
-
filesTypeAware: defaultFilesTypesAware,
|
|
4946
|
-
ignoresTypeAware: [GLOB_ASTRO_TS, `${GLOB_MARKDOWN}/**`],
|
|
4947
4844
|
lessOpinionated: options.lessOpinionated,
|
|
4948
4845
|
projectRoot: projectRootOptions,
|
|
4949
4846
|
overrides: getOverrides(options, "preact"),
|
|
4950
4847
|
stylistic: stylisticOptions,
|
|
4951
4848
|
typescript: hasTypeScript,
|
|
4952
|
-
...resolveSubOptions(options, "preact")
|
|
4849
|
+
...resolveSubOptions(options, "preact"),
|
|
4850
|
+
overridesA11y: {
|
|
4851
|
+
...jsxOverridesA11y,
|
|
4852
|
+
...resolveSubOptions(options, "preact").overridesA11y
|
|
4853
|
+
}
|
|
4953
4854
|
}));
|
|
4954
4855
|
if (reactOptions !== false) mut_configs.push(react({
|
|
4955
4856
|
...typescriptConfigOptions,
|
|
4956
4857
|
files: [GLOB_SRC],
|
|
4957
|
-
filesTypeAware: defaultFilesTypesAware,
|
|
4958
|
-
ignoresTypeAware: [GLOB_ASTRO_TS, `${GLOB_MARKDOWN}/**`],
|
|
4959
4858
|
lessOpinionated: options.lessOpinionated,
|
|
4960
4859
|
nextjs: Boolean(nextjsOptions),
|
|
4961
4860
|
projectRoot: projectRootOptions,
|
|
4962
4861
|
overrides: getOverrides(options, "react"),
|
|
4963
4862
|
stylistic: stylisticOptions,
|
|
4964
4863
|
typescript: hasTypeScript,
|
|
4965
|
-
...resolveSubOptions(options, "react")
|
|
4864
|
+
...resolveSubOptions(options, "react"),
|
|
4865
|
+
overridesA11y: {
|
|
4866
|
+
...jsxOverridesA11y,
|
|
4867
|
+
...resolveSubOptions(options, "react").overridesA11y
|
|
4868
|
+
}
|
|
4966
4869
|
}));
|
|
4967
4870
|
if (options.test !== false) mut_configs.push(test({
|
|
4968
4871
|
...functionalConfigOptions,
|
|
@@ -5000,6 +4903,7 @@ async function moso(options = {}, ...userConfigs) {
|
|
|
5000
4903
|
if (vueOptions !== false) mut_configs.push(vue({
|
|
5001
4904
|
...typescriptConfigOptions,
|
|
5002
4905
|
files: [GLOB_VUE],
|
|
4906
|
+
lessOpinionated: options.lessOpinionated,
|
|
5003
4907
|
overrides: getOverrides(options, "vue"),
|
|
5004
4908
|
sfcBlocks: true,
|
|
5005
4909
|
stylistic: stylisticOptions,
|
|
@@ -5013,7 +4917,7 @@ async function moso(options = {}, ...userConfigs) {
|
|
|
5013
4917
|
entryPoint: resolvedTailwind.entryPoint,
|
|
5014
4918
|
version: resolvedTailwind.version ?? 4
|
|
5015
4919
|
} : {
|
|
5016
|
-
config: resolvedTailwind.config
|
|
4920
|
+
config: resolvedTailwind.config,
|
|
5017
4921
|
entryPoint: void 0,
|
|
5018
4922
|
version: resolvedTailwind.version ?? 3
|
|
5019
4923
|
};
|
|
@@ -5107,4 +5011,4 @@ const off = {
|
|
|
5107
5011
|
vue: false,
|
|
5108
5012
|
yaml: false
|
|
5109
5013
|
};
|
|
5110
|
-
export { GLOB_AI, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CJS, GLOB_CSS_IN_JS, GLOB_DIST, GLOB_DTS, GLOB_EXCLUDE, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LOCKFILE, GLOB_MARKDOWN, GLOB_MJS, GLOB_NODE_MODULES, GLOB_ROOT_DTS, GLOB_ROOT_JS, GLOB_ROOT_JSX, GLOB_ROOT_TS, GLOB_ROOT_TSX, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVELTE, GLOB_SVELTE_MODULE, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_TYPINGS, GLOB_VUE, GLOB_YAML, StylisticConfigDefaults, astro, baseline, checkFilePath, combine, comments, moso as default, moso, disables, e18e, flattenRules, full, functional, getOverrides, globalIgnores, ignores, imports, interopDefault, isInEditorEnv, javascript, jsdoc, jsonc, jsx, memoize, nextjs, node, off, perfectionist, preact, promise, react, regexp, resolveSubOptions, security, sortPackageJson, sortTsconfig, stylistic, svelte, tailwind, test, toml, typescript, unicorn, vue, vueInlineElements, yaml };
|
|
5014
|
+
export { GLOB_AI, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CJS, GLOB_CSS_IN_JS, GLOB_DIST, GLOB_DTS, GLOB_EXCLUDE, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LOCKFILE, GLOB_MARKDOWN, GLOB_MJS, GLOB_NODE_MODULES, GLOB_ROOT_DTS, GLOB_ROOT_JS, GLOB_ROOT_JSX, GLOB_ROOT_TS, GLOB_ROOT_TSX, GLOB_SCRIPT, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVELTE, GLOB_SVELTE_MODULE, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_TYPINGS, GLOB_VUE, GLOB_YAML, StylisticConfigDefaults, astro, baseline, checkFilePath, combine, comments, moso as default, moso, disables, e18e, flattenRules, full, functional, getOverrides, globalIgnores, ignores, imports, interopDefault, isInEditorEnv, javascript, jsdoc, jsonc, jsx, memoize, nextjs, node, off, perfectionist, preact, promise, react, regexp, resolveSubOptions, security, sortPackageJson, sortTsconfig, stylistic, svelte, tailwind, test, toml, typescript, unicorn, vue, vueInlineElements, yaml };
|