@moso/eslint-config 3.1.0 → 3.3.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 +17 -16
- package/dist/index.d.mts +505 -462
- package/dist/index.mjs +324 -273
- package/package.json +35 -35
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
2
|
import { getPackageInfo, isPackageExists } from "local-pkg";
|
|
3
3
|
import assert from "node:assert/strict";
|
|
4
|
-
import globals from "globals";
|
|
5
4
|
import { AST_NODE_TYPES, AST_TOKEN_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
6
5
|
import { isIdentifier } from "@typescript-eslint/utils/ast-utils";
|
|
7
|
-
import
|
|
6
|
+
import globals from "globals";
|
|
8
7
|
import { FlatConfigComposer } from "eslint-flat-config-utils";
|
|
8
|
+
//#region package.json
|
|
9
|
+
var peerDependenciesMeta = {
|
|
10
|
+
"@eslint-react/eslint-plugin": { "optional": true },
|
|
11
|
+
"@next/eslint-plugin-next": { "optional": true },
|
|
12
|
+
"astro-eslint-parser": { "optional": true },
|
|
13
|
+
"eslint-plugin-astro": { "optional": true },
|
|
14
|
+
"eslint-plugin-better-tailwindcss": { "optional": true },
|
|
15
|
+
"eslint-plugin-erasable-syntax-only": { "optional": true },
|
|
16
|
+
"eslint-plugin-jsx-a11y": { "optional": true },
|
|
17
|
+
"eslint-plugin-react-hooks": { "optional": true },
|
|
18
|
+
"eslint-plugin-react-refresh": { "optional": true },
|
|
19
|
+
"eslint-plugin-react-you-might-not-need-an-effect": { "optional": true },
|
|
20
|
+
"eslint-plugin-vue": { "optional": true },
|
|
21
|
+
"eslint-plugin-vuejs-accessibility": { "optional": true },
|
|
22
|
+
"typescript": { "optional": true }
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
9
25
|
//#region src/utils.ts
|
|
10
26
|
/**
|
|
11
27
|
* Resolve and flatten any mix of (awaitable) config items or arrays
|
|
@@ -194,6 +210,10 @@ const vueInlineElements = [
|
|
|
194
210
|
//#region src/tools.ts
|
|
195
211
|
const scopeURL = import.meta.dirname;
|
|
196
212
|
/**
|
|
213
|
+
* The optional peer dependencies in a self-maintained list.
|
|
214
|
+
*/
|
|
215
|
+
const optionalPeers = new Set(Object.keys(peerDependenciesMeta));
|
|
216
|
+
/**
|
|
197
217
|
* Whether `name` resolves from this package's own directory (not the user's cwd).
|
|
198
218
|
*/
|
|
199
219
|
const isPackageInScope = (name) => isPackageExists(name, { paths: [scopeURL] });
|
|
@@ -206,16 +226,15 @@ const isInteractive = () => {
|
|
|
206
226
|
};
|
|
207
227
|
/**
|
|
208
228
|
* Offer to install missing packages through an interactive prompt.
|
|
209
|
-
* Only called from `loadPackages` after it has verified the session is interactive
|
|
229
|
+
* Only called from `loadPackages` after it has verified the session is interactive,
|
|
230
|
+
* and the packages are genuinely missing.
|
|
210
231
|
*
|
|
211
|
-
* @param
|
|
232
|
+
* @param missingPackages - Package names to offer for installation.
|
|
212
233
|
*/
|
|
213
|
-
const ensurePackages = async (
|
|
214
|
-
const missingPackages = packages.filter((x) => !isPackageInScope(x));
|
|
215
|
-
if (missingPackages.length === 0) return;
|
|
234
|
+
const ensurePackages = async (missingPackages) => {
|
|
216
235
|
if (await (await import("@clack/prompts")).confirm({ message: missingPackages.length === 1 ? `${missingPackages[0]} is required. Do you want to install it?` : `These packages are required: ${missingPackages.join(", ")}.\nDo you want to install them?` }) === true) {
|
|
217
236
|
const { installPackage } = await import("@antfu/install-pkg");
|
|
218
|
-
await installPackage(missingPackages, { dev: true });
|
|
237
|
+
await installPackage([...missingPackages], { dev: true });
|
|
219
238
|
}
|
|
220
239
|
};
|
|
221
240
|
/**
|
|
@@ -231,7 +250,7 @@ const ensurePackages = async (packages) => {
|
|
|
231
250
|
*/
|
|
232
251
|
const loadPackages = async (packageIds) => {
|
|
233
252
|
if (isInteractive()) {
|
|
234
|
-
const missing = packageIds.filter((id) => !
|
|
253
|
+
const missing = packageIds.filter((id) => optionalPeers.has(id) && !isPackageInScope(id));
|
|
235
254
|
if (missing.length > 0) await ensurePackages(missing);
|
|
236
255
|
}
|
|
237
256
|
return Promise.all(packageIds.map(async (id) => interopDefault(import(id))));
|
|
@@ -303,27 +322,39 @@ const astro = async (options) => {
|
|
|
303
322
|
//#region src/configs/baseline.ts
|
|
304
323
|
const defaultIgnoreFeatures = ["functions-caller-arguments"];
|
|
305
324
|
const baseline = async (options) => {
|
|
306
|
-
const { baseline, files, filesTypeAware, ignoreFeatures, ignoreNodeTypes, ignoresTypeAware, overrides, overridesTypeAware, projectRoot, typescript } = options;
|
|
307
|
-
const isTypeAware = typescript && typeof projectRoot === "string";
|
|
325
|
+
const { baseline, files, filesTypeAware, hasDOM, ignoreFeatures, ignoreNodeTypes, ignoresTypeAware, overrides, overridesTypeAware, parserOptions, projectRoot, typescript } = options;
|
|
326
|
+
const isTypeAware = typescript && typeof projectRoot === "string" && parserOptions?.projectService !== false;
|
|
308
327
|
const [baselinePlugin] = await loadPackages(["eslint-plugin-baseline-js"]);
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
328
|
+
const baselineRule = (typeAware) => ({ "baseline-js/use-baseline": ["warn", {
|
|
329
|
+
available: baseline ?? "widely",
|
|
330
|
+
ignoreFeatures: [...defaultIgnoreFeatures, ...ignoreFeatures ?? []],
|
|
331
|
+
ignoreNodeTypes,
|
|
332
|
+
includeJsBuiltins: { preset: typeAware ? "type-aware" : "auto" },
|
|
333
|
+
includeWebApis: hasDOM === false ? false : { preset: typeAware ? "type-aware" : "auto" }
|
|
334
|
+
}] });
|
|
335
|
+
return [
|
|
336
|
+
{
|
|
337
|
+
name: "moso/baseline/setup",
|
|
338
|
+
plugins: { "baseline-js": memoize(baselinePlugin, "eslint-plugin-baseline-js") }
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
name: "moso/baseline/rules",
|
|
342
|
+
files: isTypeAware ? files : [...files, ...filesTypeAware ?? []],
|
|
343
|
+
rules: {
|
|
344
|
+
...baselineRule(false),
|
|
345
|
+
...overrides
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
...isTypeAware ? [{
|
|
349
|
+
name: "moso/baseline/type-aware-rules",
|
|
350
|
+
files: filesTypeAware,
|
|
351
|
+
ignores: ignoresTypeAware ?? [],
|
|
352
|
+
rules: {
|
|
353
|
+
...baselineRule(true),
|
|
354
|
+
...overridesTypeAware
|
|
355
|
+
}
|
|
356
|
+
}] : []
|
|
357
|
+
];
|
|
327
358
|
};
|
|
328
359
|
//#endregion
|
|
329
360
|
//#region src/globs.ts
|
|
@@ -334,37 +365,25 @@ const GLOB_JSX = "**/*.?([cm])jsx";
|
|
|
334
365
|
const GLOB_TS = "**/*.?([cm])ts";
|
|
335
366
|
const GLOB_TSX = "**/*.?([cm])tsx";
|
|
336
367
|
const GLOB_DTS = "**/?(.)*.d.?([cm])ts";
|
|
337
|
-
const GLOB_ROOT_JS = "
|
|
338
|
-
const GLOB_ROOT_JSX = "
|
|
339
|
-
const GLOB_ROOT_TS = "
|
|
340
|
-
const GLOB_ROOT_TSX = "
|
|
341
|
-
const GLOB_ROOT_DTS = "
|
|
368
|
+
const GLOB_ROOT_JS = "?(.)*.?([cm])js";
|
|
369
|
+
const GLOB_ROOT_JSX = "?(.)*.?([cm])jsx";
|
|
370
|
+
const GLOB_ROOT_TS = "?(.)*.?([cm])ts";
|
|
371
|
+
const GLOB_ROOT_TSX = "?(.)*.?([cm])tsx";
|
|
372
|
+
const GLOB_ROOT_DTS = "?(.)*.d.?([cm])ts";
|
|
342
373
|
const GLOB_MJS = "**/*.mjs";
|
|
343
|
-
const GLOB_MTS = "**/*.mts";
|
|
344
374
|
const GLOB_CJS = "**/*.cjs";
|
|
345
|
-
const
|
|
346
|
-
const GLOB_STYLE = "**/?(.)*.{c,le,sc,pc,postc}ss";
|
|
347
|
-
const GLOB_CSS = "**/?(.)*.css";
|
|
348
|
-
const GLOB_POSTCSS = "**/?(.)*.{p,post}css";
|
|
349
|
-
const GLOB_LESS = "**/?(.)*.less";
|
|
350
|
-
const GLOB_SCSS = "**/?(.)*.scss";
|
|
375
|
+
const GLOB_TYPINGS = "typings/**/?(.)*.?([cm])ts";
|
|
376
|
+
const GLOB_STYLE = "**/?(.)*.{c,le,sa,sc,pc,postc}ss";
|
|
351
377
|
const GLOB_CSS_IN_JS = "**/*.css.{j,t}s";
|
|
352
378
|
const GLOB_JSON = "**/*.json";
|
|
353
379
|
const GLOB_JSON5 = "**/*.json5";
|
|
354
380
|
const GLOB_JSONC = "**/*.jsonc";
|
|
355
381
|
const GLOB_ASTRO = "**/*.astro";
|
|
356
382
|
const GLOB_ASTRO_TS = "**/*.astro/*.ts";
|
|
357
|
-
const GLOB_HTML = "**/*.htm?(l)";
|
|
358
383
|
const GLOB_MARKDOWN = "**/*.md";
|
|
359
|
-
const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
|
|
360
|
-
const GLOB_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md";
|
|
361
|
-
const GLOB_SVELTE = "**/*.svelte?(.{js,ts})";
|
|
362
|
-
const GLOB_SVG = "**/*.svg";
|
|
363
384
|
const GLOB_TOML = "**/*.toml";
|
|
364
385
|
const GLOB_VUE = "**/*.vue";
|
|
365
|
-
const GLOB_XML = "**/*.xml";
|
|
366
386
|
const GLOB_YAML = "**/*.y?(a)ml";
|
|
367
|
-
const GLOB_TYPINGS = "typings/**/?(.)*.?([cm])ts";
|
|
368
387
|
const GLOB_TESTS = [
|
|
369
388
|
`**/__tests__/**/?(.)*.${GLOB_SRC_EXT}`,
|
|
370
389
|
`**/?(.)*.spec.${GLOB_SRC_EXT}`,
|
|
@@ -372,18 +391,6 @@ const GLOB_TESTS = [
|
|
|
372
391
|
`**/?(.)*.bench.${GLOB_SRC_EXT}`,
|
|
373
392
|
`**/?(.)*.benchmark.${GLOB_SRC_EXT}`
|
|
374
393
|
];
|
|
375
|
-
const GLOB_ALL_SRC = [
|
|
376
|
-
GLOB_SRC,
|
|
377
|
-
GLOB_STYLE,
|
|
378
|
-
GLOB_JSON,
|
|
379
|
-
GLOB_JSON5,
|
|
380
|
-
GLOB_HTML,
|
|
381
|
-
GLOB_MARKDOWN,
|
|
382
|
-
GLOB_SVELTE,
|
|
383
|
-
GLOB_VUE,
|
|
384
|
-
GLOB_YAML,
|
|
385
|
-
GLOB_XML
|
|
386
|
-
];
|
|
387
394
|
const GLOB_NODE_MODULES = "**/node_modules";
|
|
388
395
|
const GLOB_DIST = "**/dist";
|
|
389
396
|
const GLOB_LOCKFILE = [
|
|
@@ -435,8 +442,8 @@ const GLOB_EXCLUDE = [
|
|
|
435
442
|
];
|
|
436
443
|
//#endregion
|
|
437
444
|
//#region src/configs/disables.ts
|
|
438
|
-
const disables = async () => {
|
|
439
|
-
const [functionalPlugin] = await loadPackages(["eslint-plugin-functional"]);
|
|
445
|
+
const disables = async (functionalEnabled = false) => {
|
|
446
|
+
const [functionalPlugin] = functionalEnabled ? await loadPackages(["eslint-plugin-functional"]) : [void 0];
|
|
440
447
|
return [
|
|
441
448
|
{
|
|
442
449
|
name: "moso/disables/allow-default-export",
|
|
@@ -498,7 +505,7 @@ const disables = async () => {
|
|
|
498
505
|
},
|
|
499
506
|
{
|
|
500
507
|
name: "moso/disables/github",
|
|
501
|
-
files: ["**/
|
|
508
|
+
files: ["**/ISSUE_TEMPLATE/**"],
|
|
502
509
|
rules: { "unicorn/filename-case": "off" }
|
|
503
510
|
},
|
|
504
511
|
{
|
|
@@ -575,7 +582,7 @@ const disables = async () => {
|
|
|
575
582
|
name: "moso/disables/typings",
|
|
576
583
|
files: [GLOB_TYPINGS],
|
|
577
584
|
rules: {
|
|
578
|
-
...(assert.ok(!Array.isArray(functionalPlugin.configs.off)), functionalPlugin.configs.off.rules),
|
|
585
|
+
...functionalPlugin !== void 0 && (assert.ok(!Array.isArray(functionalPlugin.configs.off)), functionalPlugin.configs.off.rules),
|
|
579
586
|
"jsdoc/check-examples": "off",
|
|
580
587
|
"jsdoc/check-indentation": "off",
|
|
581
588
|
"jsdoc/check-line-alignment": "off",
|
|
@@ -621,7 +628,7 @@ const e18e = async (options) => {
|
|
|
621
628
|
const { isInEditor, lessOpinionated, mode, modernization, moduleReplacements, overrides, performanceImprovements } = options;
|
|
622
629
|
const [e18ePlugin] = await loadPackages(["@e18e/eslint-plugin"]);
|
|
623
630
|
const enableModernization = modernization !== false;
|
|
624
|
-
const enableModuleReplacements = moduleReplacements
|
|
631
|
+
const enableModuleReplacements = moduleReplacements ?? (mode === "library" && isInEditor === true);
|
|
625
632
|
const enablePerformanceImprovements = performanceImprovements !== false;
|
|
626
633
|
return [{
|
|
627
634
|
name: "moso/e18e/rules",
|
|
@@ -777,56 +784,14 @@ const ignores = async (options) => {
|
|
|
777
784
|
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];
|
|
778
785
|
if (ignoreTypeScript) mut_ignores.push(GLOB_TS, GLOB_TSX);
|
|
779
786
|
mut_configs.push(globalIgnores(mut_ignores, "moso/ignores/globals"));
|
|
780
|
-
if (
|
|
781
|
-
files: [".gitignore"],
|
|
782
|
-
name: "moso/ignores/gitignore",
|
|
783
|
-
strict: false
|
|
784
|
-
}));
|
|
785
|
-
else if (typeof gitignore === "string" || Array.isArray(gitignore)) mut_configs.push(eslintConfigFlatGitIgnore({
|
|
786
|
-
files: gitignore,
|
|
787
|
+
if (gitignore !== false) mut_configs.push(eslintConfigFlatGitIgnore({
|
|
787
788
|
name: "moso/ignores/gitignore",
|
|
788
|
-
strict: false
|
|
789
|
+
strict: false,
|
|
790
|
+
...typeof gitignore === "string" ? { files: [gitignore] } : typeof gitignore === "object" ? gitignore : { files: [".gitignore"] }
|
|
789
791
|
}));
|
|
790
792
|
return mut_configs;
|
|
791
793
|
};
|
|
792
794
|
//#endregion
|
|
793
|
-
//#region src/configs/imports.ts
|
|
794
|
-
const imports = async (options) => {
|
|
795
|
-
const { files, overrides, stylistic, typescript } = options;
|
|
796
|
-
const [importLite] = await loadPackages(["eslint-plugin-import-lite"]);
|
|
797
|
-
const stylisticEnabled = stylistic !== false;
|
|
798
|
-
return [{
|
|
799
|
-
name: "moso/imports",
|
|
800
|
-
plugins: { "import-lite": memoize(importLite, "eslint-plugin-import-lite") },
|
|
801
|
-
rules: {
|
|
802
|
-
"@moso/no-import-duplicates": "error",
|
|
803
|
-
"@moso/no-import-from-dist": "error",
|
|
804
|
-
"@moso/no-import-node-modules-by-path": "error",
|
|
805
|
-
"import-lite/consistent-type-specifier-style": "error",
|
|
806
|
-
"import-lite/first": "error",
|
|
807
|
-
"import-lite/no-duplicates": "error",
|
|
808
|
-
"import-lite/no-mutable-exports": "error",
|
|
809
|
-
"import-lite/no-named-default": "error",
|
|
810
|
-
...stylisticEnabled && { "import-lite/newline-after-import": ["error", { considerComments: false }] },
|
|
811
|
-
...overrides
|
|
812
|
-
}
|
|
813
|
-
}, ...typescript ? [{
|
|
814
|
-
name: "moso/imports/typescript",
|
|
815
|
-
files,
|
|
816
|
-
rules: {
|
|
817
|
-
"@typescript-eslint/no-import-type-side-effects": "error",
|
|
818
|
-
"@typescript-eslint/consistent-type-imports": [stylisticEnabled ? "error" : "off", {
|
|
819
|
-
disallowTypeAnnotations: false,
|
|
820
|
-
fixStyle: "inline-type-imports",
|
|
821
|
-
prefer: "type-imports"
|
|
822
|
-
}]
|
|
823
|
-
}
|
|
824
|
-
}] : []];
|
|
825
|
-
};
|
|
826
|
-
//#endregion
|
|
827
|
-
//#region package.json
|
|
828
|
-
var version = "3.1.0";
|
|
829
|
-
//#endregion
|
|
830
795
|
//#region src/rules/utils.ts
|
|
831
796
|
/**
|
|
832
797
|
* Typed rule factory for every rule in this plugin.
|
|
@@ -840,11 +805,10 @@ const createRule = ESLintUtils.RuleCreator((name) => name);
|
|
|
840
805
|
* (or the node itself) matching a node type.
|
|
841
806
|
* Basically the AST equivalent of `Element#closest`.
|
|
842
807
|
*/
|
|
843
|
-
const closest = (node,
|
|
844
|
-
const predicate = typeof test === "string" ? (node) => node.type === test : test;
|
|
808
|
+
const closest = (node, type) => {
|
|
845
809
|
const findClosest = (current) => {
|
|
846
810
|
if (!current) return void 0;
|
|
847
|
-
return
|
|
811
|
+
return current.type === type ? current : findClosest(current.parent);
|
|
848
812
|
};
|
|
849
813
|
return findClosest(node);
|
|
850
814
|
};
|
|
@@ -880,9 +844,13 @@ const getFixer = (token, pattern) => {
|
|
|
880
844
|
};
|
|
881
845
|
case AST_TOKEN_TYPES.RegularExpression: return (fixer) => {
|
|
882
846
|
const mut_flags = new Set(token.regex.flags);
|
|
883
|
-
mut_flags.add("u");
|
|
884
|
-
|
|
885
|
-
|
|
847
|
+
if (!mut_flags.has("v")) mut_flags.add("u");
|
|
848
|
+
try {
|
|
849
|
+
const re = new RegExp(escape(token.regex.pattern, pattern), [...mut_flags].join(""));
|
|
850
|
+
return fixer.replaceText(token, re.toString());
|
|
851
|
+
} catch {
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
886
854
|
};
|
|
887
855
|
case AST_TOKEN_TYPES.String:
|
|
888
856
|
case AST_TOKEN_TYPES.Template: return (fixer) => {
|
|
@@ -916,19 +884,10 @@ const getReturnExpression = (node) => {
|
|
|
916
884
|
*/
|
|
917
885
|
const getValue = (token) => {
|
|
918
886
|
switch (token.type) {
|
|
919
|
-
case AST_TOKEN_TYPES.Block:
|
|
920
|
-
case AST_TOKEN_TYPES.Boolean: return false;
|
|
921
887
|
case AST_TOKEN_TYPES.Identifier:
|
|
922
|
-
if (token.value.startsWith("#")) return token.value.slice(1);
|
|
923
|
-
return token.value;
|
|
924
888
|
case AST_TOKEN_TYPES.JSXIdentifier:
|
|
925
|
-
case AST_TOKEN_TYPES.JSXText:
|
|
926
|
-
case AST_TOKEN_TYPES.Keyword:
|
|
927
|
-
case AST_TOKEN_TYPES.Line:
|
|
928
|
-
case AST_TOKEN_TYPES.Null:
|
|
929
|
-
case AST_TOKEN_TYPES.Numeric: return false;
|
|
889
|
+
case AST_TOKEN_TYPES.JSXText:
|
|
930
890
|
case AST_TOKEN_TYPES.PrivateIdentifier: return token.value;
|
|
931
|
-
case AST_TOKEN_TYPES.Punctuator: return false;
|
|
932
891
|
case AST_TOKEN_TYPES.RegularExpression: return token.regex.pattern;
|
|
933
892
|
case AST_TOKEN_TYPES.String:
|
|
934
893
|
case AST_TOKEN_TYPES.Template: return token.value.slice(1, -1);
|
|
@@ -974,10 +933,9 @@ const isIdentifierFunction = (node) => {
|
|
|
974
933
|
return 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);
|
|
975
934
|
};
|
|
976
935
|
const isLiteralValue = (node, value) => {
|
|
977
|
-
if (node
|
|
936
|
+
if (node?.type !== AST_NODE_TYPES.Literal) return false;
|
|
978
937
|
if (typeof value === "string") return node.value === value;
|
|
979
|
-
|
|
980
|
-
return value.includes(node.value);
|
|
938
|
+
return typeof node.value === "string" && value.test(node.value);
|
|
981
939
|
};
|
|
982
940
|
const makeProgramListener = (pattern, onReport) => ({ Program: (program) => {
|
|
983
941
|
const tokens = program.tokens ?? [];
|
|
@@ -1032,9 +990,9 @@ const ruleAvoidBarrelFiles = createRule({
|
|
|
1032
990
|
declarationCount: declarationCount + 1,
|
|
1033
991
|
exportCount
|
|
1034
992
|
};
|
|
1035
|
-
if (statement.type === AST_NODE_TYPES.ExportNamedDeclaration) return {
|
|
993
|
+
if (statement.type === AST_NODE_TYPES.ExportNamedDeclaration && statement.exportKind !== "type") return {
|
|
1036
994
|
declarationCount,
|
|
1037
|
-
exportCount: exportCount + statement.specifiers.length
|
|
995
|
+
exportCount: exportCount + statement.specifiers.filter((specifier) => specifier.exportKind !== "type").length
|
|
1038
996
|
};
|
|
1039
997
|
if (statement.type === AST_NODE_TYPES.ExportAllDeclaration && statement.exportKind !== "type") return {
|
|
1040
998
|
declarationCount,
|
|
@@ -1062,7 +1020,7 @@ const ruleAvoidBarrelFiles = createRule({
|
|
|
1062
1020
|
declarationCount: 0,
|
|
1063
1021
|
exportCount: 0
|
|
1064
1022
|
});
|
|
1065
|
-
if (exportCount > declarationCount && exportCount
|
|
1023
|
+
if (exportCount > declarationCount && exportCount >= amountOfExportsToConsiderModuleAsBarrel) context.report({
|
|
1066
1024
|
node,
|
|
1067
1025
|
messageId: "avoidBarrelFiles"
|
|
1068
1026
|
});
|
|
@@ -1100,7 +1058,7 @@ const ruleNoBidi = createRule({
|
|
|
1100
1058
|
//#endregion
|
|
1101
1059
|
//#region src/rules/no-force-cast-via-top-type/no-force-cast-via-top-type.ts
|
|
1102
1060
|
const isTopType = (node) => node.type === AST_NODE_TYPES.TSAnyKeyword || node.type === AST_NODE_TYPES.TSUnknownKeyword;
|
|
1103
|
-
const
|
|
1061
|
+
const isCastToAnotherType = (node) => node?.type === AST_NODE_TYPES.TSAsExpression && !isTopType(node.typeAnnotation);
|
|
1104
1062
|
const ruleNoForceCastViaTopType = createRule({
|
|
1105
1063
|
name: "no-force-cast-via-top-type",
|
|
1106
1064
|
meta: {
|
|
@@ -1115,7 +1073,7 @@ const ruleNoForceCastViaTopType = createRule({
|
|
|
1115
1073
|
},
|
|
1116
1074
|
create: (context) => ({ TSAsExpression: (node) => {
|
|
1117
1075
|
if (!isTopType(node.typeAnnotation)) return;
|
|
1118
|
-
if (!
|
|
1076
|
+
if (!isCastToAnotherType(node.parent)) return;
|
|
1119
1077
|
const type = node.typeAnnotation.type === AST_NODE_TYPES.TSAnyKeyword ? "any" : "unknown";
|
|
1120
1078
|
context.report({
|
|
1121
1079
|
node,
|
|
@@ -1179,13 +1137,23 @@ const ruleNoImportFromDist = createRule({
|
|
|
1179
1137
|
schema: [],
|
|
1180
1138
|
messages: { noImportFromDist: "Do not import modules from the `dist` folder. Got {{path}}." }
|
|
1181
1139
|
},
|
|
1182
|
-
create: (context) => ({
|
|
1183
|
-
|
|
1184
|
-
node
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1140
|
+
create: (context) => ({
|
|
1141
|
+
"ImportDeclaration": (node) => {
|
|
1142
|
+
if (isDist(node.source.value)) context.report({
|
|
1143
|
+
node,
|
|
1144
|
+
messageId: "noImportFromDist",
|
|
1145
|
+
data: { path: node.source.value }
|
|
1146
|
+
});
|
|
1147
|
+
},
|
|
1148
|
+
"CallExpression[callee.name=\"require\"]": (node) => {
|
|
1149
|
+
const firstArg = node.arguments.at(0);
|
|
1150
|
+
if (firstArg?.type === AST_NODE_TYPES.Literal && typeof firstArg.value === "string" && isDist(firstArg.value)) context.report({
|
|
1151
|
+
node,
|
|
1152
|
+
messageId: "noImportFromDist",
|
|
1153
|
+
data: { path: firstArg.value }
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
})
|
|
1189
1157
|
});
|
|
1190
1158
|
//#endregion
|
|
1191
1159
|
//#region src/rules/no-import-node-modules-by-path/no-import-node-modules-by-path.ts
|
|
@@ -1209,8 +1177,8 @@ const ruleNoImportNodeModulesByPath = createRule({
|
|
|
1209
1177
|
});
|
|
1210
1178
|
},
|
|
1211
1179
|
"CallExpression[callee.name=\"require\"]": (node) => {
|
|
1212
|
-
const firstArg = node.arguments
|
|
1213
|
-
if (firstArg
|
|
1180
|
+
const firstArg = node.arguments.at(0);
|
|
1181
|
+
if (firstArg?.type === AST_NODE_TYPES.Literal && typeof firstArg.value === "string" && firstArg.value.includes("/node_modules/")) context.report({
|
|
1214
1182
|
node,
|
|
1215
1183
|
messageId: "noImportNodeModulesByPath"
|
|
1216
1184
|
});
|
|
@@ -1250,20 +1218,19 @@ const ruleNoInvisibleCharacters = createRule({
|
|
|
1250
1218
|
//#region src/rules/no-redundant-variable/no-redundant-variable.ts
|
|
1251
1219
|
const isRedundantVariable = (node, exit) => {
|
|
1252
1220
|
if (!node) return false;
|
|
1253
|
-
return node.type === AST_NODE_TYPES.VariableDeclaration && node.declarations.length === 1 && node.declarations.
|
|
1221
|
+
return node.type === AST_NODE_TYPES.VariableDeclaration && node.declarations.length === 1 && node.declarations[0].init !== null && isSameIdentifier(exit.argument, node.declarations[0].id);
|
|
1254
1222
|
};
|
|
1255
|
-
const isRedundantVariableFixer = (source, variable, exit) => (fixer) => {
|
|
1256
|
-
const { init, id } = variable.declarations[0];
|
|
1257
|
-
if (!init || !exit.argument) return null;
|
|
1223
|
+
const isRedundantVariableFixer = (source, variable, id, init, exit) => (fixer) => {
|
|
1258
1224
|
const replaced = getReturnExpression(init);
|
|
1259
1225
|
const modified = wrap(source.getText(replaced), (input) => {
|
|
1260
1226
|
if (!id.typeAnnotation) return input;
|
|
1261
1227
|
const annotation = source.getText(id.typeAnnotation.typeAnnotation);
|
|
1262
|
-
return `(${input}) as ${
|
|
1228
|
+
return `(${input}) as ${replaced === init ? annotation : `Promise<${annotation}>`}`;
|
|
1263
1229
|
});
|
|
1264
1230
|
return [fixer.remove(variable), fixer.replaceText(exit.argument, modified)];
|
|
1265
1231
|
};
|
|
1266
1232
|
const isReturnStatement = (node) => node.type === AST_NODE_TYPES.ReturnStatement && isIdentifier(node.argument);
|
|
1233
|
+
const isSelfReferencing = (source, variable, init) => source.getDeclaredVariables(variable).some(({ references }) => references.some(({ identifier }) => identifier.range[0] >= init.range[0] && identifier.range[1] <= init.range[1]));
|
|
1267
1234
|
const ruleNoRedundantVariables = createRule({
|
|
1268
1235
|
name: "no-redundant-variable",
|
|
1269
1236
|
meta: {
|
|
@@ -1275,7 +1242,7 @@ const ruleNoRedundantVariables = createRule({
|
|
|
1275
1242
|
},
|
|
1276
1243
|
fixable: "code",
|
|
1277
1244
|
schema: [],
|
|
1278
|
-
messages: { noRedundantVar: "
|
|
1245
|
+
messages: { noRedundantVar: "Return the value directly instead of assigning it to a redundant variable." }
|
|
1279
1246
|
},
|
|
1280
1247
|
create: (context) => ({ BlockStatement: ({ body }) => {
|
|
1281
1248
|
let mut_previous;
|
|
@@ -1284,11 +1251,14 @@ const ruleNoRedundantVariables = createRule({
|
|
|
1284
1251
|
mut_previous = statement;
|
|
1285
1252
|
continue;
|
|
1286
1253
|
}
|
|
1287
|
-
if (isRedundantVariable(mut_previous, statement))
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1254
|
+
if (isRedundantVariable(mut_previous, statement)) {
|
|
1255
|
+
const { id, init } = mut_previous.declarations[0];
|
|
1256
|
+
if (init && !isSelfReferencing(context.sourceCode, mut_previous, init)) context.report({
|
|
1257
|
+
node: statement,
|
|
1258
|
+
messageId: "noRedundantVar",
|
|
1259
|
+
fix: isRedundantVariableFixer(context.sourceCode, mut_previous, id, init, statement)
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1292
1262
|
return;
|
|
1293
1263
|
}
|
|
1294
1264
|
} })
|
|
@@ -1301,7 +1271,7 @@ const ruleNoStringInterpolation = createRule({
|
|
|
1301
1271
|
meta: {
|
|
1302
1272
|
type: "suggestion",
|
|
1303
1273
|
docs: {
|
|
1304
|
-
description: "Disallow
|
|
1274
|
+
description: "Disallow multiline expressions in string interpolation.",
|
|
1305
1275
|
recommended: "stylistic",
|
|
1306
1276
|
url: "https://dimensiondev.github.io/eslint-plugin/src/rules/string/no-interpolation"
|
|
1307
1277
|
},
|
|
@@ -1349,6 +1319,18 @@ const ruleNoTopLevelAwait = createRule({
|
|
|
1349
1319
|
node,
|
|
1350
1320
|
messageId: "noTopLevelAwait"
|
|
1351
1321
|
});
|
|
1322
|
+
},
|
|
1323
|
+
"ForOfStatement": (node) => {
|
|
1324
|
+
if (mut_functionDepth === 0 && node.await) context.report({
|
|
1325
|
+
node,
|
|
1326
|
+
messageId: "noTopLevelAwait"
|
|
1327
|
+
});
|
|
1328
|
+
},
|
|
1329
|
+
"VariableDeclaration": (node) => {
|
|
1330
|
+
if (mut_functionDepth === 0 && node.kind === "await using") context.report({
|
|
1331
|
+
node,
|
|
1332
|
+
messageId: "noTopLevelAwait"
|
|
1333
|
+
});
|
|
1352
1334
|
}
|
|
1353
1335
|
};
|
|
1354
1336
|
}
|
|
@@ -1366,7 +1348,7 @@ const ruleNoUnneededArrayFlatMap = createRule({
|
|
|
1366
1348
|
},
|
|
1367
1349
|
fixable: "code",
|
|
1368
1350
|
schema: [],
|
|
1369
|
-
messages: { noUnneededArrayFlatMap: "
|
|
1351
|
+
messages: { noUnneededArrayFlatMap: "Use `Array#flat()` instead of `Array#flatMap()` with an identity callback." }
|
|
1370
1352
|
},
|
|
1371
1353
|
create: (context) => ({ CallExpression: (node) => {
|
|
1372
1354
|
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
@@ -1375,11 +1357,14 @@ const ruleNoUnneededArrayFlatMap = createRule({
|
|
|
1375
1357
|
context.report({
|
|
1376
1358
|
node,
|
|
1377
1359
|
messageId: "noUnneededArrayFlatMap",
|
|
1378
|
-
fix: (fixer) => [fixer.replaceText(property, "flat"),
|
|
1360
|
+
fix: (fixer) => [fixer.replaceText(property, "flat"), fixer.replaceTextRange([node.arguments[0].range[0], node.range[1] - 1], "")]
|
|
1379
1361
|
});
|
|
1380
1362
|
} })
|
|
1381
1363
|
});
|
|
1382
1364
|
//#endregion
|
|
1365
|
+
//#region src/rules/package.json
|
|
1366
|
+
var version = "3.3.0";
|
|
1367
|
+
//#endregion
|
|
1383
1368
|
//#region src/rules/prefer-early-return/prefer-early-return.ts
|
|
1384
1369
|
const isTriggering = (node, maximumStatements) => {
|
|
1385
1370
|
if (node.type !== AST_NODE_TYPES.IfStatement || node.alternate !== null) return false;
|
|
@@ -1387,7 +1372,6 @@ const isTriggering = (node, maximumStatements) => {
|
|
|
1387
1372
|
return consequent.type === AST_NODE_TYPES.ExpressionStatement && maximumStatements === 0 || consequent.type === AST_NODE_TYPES.BlockStatement && consequent.body.length > maximumStatements;
|
|
1388
1373
|
};
|
|
1389
1374
|
const makeFixer = (context, parent) => (fixer) => {
|
|
1390
|
-
if (parent.type !== AST_NODE_TYPES.IfStatement) return [];
|
|
1391
1375
|
const { test, consequent } = parent;
|
|
1392
1376
|
const bodyText = consequent.type === AST_NODE_TYPES.BlockStatement ? context.sourceCode.getText(consequent).slice(1, -1).trim() : context.sourceCode.getText(consequent);
|
|
1393
1377
|
const negated = test.type === AST_NODE_TYPES.UnaryExpression && test.operator === "!" ? context.sourceCode.getText(test.argument) : `!(${context.sourceCode.getText(test)})`;
|
|
@@ -1420,11 +1404,12 @@ const rulePreferEarlyReturns = createRule({
|
|
|
1420
1404
|
defaultOptions: [{ maximumStatements: 1 }],
|
|
1421
1405
|
create: (context, [{ maximumStatements }]) => ({ BlockStatement: ({ body, parent }) => {
|
|
1422
1406
|
if (!isFunctionLike(parent)) return;
|
|
1423
|
-
|
|
1407
|
+
const statement = body.at(0);
|
|
1408
|
+
if (statement === void 0 || body.length !== 1 || !isTriggering(statement, maximumStatements)) return;
|
|
1424
1409
|
context.report({
|
|
1425
|
-
node:
|
|
1410
|
+
node: statement,
|
|
1426
1411
|
messageId: "preferEarlyReturn",
|
|
1427
|
-
fix: makeFixer(context,
|
|
1412
|
+
fix: makeFixer(context, statement)
|
|
1428
1413
|
});
|
|
1429
1414
|
} })
|
|
1430
1415
|
});
|
|
@@ -1452,7 +1437,7 @@ const rulePreferFetch = createRule({
|
|
|
1452
1437
|
name: "prefer-fetch",
|
|
1453
1438
|
meta: {
|
|
1454
1439
|
docs: {
|
|
1455
|
-
description: "Enforce fetch",
|
|
1440
|
+
description: "Enforce `fetch()` over legacy HTTP request APIs and libraries.",
|
|
1456
1441
|
recommended: "stylistic",
|
|
1457
1442
|
url: "https://dimensiondev.github.io/eslint-plugin/src/rules/prefer-fetch"
|
|
1458
1443
|
},
|
|
@@ -1489,16 +1474,17 @@ const rulePreferFetch = createRule({
|
|
|
1489
1474
|
//#region src/rules/prefer-reduce-over-chaining/prefer-reduce-over-chaining.ts
|
|
1490
1475
|
const arrayHighOrderFunctions = /* @__PURE__ */ new Set([
|
|
1491
1476
|
"filter",
|
|
1477
|
+
"flatMap",
|
|
1492
1478
|
"forEach",
|
|
1493
1479
|
"map",
|
|
1494
1480
|
"reduce",
|
|
1495
1481
|
"reduceRight"
|
|
1496
1482
|
]);
|
|
1497
1483
|
const isArrayHigherOrderFunction = (node) => {
|
|
1498
|
-
if (node
|
|
1484
|
+
if (node?.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
1499
1485
|
if (node.computed) return false;
|
|
1500
1486
|
if (node.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
1501
|
-
return arrayHighOrderFunctions.has(node.property.name) && node.parent.type === AST_NODE_TYPES.CallExpression;
|
|
1487
|
+
return arrayHighOrderFunctions.has(node.property.name) && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
|
|
1502
1488
|
};
|
|
1503
1489
|
const rulePreferReduceOverChaining = createRule({
|
|
1504
1490
|
name: "prefer-reduce-over-chaining",
|
|
@@ -1515,7 +1501,6 @@ const rulePreferReduceOverChaining = createRule({
|
|
|
1515
1501
|
create: (context) => ({ MemberExpression: (node) => {
|
|
1516
1502
|
if (!isArrayHigherOrderFunction(node)) return;
|
|
1517
1503
|
const { parent } = node;
|
|
1518
|
-
if (parent.type !== AST_NODE_TYPES.CallExpression) return;
|
|
1519
1504
|
if (!isArrayHigherOrderFunction(parent.parent)) return;
|
|
1520
1505
|
context.report({
|
|
1521
1506
|
node: parent,
|
|
@@ -1572,7 +1557,6 @@ const isGuardedIndex = (node) => {
|
|
|
1572
1557
|
return parent.type === AST_NODE_TYPES.LogicalExpression && parent.operator === "??" && parent.left === node;
|
|
1573
1558
|
};
|
|
1574
1559
|
const isMathCall = (node, methods) => {
|
|
1575
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
1576
1560
|
const { callee } = node;
|
|
1577
1561
|
return callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && isIdentifierName(callee.object, "Math") && (methods === void 0 || isIdentifierName(callee.property, methods));
|
|
1578
1562
|
};
|
|
@@ -1769,6 +1753,43 @@ var rules_default = {
|
|
|
1769
1753
|
configs
|
|
1770
1754
|
};
|
|
1771
1755
|
//#endregion
|
|
1756
|
+
//#region src/configs/imports.ts
|
|
1757
|
+
const imports = async (options) => {
|
|
1758
|
+
const { files, overrides, stylistic, typescript } = options;
|
|
1759
|
+
const [importLite] = await loadPackages(["eslint-plugin-import-lite"]);
|
|
1760
|
+
const stylisticEnabled = stylistic !== false;
|
|
1761
|
+
return [{
|
|
1762
|
+
name: "moso/imports",
|
|
1763
|
+
plugins: {
|
|
1764
|
+
"@moso": memoize(rules_default, "@moso/eslint-plugin"),
|
|
1765
|
+
"import-lite": memoize(importLite, "eslint-plugin-import-lite")
|
|
1766
|
+
},
|
|
1767
|
+
rules: {
|
|
1768
|
+
"@moso/no-import-duplicates": "error",
|
|
1769
|
+
"@moso/no-import-from-dist": "error",
|
|
1770
|
+
"@moso/no-import-node-modules-by-path": "error",
|
|
1771
|
+
"import-lite/consistent-type-specifier-style": "error",
|
|
1772
|
+
"import-lite/first": "error",
|
|
1773
|
+
"import-lite/no-duplicates": "error",
|
|
1774
|
+
"import-lite/no-mutable-exports": "error",
|
|
1775
|
+
"import-lite/no-named-default": "error",
|
|
1776
|
+
...stylisticEnabled && { "import-lite/newline-after-import": ["error", { considerComments: false }] },
|
|
1777
|
+
...overrides
|
|
1778
|
+
}
|
|
1779
|
+
}, ...typescript ? [{
|
|
1780
|
+
name: "moso/imports/typescript",
|
|
1781
|
+
files,
|
|
1782
|
+
rules: {
|
|
1783
|
+
"@typescript-eslint/no-import-type-side-effects": "error",
|
|
1784
|
+
"@typescript-eslint/consistent-type-imports": [stylisticEnabled ? "error" : "off", {
|
|
1785
|
+
disallowTypeAnnotations: false,
|
|
1786
|
+
fixStyle: "inline-type-imports",
|
|
1787
|
+
prefer: "type-imports"
|
|
1788
|
+
}]
|
|
1789
|
+
}
|
|
1790
|
+
}] : []];
|
|
1791
|
+
};
|
|
1792
|
+
//#endregion
|
|
1772
1793
|
//#region src/configs/javascript.ts
|
|
1773
1794
|
const useNumberIsFinite = "Please use `Number.isFinite` instead.";
|
|
1774
1795
|
const useNumberIsNan = "Please use `Number.isNaN` instead.";
|
|
@@ -2088,7 +2109,7 @@ const javascript = async (options) => {
|
|
|
2088
2109
|
//#endregion
|
|
2089
2110
|
//#region src/configs/jsdoc.ts
|
|
2090
2111
|
const jsdoc = async (options) => {
|
|
2091
|
-
const { files, lessOpinionated, overrides, stylistic } = options;
|
|
2112
|
+
const { files, lessOpinionated, overrides, stylistic, typescript } = options;
|
|
2092
2113
|
const [jsdocPlugin] = await loadPackages(["eslint-plugin-jsdoc"]);
|
|
2093
2114
|
const stylisticEnabled = stylistic === false ? "off" : "error";
|
|
2094
2115
|
return [{
|
|
@@ -2110,7 +2131,6 @@ const jsdoc = async (options) => {
|
|
|
2110
2131
|
"jsdoc/multiline-blocks": stylisticEnabled,
|
|
2111
2132
|
"jsdoc/no-defaults": "warn",
|
|
2112
2133
|
"jsdoc/no-multi-asterisks": "error",
|
|
2113
|
-
"jsdoc/no-undefined-types": ["error", { disableReporting: true }],
|
|
2114
2134
|
"jsdoc/reject-any-type": "error",
|
|
2115
2135
|
"jsdoc/reject-function-type": "error",
|
|
2116
2136
|
"jsdoc/require-jsdoc": ["warn", {
|
|
@@ -2138,7 +2158,7 @@ const jsdoc = async (options) => {
|
|
|
2138
2158
|
"jsdoc/require-yields-check": "error",
|
|
2139
2159
|
"jsdoc/require-yields-type": "error",
|
|
2140
2160
|
"jsdoc/tag-lines": [
|
|
2141
|
-
|
|
2161
|
+
stylisticEnabled,
|
|
2142
2162
|
"never",
|
|
2143
2163
|
{
|
|
2144
2164
|
applyToEndTag: false,
|
|
@@ -2149,7 +2169,6 @@ const jsdoc = async (options) => {
|
|
|
2149
2169
|
"jsdoc/valid-types": "error",
|
|
2150
2170
|
...!lessOpinionated && {
|
|
2151
2171
|
"jsdoc/check-indentation": "warn",
|
|
2152
|
-
"jsdoc/check-line-alignment": "error",
|
|
2153
2172
|
"jsdoc/no-bad-blocks": ["warn", { ignore: [
|
|
2154
2173
|
"ts-check",
|
|
2155
2174
|
"ts-expect-error",
|
|
@@ -2157,7 +2176,7 @@ const jsdoc = async (options) => {
|
|
|
2157
2176
|
"ts-nocheck",
|
|
2158
2177
|
"vue-ignore"
|
|
2159
2178
|
] }],
|
|
2160
|
-
"jsdoc/no-types": "warn",
|
|
2179
|
+
"jsdoc/no-types": typescript ? "off" : "warn",
|
|
2161
2180
|
"jsdoc/require-asterisk-prefix": "warn",
|
|
2162
2181
|
"jsdoc/require-description": "warn",
|
|
2163
2182
|
"jsdoc/require-hyphen-before-param-description": "warn",
|
|
@@ -2214,7 +2233,7 @@ const jsonc = async (options) => {
|
|
|
2214
2233
|
"jsonc/array-bracket-spacing": [stylisticEnabled, "never"],
|
|
2215
2234
|
"jsonc/comma-dangle": [stylisticEnabled, "never"],
|
|
2216
2235
|
"jsonc/comma-style": [stylisticEnabled, "last"],
|
|
2217
|
-
"jsonc/indent": [stylisticEnabled,
|
|
2236
|
+
"jsonc/indent": [stylisticEnabled, indent],
|
|
2218
2237
|
"jsonc/key-spacing": [stylisticEnabled, {
|
|
2219
2238
|
afterColon: true,
|
|
2220
2239
|
beforeColon: false
|
|
@@ -2298,7 +2317,7 @@ const jsx = async (options) => {
|
|
|
2298
2317
|
//#endregion
|
|
2299
2318
|
//#region src/configs/nextjs.ts
|
|
2300
2319
|
const nextjs = async (options) => {
|
|
2301
|
-
const { files, mode, overrides } = options;
|
|
2320
|
+
const { files, mode, overrides, rootDir } = options;
|
|
2302
2321
|
const [nextjsPlugin] = await loadPackages(["@next/eslint-plugin-next"]);
|
|
2303
2322
|
return [{
|
|
2304
2323
|
name: "moso/nextjs/setup",
|
|
@@ -2310,7 +2329,10 @@ const nextjs = async (options) => {
|
|
|
2310
2329
|
parserOptions: { ecmaFeatures: { jsx: true } },
|
|
2311
2330
|
sourceType: "module"
|
|
2312
2331
|
},
|
|
2313
|
-
settings: {
|
|
2332
|
+
settings: {
|
|
2333
|
+
react: { version: "detect" },
|
|
2334
|
+
...rootDir !== void 0 && { next: { rootDir } }
|
|
2335
|
+
},
|
|
2314
2336
|
rules: {
|
|
2315
2337
|
...(assert.ok(!Array.isArray(nextjsPlugin.configs.recommended)), nextjsPlugin.configs.recommended.rules),
|
|
2316
2338
|
...(assert.ok(!Array.isArray(nextjsPlugin.configs["core-web-vitals"])), nextjsPlugin.configs["core-web-vitals"].rules),
|
|
@@ -2403,7 +2425,7 @@ const node = async (options) => {
|
|
|
2403
2425
|
},
|
|
2404
2426
|
{
|
|
2405
2427
|
name: "moso/node/rules",
|
|
2406
|
-
files,
|
|
2428
|
+
files: files ?? ["**/*.?([cm])[jt]s?(x)"],
|
|
2407
2429
|
languageOptions: { globals: { ...globals.node } },
|
|
2408
2430
|
settings: { node: { version: "^22.22.3 || >=24" } },
|
|
2409
2431
|
rules: {
|
|
@@ -2445,7 +2467,7 @@ const node = async (options) => {
|
|
|
2445
2467
|
},
|
|
2446
2468
|
...options.strict ? [{
|
|
2447
2469
|
name: "moso/node/strict",
|
|
2448
|
-
files:
|
|
2470
|
+
files: options.module ? [GLOB_CJS] : [GLOB_CJS, GLOB_JS],
|
|
2449
2471
|
rules: { strict: ["warn", "global"] }
|
|
2450
2472
|
}] : []
|
|
2451
2473
|
];
|
|
@@ -2690,9 +2712,9 @@ const perfectionist = async (options) => {
|
|
|
2690
2712
|
},
|
|
2691
2713
|
ignoreCase: true,
|
|
2692
2714
|
type: "alphabetical"
|
|
2693
|
-
}]
|
|
2694
|
-
|
|
2695
|
-
|
|
2715
|
+
}],
|
|
2716
|
+
...overrides
|
|
2717
|
+
}
|
|
2696
2718
|
}];
|
|
2697
2719
|
};
|
|
2698
2720
|
//#endregion
|
|
@@ -2745,15 +2767,15 @@ const RemixPackages = [
|
|
|
2745
2767
|
"@remix-run/serve"
|
|
2746
2768
|
];
|
|
2747
2769
|
const react = async (options) => {
|
|
2748
|
-
const { a11y, additionalHooks = "useIsomorphicLayoutEffect", files, filesTypeAware, ignoresTypeAware, lessOpinionated, nextjs, overrides, overridesA11y, overridesTypeAware, parserOptions, projectRoot, stylistic, typescript } = options;
|
|
2770
|
+
const { a11y, additionalHooks = "useIsomorphicLayoutEffect", files, filesTypeAware, ignoresTypeAware, lessOpinionated, nextjs, overrides, overridesA11y, overridesTypeAware, parserOptions, projectRoot, reactRefresh, stylistic, typescript } = options;
|
|
2749
2771
|
const [reactPlugin, reactHooksPlugin, reactRefreshPlugin, reactYouMightNotNeedAnEffect] = await loadPackages([
|
|
2750
2772
|
"@eslint-react/eslint-plugin",
|
|
2751
2773
|
"eslint-plugin-react-hooks",
|
|
2752
2774
|
"eslint-plugin-react-refresh",
|
|
2753
2775
|
"eslint-plugin-react-you-might-not-need-an-effect"
|
|
2754
2776
|
]);
|
|
2755
|
-
const isTypeAware = typescript && typeof projectRoot === "string";
|
|
2756
|
-
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((x) => isPackageExists(x));
|
|
2777
|
+
const isTypeAware = typescript && typeof projectRoot === "string" && parserOptions?.projectService !== false;
|
|
2778
|
+
const isAllowConstantExport = reactRefresh?.allowConstantExport ?? ReactRefreshAllowConstantExportPackages.some((x) => isPackageExists(x));
|
|
2757
2779
|
const isUsingNextJS = nextjs !== false;
|
|
2758
2780
|
const isUsingRemix = RemixPackages.some((x) => isPackageExists(x));
|
|
2759
2781
|
const isUsingReactRouter = ReactRouterPackages.some((x) => isPackageExists(x));
|
|
@@ -3463,7 +3485,7 @@ const tailwind = async (options) => {
|
|
|
3463
3485
|
const stylisticEnabled = stylistic !== false;
|
|
3464
3486
|
return [{
|
|
3465
3487
|
name: "moso/tailwind",
|
|
3466
|
-
settings: { "better-tailwindcss": version === 4 ? { entryPoint } :
|
|
3488
|
+
settings: { "better-tailwindcss": version === 4 ? { entryPoint } : { config } },
|
|
3467
3489
|
plugins: { "tailwind-better": memoize(tailwindPlugin, "eslint-plugin-better-tailwindcss") },
|
|
3468
3490
|
rules: {
|
|
3469
3491
|
"tailwind-better/no-conflicting-classes": "error",
|
|
@@ -3475,7 +3497,8 @@ const tailwind = async (options) => {
|
|
|
3475
3497
|
group: "newLine",
|
|
3476
3498
|
indent: stylistic.indent,
|
|
3477
3499
|
lineBreakStyle: "unix",
|
|
3478
|
-
preferSingleLine: false
|
|
3500
|
+
preferSingleLine: false,
|
|
3501
|
+
printWidth: 0
|
|
3479
3502
|
}],
|
|
3480
3503
|
"tailwind-better/enforce-consistent-class-order": ["error", {
|
|
3481
3504
|
order: "strict",
|
|
@@ -3565,7 +3588,7 @@ const toml = async (options) => {
|
|
|
3565
3588
|
minItems: 4,
|
|
3566
3589
|
multiline: true
|
|
3567
3590
|
}],
|
|
3568
|
-
"toml/indent": ["error",
|
|
3591
|
+
"toml/indent": ["error", indent],
|
|
3569
3592
|
"toml/inline-table-curly-spacing": "error",
|
|
3570
3593
|
"toml/key-spacing": "error",
|
|
3571
3594
|
"toml/padding-line-between-pairs": "error",
|
|
@@ -3584,7 +3607,7 @@ const typescript = async (options) => {
|
|
|
3584
3607
|
const { componentExts, disableTypeAwareRules, erasableOnly, files, filesTypeAware, functionalEnforcement, lessOpinionated, mode, overrides, overridesTypeAware, parserOptions, projectRoot, stylistic, unsafe } = options;
|
|
3585
3608
|
const [tsEslintPlugin, tsEslintParser] = await loadPackages(["@typescript-eslint/eslint-plugin", "@typescript-eslint/parser"]);
|
|
3586
3609
|
const [erasableSyntaxPlugin] = erasableOnly !== false && !lessOpinionated ? await loadPackages(["eslint-plugin-erasable-syntax-only"]) : [void 0];
|
|
3587
|
-
const isTypeAware = typeof projectRoot === "string";
|
|
3610
|
+
const isTypeAware = typeof projectRoot === "string" && parserOptions.projectService !== false;
|
|
3588
3611
|
const stylisticEnabled = stylistic !== false;
|
|
3589
3612
|
return [
|
|
3590
3613
|
{
|
|
@@ -3595,7 +3618,7 @@ const typescript = async (options) => {
|
|
|
3595
3618
|
parserOptions: {
|
|
3596
3619
|
ecmaFeatures: { jsx: true },
|
|
3597
3620
|
ecmaVersion: "latest",
|
|
3598
|
-
extraFileExtensions: componentExts.map((ext) =>
|
|
3621
|
+
extraFileExtensions: componentExts.map((ext) => `.${ext}`),
|
|
3599
3622
|
jsxPragma: void 0,
|
|
3600
3623
|
sourceType: "module",
|
|
3601
3624
|
warnOnUnsupportedTypeScriptVersion: true,
|
|
@@ -3892,7 +3915,7 @@ const typescript = async (options) => {
|
|
|
3892
3915
|
parserOptions: {
|
|
3893
3916
|
ecmaFeatures: { jsx: true },
|
|
3894
3917
|
ecmaVersion: "latest",
|
|
3895
|
-
extraFileExtensions: componentExts.map((ext) =>
|
|
3918
|
+
extraFileExtensions: componentExts.map((ext) => `.${ext}`),
|
|
3896
3919
|
jsxPragma: void 0,
|
|
3897
3920
|
projectService: true,
|
|
3898
3921
|
sourceType: "module",
|
|
@@ -3904,7 +3927,7 @@ const typescript = async (options) => {
|
|
|
3904
3927
|
rules: {
|
|
3905
3928
|
...(assert.ok(!Array.isArray(tsEslintPlugin.configs?.["recommended-type-checked-only"])), tsEslintPlugin.configs?.["recommended-type-checked-only"]?.rules),
|
|
3906
3929
|
"no-implied-eval": "off",
|
|
3907
|
-
"
|
|
3930
|
+
"no-throw-literal": "off",
|
|
3908
3931
|
"prefer-destructuring": "off",
|
|
3909
3932
|
"prefer-promise-reject-errors": "off",
|
|
3910
3933
|
"require-await": "off",
|
|
@@ -4137,8 +4160,34 @@ const typescript = async (options) => {
|
|
|
4137
4160
|
};
|
|
4138
4161
|
//#endregion
|
|
4139
4162
|
//#region src/configs/unicorn.ts
|
|
4163
|
+
const DOMRules = [
|
|
4164
|
+
"unicorn/better-dom-traversing",
|
|
4165
|
+
"unicorn/dom-node-dataset",
|
|
4166
|
+
"unicorn/no-blob-to-file",
|
|
4167
|
+
"unicorn/no-canvas-to-image",
|
|
4168
|
+
"unicorn/no-document-cookie",
|
|
4169
|
+
"unicorn/no-incorrect-query-selector",
|
|
4170
|
+
"unicorn/no-invalid-remove-event-listener",
|
|
4171
|
+
"unicorn/no-selector-as-dom-name",
|
|
4172
|
+
"unicorn/no-transition-all",
|
|
4173
|
+
"unicorn/no-unsafe-dom-html",
|
|
4174
|
+
"unicorn/prefer-add-event-listener",
|
|
4175
|
+
"unicorn/prefer-add-event-listener-options",
|
|
4176
|
+
"unicorn/prefer-classlist-toggle",
|
|
4177
|
+
"unicorn/prefer-dom-node-append",
|
|
4178
|
+
"unicorn/prefer-dom-node-html-methods",
|
|
4179
|
+
"unicorn/prefer-dom-node-replace-children",
|
|
4180
|
+
"unicorn/prefer-dom-node-text-content",
|
|
4181
|
+
"unicorn/prefer-keyboard-event-key",
|
|
4182
|
+
"unicorn/prefer-modern-dom-apis",
|
|
4183
|
+
"unicorn/prefer-observer-apis",
|
|
4184
|
+
"unicorn/prefer-path2d",
|
|
4185
|
+
"unicorn/prefer-query-selector",
|
|
4186
|
+
"unicorn/prefer-scoped-selector",
|
|
4187
|
+
"unicorn/require-passive-events"
|
|
4188
|
+
];
|
|
4140
4189
|
const unicorn = async (options) => {
|
|
4141
|
-
const { files, lessOpinionated, overrides } = options;
|
|
4190
|
+
const { files, hasDOM, lessOpinionated, overrides } = options;
|
|
4142
4191
|
const [unicornPlugin] = await loadPackages(["eslint-plugin-unicorn"]);
|
|
4143
4192
|
return [{
|
|
4144
4193
|
name: "moso/unicorn/setup",
|
|
@@ -4239,6 +4288,7 @@ const unicorn = async (options) => {
|
|
|
4239
4288
|
"unicorn/require-module-specifiers": "off",
|
|
4240
4289
|
"unicorn/single-line-block-comment-style": "off"
|
|
4241
4290
|
},
|
|
4291
|
+
...hasDOM === false && { ...Object.fromEntries(DOMRules.map((rule) => [rule, "off"])) },
|
|
4242
4292
|
...overrides
|
|
4243
4293
|
}
|
|
4244
4294
|
}];
|
|
@@ -4460,7 +4510,7 @@ const vue = async (options) => {
|
|
|
4460
4510
|
name: "moso/nuxt/rules",
|
|
4461
4511
|
files: [
|
|
4462
4512
|
`**/app.{${GLOB_SRC_EXT},vue}`,
|
|
4463
|
-
`**/components
|
|
4513
|
+
`**/components/**/*.{${GLOB_SRC_EXT},vue}`,
|
|
4464
4514
|
`**/error.{${GLOB_SRC_EXT},vue}`,
|
|
4465
4515
|
`**/layouts/**/*.{${GLOB_SRC_EXT},vue}`,
|
|
4466
4516
|
`**/pages/**/*.{${GLOB_SRC_EXT},vue}`
|
|
@@ -4544,36 +4594,42 @@ const VuePackages = [
|
|
|
4544
4594
|
/**
|
|
4545
4595
|
* Construct an array of ESLint flat config items.
|
|
4546
4596
|
*
|
|
4547
|
-
* @param {OptionsConfig & TypedFlatConfigItem} options - Options for generating the ESLint configurations.
|
|
4597
|
+
* @param {OptionsConfig & TypedFlatConfigItem} [options={}] - Options for generating the ESLint configurations.
|
|
4548
4598
|
* @param {Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]>[]} userConfigs - User configurations to be merged with the generated configurations
|
|
4549
4599
|
* @returns {Promise<TypedFlatConfigItem[]>} - The merged ESLint configurations
|
|
4550
4600
|
*/
|
|
4551
|
-
async function moso(options, ...userConfigs) {
|
|
4552
|
-
const { componentExts = [], isInEditor = isInEditorEnv(), jsdoc: jsdocOptions = false, jsonc: jsoncOptions = false, jsx: jsxOptions = true } = options;
|
|
4553
|
-
|
|
4601
|
+
async function moso(options = {}, ...userConfigs) {
|
|
4602
|
+
const { componentExts: componentExtsOption = [], isInEditor = isInEditorEnv(), jsdoc: jsdocOptions = false, jsonc: jsoncOptions = false, jsx: jsxOptions = true } = options;
|
|
4603
|
+
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.");
|
|
4604
|
+
const mut_packageExistsCache = /* @__PURE__ */ new Map();
|
|
4605
|
+
const packageExists = (name) => {
|
|
4606
|
+
const cached = mut_packageExistsCache.get(name);
|
|
4607
|
+
if (cached !== void 0) return cached;
|
|
4608
|
+
const found = isPackageExists(name);
|
|
4609
|
+
mut_packageExistsCache.set(name, found);
|
|
4610
|
+
return found;
|
|
4611
|
+
};
|
|
4612
|
+
const anyPackageExists = (names) => names.some((x) => packageExists(x));
|
|
4613
|
+
const typescriptRequested = options.typescript ?? packageExists("typescript");
|
|
4554
4614
|
const typescriptVersion = (typescriptRequested === false ? void 0 : await getPackageInfo("typescript"))?.version;
|
|
4555
4615
|
const typescriptUnsupported = typescriptVersion !== void 0 && Number(typescriptVersion.split(".")[0]) >= 7;
|
|
4556
4616
|
if (typescriptUnsupported) {
|
|
4557
|
-
const message = `[@moso/eslint-config] TypeScript ${typescriptVersion} was detected, but TypeScript 7 does not ship a programmatic API, so @typescript-eslint (and therefore all TypeScript linting) cannot run against it.\n\n
|
|
4558
|
-
Install the TypeScript 6 compatibility package side-by-side via an npm alias:\n\n
|
|
4559
|
-
npm install -D typescript@npm:@typescript/typescript6\n\n
|
|
4560
|
-
Optionally keep TypeScript 7's own tsc available as "@typescript/native": "npm:typescript@^7.0.2".\n
|
|
4561
|
-
See https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/#running-side-by-side-with-typescript-6.0`;
|
|
4617
|
+
const message = `[@moso/eslint-config] TypeScript ${typescriptVersion} was detected, but TypeScript 7 does not ship a programmatic API, so @typescript-eslint (and therefore all TypeScript linting) cannot run against it.\n\nInstall the TypeScript 6 compatibility package side-by-side via an npm alias:\n\n npm install -D typescript@npm:@typescript/typescript6\n\nOptionally keep TypeScript 7's own tsc available as "@typescript/native": "npm:typescript@^7.0.2".\nSee https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/#running-side-by-side-with-typescript-6.0`;
|
|
4562
4618
|
if (options.typescript !== void 0) throw new Error(message);
|
|
4563
4619
|
console.warn(message);
|
|
4564
4620
|
}
|
|
4565
4621
|
const typescriptOptions = typescriptUnsupported ? false : typescriptRequested;
|
|
4566
|
-
const astroOptions = options.astro ?? AstroPackages
|
|
4567
|
-
const nextjsOptions = options.nextjs ?? NextJSPackages
|
|
4568
|
-
const reactOptions = options.react ?? ReactPackages
|
|
4569
|
-
const tailwindOptions = options.tailwind ??
|
|
4570
|
-
const vueOptions = options.vue ?? VuePackages
|
|
4571
|
-
|
|
4572
|
-
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.");
|
|
4622
|
+
const astroOptions = options.astro ?? anyPackageExists(AstroPackages);
|
|
4623
|
+
const nextjsOptions = options.nextjs ?? anyPackageExists(NextJSPackages);
|
|
4624
|
+
const reactOptions = options.react ?? anyPackageExists(ReactPackages);
|
|
4625
|
+
const tailwindOptions = options.tailwind ?? packageExists("tailwindcss");
|
|
4626
|
+
const vueOptions = options.vue ?? anyPackageExists(VuePackages);
|
|
4627
|
+
const componentExts = vueOptions === false ? [...componentExtsOption] : [.../* @__PURE__ */ new Set([...componentExtsOption, "vue"])];
|
|
4573
4628
|
const baselineOptions = options.baseline === false ? false : typeof options.baseline === "object" ? options.baseline : typeof options.baseline === "string" || typeof options.baseline === "number" ? { baseline: options.baseline } : {};
|
|
4574
4629
|
const e18eOptions = options.e18e === false ? false : typeof options.e18e === "object" ? options.e18e : options.e18e === true ? {} : options.lessOpinionated === true ? false : {};
|
|
4575
|
-
const functionalEnforcement = typeof options.functional === "string" ? options.functional : typeof options.functional === "object" ? options.functional.functionalEnforcement ?? "
|
|
4630
|
+
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";
|
|
4576
4631
|
const hasTypeScript = Boolean(typescriptOptions);
|
|
4632
|
+
const hasDOM = options.mode !== "library" || Boolean(astroOptions) || Boolean(nextjsOptions) || Boolean(reactOptions) || Boolean(vueOptions);
|
|
4577
4633
|
const ignoreOptions = typeof options.ignores === "object" ? options.ignores : {};
|
|
4578
4634
|
const modeOptions = typeof options.mode === "string" ? options.mode : "none";
|
|
4579
4635
|
const perfectionistOptions = typeof options.perfectionist === "boolean" ? options.perfectionist : options.lessOpinionated !== true;
|
|
@@ -4582,7 +4638,7 @@ async function moso(options, ...userConfigs) {
|
|
|
4582
4638
|
jsx: typeof jsxOptions === "boolean" ? jsxOptions : true,
|
|
4583
4639
|
...typeof options.stylistic === "object" && options.stylistic
|
|
4584
4640
|
};
|
|
4585
|
-
const { filesTypeAware, ignoresTypeAware, parserOptions, projectRoot: typescriptProjectRoot, useDefaultDefaultProject, ...typescriptSubOptions } = resolveSubOptions(options, "typescript");
|
|
4641
|
+
const { filesTypeAware, ignoresTypeAware, parserOptions, projectRoot: typescriptProjectRoot, unsafe: typescriptUnsafe, useDefaultDefaultProject, ...typescriptSubOptions } = resolveSubOptions(options, "typescript");
|
|
4586
4642
|
const deprecatedProjectRoot = options.projectRoot;
|
|
4587
4643
|
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 }`.");
|
|
4588
4644
|
const projectRootOptions = typeof typescriptProjectRoot === "string" ? checkFilePath(typescriptProjectRoot) : typeof deprecatedProjectRoot === "string" ? checkFilePath(deprecatedProjectRoot) : void 0;
|
|
@@ -4596,7 +4652,6 @@ async function moso(options, ...userConfigs) {
|
|
|
4596
4652
|
GLOB_TS,
|
|
4597
4653
|
GLOB_TSX
|
|
4598
4654
|
];
|
|
4599
|
-
const withRoot = (glob) => projectRootOptions === void 0 ? glob : path.join(projectRootOptions, glob);
|
|
4600
4655
|
const typescriptConfigOptions = {
|
|
4601
4656
|
...typescriptSubOptions,
|
|
4602
4657
|
filesTypeAware: filesTypeAware ?? defaultFilesTypesAware,
|
|
@@ -4605,13 +4660,7 @@ async function moso(options, ...userConfigs) {
|
|
|
4605
4660
|
tsconfigRootDir: projectRootOptions,
|
|
4606
4661
|
...parserOptions,
|
|
4607
4662
|
projectService: projectRootOptions === void 0 || parserOptions?.projectService === false ? false : useDefaultDefaultProject === false ? projectServiceUserConfig : {
|
|
4608
|
-
allowDefaultProject: [
|
|
4609
|
-
withRoot(GLOB_ROOT_DTS),
|
|
4610
|
-
withRoot(GLOB_ROOT_JS),
|
|
4611
|
-
withRoot(GLOB_ROOT_JSX),
|
|
4612
|
-
withRoot(GLOB_ROOT_TS),
|
|
4613
|
-
withRoot(GLOB_ROOT_TSX)
|
|
4614
|
-
],
|
|
4663
|
+
allowDefaultProject: [GLOB_ROOT_JS, GLOB_ROOT_JSX],
|
|
4615
4664
|
...projectServiceUserConfig
|
|
4616
4665
|
}
|
|
4617
4666
|
}
|
|
@@ -4621,50 +4670,50 @@ async function moso(options, ...userConfigs) {
|
|
|
4621
4670
|
ignoreNamePattern: ["^[mM]ut_"],
|
|
4622
4671
|
...resolveSubOptions(options, "functional")
|
|
4623
4672
|
};
|
|
4624
|
-
const mut_configs = [
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4673
|
+
const mut_configs = [];
|
|
4674
|
+
if (options.comments !== false) mut_configs.push(comments({ overrides: getOverrides(options, "comments") }));
|
|
4675
|
+
if (options.ignores !== false) mut_configs.push(ignores({
|
|
4676
|
+
...ignoreOptions,
|
|
4677
|
+
...resolveSubOptions(options, "ignores")
|
|
4678
|
+
}));
|
|
4679
|
+
if (options.imports !== false) mut_configs.push(imports({
|
|
4680
|
+
...typescriptConfigOptions,
|
|
4681
|
+
files: [
|
|
4682
|
+
GLOB_DTS,
|
|
4683
|
+
GLOB_TS,
|
|
4684
|
+
GLOB_TSX
|
|
4685
|
+
],
|
|
4686
|
+
overrides: getOverrides(options, "imports"),
|
|
4687
|
+
stylistic: stylisticOptions,
|
|
4688
|
+
typescript: hasTypeScript
|
|
4689
|
+
}));
|
|
4690
|
+
mut_configs.push(javascript({
|
|
4691
|
+
...functionalConfigOptions,
|
|
4692
|
+
isInEditor,
|
|
4693
|
+
lessOpinionated: options.lessOpinionated,
|
|
4694
|
+
perfectionist: perfectionistOptions,
|
|
4695
|
+
overrides: getOverrides(options, "javascript")
|
|
4696
|
+
}));
|
|
4697
|
+
if (options.node !== false) mut_configs.push(node({
|
|
4698
|
+
files: [GLOB_SRC],
|
|
4699
|
+
hasReact: Boolean(reactOptions),
|
|
4700
|
+
lessOpinionated: options.lessOpinionated,
|
|
4701
|
+
overrides: getOverrides(options, "node"),
|
|
4702
|
+
typescript: hasTypeScript,
|
|
4703
|
+
...resolveSubOptions(options, "node")
|
|
4704
|
+
}));
|
|
4705
|
+
if (options.promise !== false) mut_configs.push(promise({
|
|
4706
|
+
lessOpinionated: options.lessOpinionated,
|
|
4707
|
+
overrides: getOverrides(options, "promise"),
|
|
4708
|
+
typescript: hasTypeScript
|
|
4709
|
+
}));
|
|
4710
|
+
if (options.regexp !== false) mut_configs.push(regexp({ overrides: getOverrides(options, "regexp") }));
|
|
4711
|
+
if (options.unicorn !== false) mut_configs.push(unicorn({
|
|
4712
|
+
files: [GLOB_SRC],
|
|
4713
|
+
hasDOM,
|
|
4714
|
+
lessOpinionated: options.lessOpinionated,
|
|
4715
|
+
overrides: getOverrides(options, "unicorn")
|
|
4716
|
+
}));
|
|
4668
4717
|
if (stylisticOptions !== false) mut_configs.push(stylistic({
|
|
4669
4718
|
...stylisticOptions,
|
|
4670
4719
|
lessOpinionated: options.lessOpinionated,
|
|
@@ -4680,6 +4729,7 @@ async function moso(options, ...userConfigs) {
|
|
|
4680
4729
|
...astroOptions === false ? [] : [GLOB_ASTRO]
|
|
4681
4730
|
],
|
|
4682
4731
|
filesTypeAware: [GLOB_TS, GLOB_TSX],
|
|
4732
|
+
hasDOM,
|
|
4683
4733
|
overrides: getOverrides(options, "baseline"),
|
|
4684
4734
|
projectRoot: projectRootOptions,
|
|
4685
4735
|
typescript: hasTypeScript
|
|
@@ -4687,6 +4737,7 @@ async function moso(options, ...userConfigs) {
|
|
|
4687
4737
|
if (astroOptions !== false) mut_configs.push(astro({
|
|
4688
4738
|
...typescriptConfigOptions,
|
|
4689
4739
|
files: [GLOB_ASTRO],
|
|
4740
|
+
lessOpinionated: options.lessOpinionated,
|
|
4690
4741
|
overrides: getOverrides(options, "astro"),
|
|
4691
4742
|
stylistic: stylisticOptions,
|
|
4692
4743
|
typescript: hasTypeScript,
|
|
@@ -4708,8 +4759,11 @@ async function moso(options, ...userConfigs) {
|
|
|
4708
4759
|
}));
|
|
4709
4760
|
if (jsdocOptions !== false) mut_configs.push(jsdoc({
|
|
4710
4761
|
files: [GLOB_SRC],
|
|
4762
|
+
lessOpinionated: options.lessOpinionated,
|
|
4711
4763
|
overrides: getOverrides(options, "jsdoc"),
|
|
4712
|
-
stylistic: stylisticOptions
|
|
4764
|
+
stylistic: stylisticOptions,
|
|
4765
|
+
typescript: hasTypeScript,
|
|
4766
|
+
...resolveSubOptions(options, "jsdoc")
|
|
4713
4767
|
}));
|
|
4714
4768
|
if (jsoncOptions !== false) mut_configs.push(jsonc({
|
|
4715
4769
|
files: [
|
|
@@ -4730,18 +4784,14 @@ async function moso(options, ...userConfigs) {
|
|
|
4730
4784
|
if (nextjsOptions !== false) mut_configs.push(nextjs({
|
|
4731
4785
|
files: [GLOB_SRC],
|
|
4732
4786
|
mode: modeOptions,
|
|
4733
|
-
overrides: getOverrides(options, "nextjs")
|
|
4787
|
+
overrides: getOverrides(options, "nextjs"),
|
|
4788
|
+
...resolveSubOptions(options, "nextjs")
|
|
4734
4789
|
}));
|
|
4735
4790
|
if (perfectionistOptions) mut_configs.push(perfectionist({ overrides: getOverrides(options, "perfectionist") }));
|
|
4736
4791
|
if (reactOptions !== false) mut_configs.push(react({
|
|
4737
4792
|
...typescriptConfigOptions,
|
|
4738
4793
|
files: [GLOB_SRC],
|
|
4739
|
-
filesTypeAware:
|
|
4740
|
-
GLOB_DTS,
|
|
4741
|
-
GLOB_JSX,
|
|
4742
|
-
GLOB_TS,
|
|
4743
|
-
GLOB_TSX
|
|
4744
|
-
],
|
|
4794
|
+
filesTypeAware: defaultFilesTypesAware,
|
|
4745
4795
|
ignoresTypeAware: [GLOB_ASTRO_TS, `${GLOB_MARKDOWN}/**`],
|
|
4746
4796
|
lessOpinionated: options.lessOpinionated,
|
|
4747
4797
|
nextjs: Boolean(nextjsOptions),
|
|
@@ -4771,7 +4821,8 @@ async function moso(options, ...userConfigs) {
|
|
|
4771
4821
|
mode: modeOptions,
|
|
4772
4822
|
overrides: getOverrides(options, "typescript"),
|
|
4773
4823
|
projectRoot: projectRootOptions,
|
|
4774
|
-
|
|
4824
|
+
stylistic: stylisticOptions,
|
|
4825
|
+
unsafe: typescriptUnsafe ?? "warn"
|
|
4775
4826
|
}));
|
|
4776
4827
|
if (vueOptions !== false) mut_configs.push(vue({
|
|
4777
4828
|
...typescriptConfigOptions,
|
|
@@ -4804,7 +4855,7 @@ async function moso(options, ...userConfigs) {
|
|
|
4804
4855
|
overrides: getOverrides(options, "yaml"),
|
|
4805
4856
|
stylistic: stylisticOptions
|
|
4806
4857
|
}));
|
|
4807
|
-
mut_configs.push(disables());
|
|
4858
|
+
mut_configs.push(disables(functionalEnforcement !== "none"));
|
|
4808
4859
|
let mut_composer = new FlatConfigComposer().append(...mut_configs, ...userConfigs);
|
|
4809
4860
|
if (isInEditor) mut_composer = mut_composer.disableRulesFix([
|
|
4810
4861
|
"unused-imports/no-unused-imports",
|
|
@@ -4842,7 +4893,7 @@ const full = {
|
|
|
4842
4893
|
},
|
|
4843
4894
|
test: true,
|
|
4844
4895
|
toml: true,
|
|
4845
|
-
typescript: { projectRoot:
|
|
4896
|
+
typescript: { projectRoot: process.cwd() },
|
|
4846
4897
|
unicorn: true,
|
|
4847
4898
|
vue: {
|
|
4848
4899
|
a11y: true,
|
|
@@ -4878,4 +4929,4 @@ const off = {
|
|
|
4878
4929
|
yaml: false
|
|
4879
4930
|
};
|
|
4880
4931
|
//#endregion
|
|
4881
|
-
export { GLOB_AI,
|
|
4932
|
+
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_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, promise, react, regexp, resolveSubOptions, sortPackageJson, sortTsconfig, stylistic, tailwind, test, toml, typescript, unicorn, vue, vueInlineElements, yaml };
|