@moso/eslint-config 3.1.0 → 3.2.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.
Files changed (4) hide show
  1. package/README.md +17 -16
  2. package/dist/index.d.mts +483 -461
  3. package/dist/index.mjs +287 -263
  4. package/package.json +31 -31
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 path from "node:path";
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 packages - Package names to check and offer for installation.
232
+ * @param missingPackages - Package names to offer for installation.
212
233
  */
213
- const ensurePackages = async (packages) => {
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) => !isPackageExists(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, 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
- return [{
310
- name: "moso/baseline/setup",
311
- plugins: { "baseline-js": memoize(baselinePlugin, "eslint-plugin-baseline-js") }
312
- }, {
313
- name: `moso/baseline/${isTypeAware ? "type-aware-rules" : "rules"}`,
314
- files: isTypeAware ? filesTypeAware : files,
315
- ignores: isTypeAware ? ignoresTypeAware : {},
316
- rules: {
317
- "baseline-js/use-baseline": ["warn", {
318
- available: baseline ?? "widely",
319
- ignoreFeatures: [...defaultIgnoreFeatures, ...ignoreFeatures ?? []],
320
- ignoreNodeTypes,
321
- includeJsBuiltins: { preset: isTypeAware ? "type-aware" : "auto" },
322
- includeWebApis: { preset: isTypeAware ? "type-aware" : "auto" }
323
- }],
324
- ...isTypeAware ? { ...overridesTypeAware } : { ...overrides }
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: { 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 = "./?(.)*.?([cm])js";
338
- const GLOB_ROOT_JSX = "./?(.)*.?([cm])jsx";
339
- const GLOB_ROOT_TS = "./?(.)*.?([cm])ts";
340
- const GLOB_ROOT_TSX = "./?(.)*.?([cm])tsx";
341
- const GLOB_ROOT_DTS = "./?(.)*.d.?([cm])ts";
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 GLOB_CTS = "**/*.cts";
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: ["**/ISSUES_TEMPLATE/**"],
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 !== false && mode === "library" && isInEditor;
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 (typeof gitignore === "boolean" && gitignore) mut_configs.push(eslintConfigFlatGitIgnore({
781
- files: [".gitignore"],
787
+ if (gitignore !== false) mut_configs.push(eslintConfigFlatGitIgnore({
782
788
  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
- 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, test) => {
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 predicate(current) ? current : findClosest(current.parent);
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
- const re = new RegExp(escape(token.regex.pattern, pattern), [...mut_flags].join(""));
885
- return fixer.replaceText(token, re.toString());
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: return token.value;
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.type !== AST_NODE_TYPES.Literal) return false;
936
+ if (node?.type !== AST_NODE_TYPES.Literal) return false;
978
937
  if (typeof value === "string") return node.value === value;
979
- if ("test" in value) return typeof node.value === "string" && value.test(node.value);
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 > amountOfExportsToConsiderModuleAsBarrel) context.report({
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 isTypeReference = (node) => node?.type === AST_NODE_TYPES.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES.TSTypeReference;
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 (!isTypeReference(node.parent)) return;
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) => ({ ImportDeclaration: (node) => {
1183
- if (isDist(node.source.value)) context.report({
1184
- node,
1185
- messageId: "noImportFromDist",
1186
- data: { path: node.source.value }
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[0];
1213
- if (firstArg.type === AST_NODE_TYPES.Literal && typeof firstArg.value === "string" && firstArg.value.includes("/node_modules/")) context.report({
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,16 +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.some(({ init, id }) => init !== null && isSameIdentifier(exit.argument, id));
1221
+ return node.type === AST_NODE_TYPES.VariableDeclaration && node.declarations.length === 1 && node.declarations[0].init !== null && isSameIdentifier(exit.argument, node.declarations[0].id);
1222
+ };
1223
+ const isSelfReferencing = (source, variable) => {
1224
+ const { init } = variable.declarations[0];
1225
+ return source.getDeclaredVariables(variable).some(({ references }) => references.some(({ identifier }) => identifier.range[0] >= init.range[0] && identifier.range[1] <= init.range[1]));
1254
1226
  };
1255
1227
  const isRedundantVariableFixer = (source, variable, exit) => (fixer) => {
1256
1228
  const { init, id } = variable.declarations[0];
1257
- if (!init || !exit.argument) return null;
1258
1229
  const replaced = getReturnExpression(init);
1259
1230
  const modified = wrap(source.getText(replaced), (input) => {
1260
1231
  if (!id.typeAnnotation) return input;
1261
1232
  const annotation = source.getText(id.typeAnnotation.typeAnnotation);
1262
- return `(${input}) as ${init.type === AST_NODE_TYPES.AwaitExpression ? `Promise<${annotation}>` : annotation}`;
1233
+ return `(${input}) as ${replaced === init ? annotation : `Promise<${annotation}>`}`;
1263
1234
  });
1264
1235
  return [fixer.remove(variable), fixer.replaceText(exit.argument, modified)];
1265
1236
  };
@@ -1275,7 +1246,7 @@ const ruleNoRedundantVariables = createRule({
1275
1246
  },
1276
1247
  fixable: "code",
1277
1248
  schema: [],
1278
- messages: { noRedundantVar: "Disallow redundant variables." }
1249
+ messages: { noRedundantVar: "Return the value directly instead of assigning it to a redundant variable." }
1279
1250
  },
1280
1251
  create: (context) => ({ BlockStatement: ({ body }) => {
1281
1252
  let mut_previous;
@@ -1284,7 +1255,7 @@ const ruleNoRedundantVariables = createRule({
1284
1255
  mut_previous = statement;
1285
1256
  continue;
1286
1257
  }
1287
- if (isRedundantVariable(mut_previous, statement)) context.report({
1258
+ if (isRedundantVariable(mut_previous, statement) && !isSelfReferencing(context.sourceCode, mut_previous)) context.report({
1288
1259
  node: statement,
1289
1260
  messageId: "noRedundantVar",
1290
1261
  fix: isRedundantVariableFixer(context.sourceCode, mut_previous, statement)
@@ -1301,7 +1272,7 @@ const ruleNoStringInterpolation = createRule({
1301
1272
  meta: {
1302
1273
  type: "suggestion",
1303
1274
  docs: {
1304
- description: "Disallow simple string interpolation.",
1275
+ description: "Disallow multiline expressions in string interpolation.",
1305
1276
  recommended: "stylistic",
1306
1277
  url: "https://dimensiondev.github.io/eslint-plugin/src/rules/string/no-interpolation"
1307
1278
  },
@@ -1349,6 +1320,18 @@ const ruleNoTopLevelAwait = createRule({
1349
1320
  node,
1350
1321
  messageId: "noTopLevelAwait"
1351
1322
  });
1323
+ },
1324
+ "ForOfStatement": (node) => {
1325
+ if (mut_functionDepth === 0 && node.await) context.report({
1326
+ node,
1327
+ messageId: "noTopLevelAwait"
1328
+ });
1329
+ },
1330
+ "VariableDeclaration": (node) => {
1331
+ if (mut_functionDepth === 0 && node.kind === "await using") context.report({
1332
+ node,
1333
+ messageId: "noTopLevelAwait"
1334
+ });
1352
1335
  }
1353
1336
  };
1354
1337
  }
@@ -1366,7 +1349,7 @@ const ruleNoUnneededArrayFlatMap = createRule({
1366
1349
  },
1367
1350
  fixable: "code",
1368
1351
  schema: [],
1369
- messages: { noUnneededArrayFlatMap: "Disallow simple `Array#flatMap()` in array." }
1352
+ messages: { noUnneededArrayFlatMap: "Use `Array#flat()` instead of `Array#flatMap()` with an identity callback." }
1370
1353
  },
1371
1354
  create: (context) => ({ CallExpression: (node) => {
1372
1355
  if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return;
@@ -1375,11 +1358,14 @@ const ruleNoUnneededArrayFlatMap = createRule({
1375
1358
  context.report({
1376
1359
  node,
1377
1360
  messageId: "noUnneededArrayFlatMap",
1378
- fix: (fixer) => [fixer.replaceText(property, "flat"), ...node.arguments.map((argument) => fixer.remove(argument))]
1361
+ fix: (fixer) => [fixer.replaceText(property, "flat"), fixer.replaceTextRange([node.arguments[0].range[0], node.range[1] - 1], "")]
1379
1362
  });
1380
1363
  } })
1381
1364
  });
1382
1365
  //#endregion
1366
+ //#region src/rules/package.json
1367
+ var version = "3.2.0";
1368
+ //#endregion
1383
1369
  //#region src/rules/prefer-early-return/prefer-early-return.ts
1384
1370
  const isTriggering = (node, maximumStatements) => {
1385
1371
  if (node.type !== AST_NODE_TYPES.IfStatement || node.alternate !== null) return false;
@@ -1387,7 +1373,6 @@ const isTriggering = (node, maximumStatements) => {
1387
1373
  return consequent.type === AST_NODE_TYPES.ExpressionStatement && maximumStatements === 0 || consequent.type === AST_NODE_TYPES.BlockStatement && consequent.body.length > maximumStatements;
1388
1374
  };
1389
1375
  const makeFixer = (context, parent) => (fixer) => {
1390
- if (parent.type !== AST_NODE_TYPES.IfStatement) return [];
1391
1376
  const { test, consequent } = parent;
1392
1377
  const bodyText = consequent.type === AST_NODE_TYPES.BlockStatement ? context.sourceCode.getText(consequent).slice(1, -1).trim() : context.sourceCode.getText(consequent);
1393
1378
  const negated = test.type === AST_NODE_TYPES.UnaryExpression && test.operator === "!" ? context.sourceCode.getText(test.argument) : `!(${context.sourceCode.getText(test)})`;
@@ -1420,11 +1405,12 @@ const rulePreferEarlyReturns = createRule({
1420
1405
  defaultOptions: [{ maximumStatements: 1 }],
1421
1406
  create: (context, [{ maximumStatements }]) => ({ BlockStatement: ({ body, parent }) => {
1422
1407
  if (!isFunctionLike(parent)) return;
1423
- if (!(body.length === 1 && isTriggering(body[0], maximumStatements))) return;
1408
+ const statement = body.at(0);
1409
+ if (statement === void 0 || body.length !== 1 || !isTriggering(statement, maximumStatements)) return;
1424
1410
  context.report({
1425
- node: body[0],
1411
+ node: statement,
1426
1412
  messageId: "preferEarlyReturn",
1427
- fix: makeFixer(context, body[0])
1413
+ fix: makeFixer(context, statement)
1428
1414
  });
1429
1415
  } })
1430
1416
  });
@@ -1452,7 +1438,7 @@ const rulePreferFetch = createRule({
1452
1438
  name: "prefer-fetch",
1453
1439
  meta: {
1454
1440
  docs: {
1455
- description: "Enforce fetch",
1441
+ description: "Enforce `fetch()` over legacy HTTP request APIs and libraries.",
1456
1442
  recommended: "stylistic",
1457
1443
  url: "https://dimensiondev.github.io/eslint-plugin/src/rules/prefer-fetch"
1458
1444
  },
@@ -1489,16 +1475,17 @@ const rulePreferFetch = createRule({
1489
1475
  //#region src/rules/prefer-reduce-over-chaining/prefer-reduce-over-chaining.ts
1490
1476
  const arrayHighOrderFunctions = /* @__PURE__ */ new Set([
1491
1477
  "filter",
1478
+ "flatMap",
1492
1479
  "forEach",
1493
1480
  "map",
1494
1481
  "reduce",
1495
1482
  "reduceRight"
1496
1483
  ]);
1497
1484
  const isArrayHigherOrderFunction = (node) => {
1498
- if (node.type !== AST_NODE_TYPES.MemberExpression) return false;
1485
+ if (node?.type !== AST_NODE_TYPES.MemberExpression) return false;
1499
1486
  if (node.computed) return false;
1500
1487
  if (node.property.type !== AST_NODE_TYPES.Identifier) return false;
1501
- return arrayHighOrderFunctions.has(node.property.name) && node.parent.type === AST_NODE_TYPES.CallExpression;
1488
+ return arrayHighOrderFunctions.has(node.property.name) && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
1502
1489
  };
1503
1490
  const rulePreferReduceOverChaining = createRule({
1504
1491
  name: "prefer-reduce-over-chaining",
@@ -1515,7 +1502,6 @@ const rulePreferReduceOverChaining = createRule({
1515
1502
  create: (context) => ({ MemberExpression: (node) => {
1516
1503
  if (!isArrayHigherOrderFunction(node)) return;
1517
1504
  const { parent } = node;
1518
- if (parent.type !== AST_NODE_TYPES.CallExpression) return;
1519
1505
  if (!isArrayHigherOrderFunction(parent.parent)) return;
1520
1506
  context.report({
1521
1507
  node: parent,
@@ -1572,7 +1558,6 @@ const isGuardedIndex = (node) => {
1572
1558
  return parent.type === AST_NODE_TYPES.LogicalExpression && parent.operator === "??" && parent.left === node;
1573
1559
  };
1574
1560
  const isMathCall = (node, methods) => {
1575
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
1576
1561
  const { callee } = node;
1577
1562
  return callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && isIdentifierName(callee.object, "Math") && (methods === void 0 || isIdentifierName(callee.property, methods));
1578
1563
  };
@@ -1769,6 +1754,43 @@ var rules_default = {
1769
1754
  configs
1770
1755
  };
1771
1756
  //#endregion
1757
+ //#region src/configs/imports.ts
1758
+ const imports = async (options) => {
1759
+ const { files, overrides, stylistic, typescript } = options;
1760
+ const [importLite] = await loadPackages(["eslint-plugin-import-lite"]);
1761
+ const stylisticEnabled = stylistic !== false;
1762
+ return [{
1763
+ name: "moso/imports",
1764
+ plugins: {
1765
+ "@moso": memoize(rules_default, "@moso/eslint-plugin"),
1766
+ "import-lite": memoize(importLite, "eslint-plugin-import-lite")
1767
+ },
1768
+ rules: {
1769
+ "@moso/no-import-duplicates": "error",
1770
+ "@moso/no-import-from-dist": "error",
1771
+ "@moso/no-import-node-modules-by-path": "error",
1772
+ "import-lite/consistent-type-specifier-style": "error",
1773
+ "import-lite/first": "error",
1774
+ "import-lite/no-duplicates": "error",
1775
+ "import-lite/no-mutable-exports": "error",
1776
+ "import-lite/no-named-default": "error",
1777
+ ...stylisticEnabled && { "import-lite/newline-after-import": ["error", { considerComments: false }] },
1778
+ ...overrides
1779
+ }
1780
+ }, ...typescript ? [{
1781
+ name: "moso/imports/typescript",
1782
+ files,
1783
+ rules: {
1784
+ "@typescript-eslint/no-import-type-side-effects": "error",
1785
+ "@typescript-eslint/consistent-type-imports": [stylisticEnabled ? "error" : "off", {
1786
+ disallowTypeAnnotations: false,
1787
+ fixStyle: "inline-type-imports",
1788
+ prefer: "type-imports"
1789
+ }]
1790
+ }
1791
+ }] : []];
1792
+ };
1793
+ //#endregion
1772
1794
  //#region src/configs/javascript.ts
1773
1795
  const useNumberIsFinite = "Please use `Number.isFinite` instead.";
1774
1796
  const useNumberIsNan = "Please use `Number.isNaN` instead.";
@@ -2088,7 +2110,7 @@ const javascript = async (options) => {
2088
2110
  //#endregion
2089
2111
  //#region src/configs/jsdoc.ts
2090
2112
  const jsdoc = async (options) => {
2091
- const { files, lessOpinionated, overrides, stylistic } = options;
2113
+ const { files, lessOpinionated, overrides, stylistic, typescript } = options;
2092
2114
  const [jsdocPlugin] = await loadPackages(["eslint-plugin-jsdoc"]);
2093
2115
  const stylisticEnabled = stylistic === false ? "off" : "error";
2094
2116
  return [{
@@ -2157,7 +2179,7 @@ const jsdoc = async (options) => {
2157
2179
  "ts-nocheck",
2158
2180
  "vue-ignore"
2159
2181
  ] }],
2160
- "jsdoc/no-types": "warn",
2182
+ "jsdoc/no-types": typescript ? "off" : "warn",
2161
2183
  "jsdoc/require-asterisk-prefix": "warn",
2162
2184
  "jsdoc/require-description": "warn",
2163
2185
  "jsdoc/require-hyphen-before-param-description": "warn",
@@ -2214,7 +2236,7 @@ const jsonc = async (options) => {
2214
2236
  "jsonc/array-bracket-spacing": [stylisticEnabled, "never"],
2215
2237
  "jsonc/comma-dangle": [stylisticEnabled, "never"],
2216
2238
  "jsonc/comma-style": [stylisticEnabled, "last"],
2217
- "jsonc/indent": [stylisticEnabled, typeof indent === "number" || typeof indent === "string" ? indent : 4],
2239
+ "jsonc/indent": [stylisticEnabled, indent],
2218
2240
  "jsonc/key-spacing": [stylisticEnabled, {
2219
2241
  afterColon: true,
2220
2242
  beforeColon: false
@@ -2298,7 +2320,7 @@ const jsx = async (options) => {
2298
2320
  //#endregion
2299
2321
  //#region src/configs/nextjs.ts
2300
2322
  const nextjs = async (options) => {
2301
- const { files, mode, overrides } = options;
2323
+ const { files, mode, overrides, rootDir } = options;
2302
2324
  const [nextjsPlugin] = await loadPackages(["@next/eslint-plugin-next"]);
2303
2325
  return [{
2304
2326
  name: "moso/nextjs/setup",
@@ -2310,7 +2332,10 @@ const nextjs = async (options) => {
2310
2332
  parserOptions: { ecmaFeatures: { jsx: true } },
2311
2333
  sourceType: "module"
2312
2334
  },
2313
- settings: { react: { version: "detect" } },
2335
+ settings: {
2336
+ react: { version: "detect" },
2337
+ ...rootDir !== void 0 && { next: { rootDir } }
2338
+ },
2314
2339
  rules: {
2315
2340
  ...(assert.ok(!Array.isArray(nextjsPlugin.configs.recommended)), nextjsPlugin.configs.recommended.rules),
2316
2341
  ...(assert.ok(!Array.isArray(nextjsPlugin.configs["core-web-vitals"])), nextjsPlugin.configs["core-web-vitals"].rules),
@@ -2403,7 +2428,7 @@ const node = async (options) => {
2403
2428
  },
2404
2429
  {
2405
2430
  name: "moso/node/rules",
2406
- files,
2431
+ files: files ?? ["**/*.?([cm])[jt]s?(x)"],
2407
2432
  languageOptions: { globals: { ...globals.node } },
2408
2433
  settings: { node: { version: "^22.22.3 || >=24" } },
2409
2434
  rules: {
@@ -2445,7 +2470,7 @@ const node = async (options) => {
2445
2470
  },
2446
2471
  ...options.strict ? [{
2447
2472
  name: "moso/node/strict",
2448
- files: files ?? (options.module ? ["**/*.cjs"] : ["**/*.cjs", "**/*.?([cm])js"]),
2473
+ files: options.module ? [GLOB_CJS] : [GLOB_CJS, GLOB_JS],
2449
2474
  rules: { strict: ["warn", "global"] }
2450
2475
  }] : []
2451
2476
  ];
@@ -2690,9 +2715,9 @@ const perfectionist = async (options) => {
2690
2715
  },
2691
2716
  ignoreCase: true,
2692
2717
  type: "alphabetical"
2693
- }]
2694
- },
2695
- ...overrides
2718
+ }],
2719
+ ...overrides
2720
+ }
2696
2721
  }];
2697
2722
  };
2698
2723
  //#endregion
@@ -2745,15 +2770,15 @@ const RemixPackages = [
2745
2770
  "@remix-run/serve"
2746
2771
  ];
2747
2772
  const react = async (options) => {
2748
- const { a11y, additionalHooks = "useIsomorphicLayoutEffect", files, filesTypeAware, ignoresTypeAware, lessOpinionated, nextjs, overrides, overridesA11y, overridesTypeAware, parserOptions, projectRoot, stylistic, typescript } = options;
2773
+ const { a11y, additionalHooks = "useIsomorphicLayoutEffect", files, filesTypeAware, ignoresTypeAware, lessOpinionated, nextjs, overrides, overridesA11y, overridesTypeAware, parserOptions, projectRoot, reactRefresh, stylistic, typescript } = options;
2749
2774
  const [reactPlugin, reactHooksPlugin, reactRefreshPlugin, reactYouMightNotNeedAnEffect] = await loadPackages([
2750
2775
  "@eslint-react/eslint-plugin",
2751
2776
  "eslint-plugin-react-hooks",
2752
2777
  "eslint-plugin-react-refresh",
2753
2778
  "eslint-plugin-react-you-might-not-need-an-effect"
2754
2779
  ]);
2755
- const isTypeAware = typescript && typeof projectRoot === "string";
2756
- const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((x) => isPackageExists(x));
2780
+ const isTypeAware = typescript && typeof projectRoot === "string" && parserOptions?.projectService !== false;
2781
+ const isAllowConstantExport = reactRefresh?.allowConstantExport ?? ReactRefreshAllowConstantExportPackages.some((x) => isPackageExists(x));
2757
2782
  const isUsingNextJS = nextjs !== false;
2758
2783
  const isUsingRemix = RemixPackages.some((x) => isPackageExists(x));
2759
2784
  const isUsingReactRouter = ReactRouterPackages.some((x) => isPackageExists(x));
@@ -3463,7 +3488,7 @@ const tailwind = async (options) => {
3463
3488
  const stylisticEnabled = stylistic !== false;
3464
3489
  return [{
3465
3490
  name: "moso/tailwind",
3466
- settings: { "better-tailwindcss": version === 4 ? { entryPoint } : version === 3 ? { config } : void 0 },
3491
+ settings: { "better-tailwindcss": version === 4 ? { entryPoint } : { config } },
3467
3492
  plugins: { "tailwind-better": memoize(tailwindPlugin, "eslint-plugin-better-tailwindcss") },
3468
3493
  rules: {
3469
3494
  "tailwind-better/no-conflicting-classes": "error",
@@ -3475,7 +3500,8 @@ const tailwind = async (options) => {
3475
3500
  group: "newLine",
3476
3501
  indent: stylistic.indent,
3477
3502
  lineBreakStyle: "unix",
3478
- preferSingleLine: false
3503
+ preferSingleLine: false,
3504
+ printWidth: 0
3479
3505
  }],
3480
3506
  "tailwind-better/enforce-consistent-class-order": ["error", {
3481
3507
  order: "strict",
@@ -3565,7 +3591,7 @@ const toml = async (options) => {
3565
3591
  minItems: 4,
3566
3592
  multiline: true
3567
3593
  }],
3568
- "toml/indent": ["error", typeof indent === "number" || typeof indent === "string" ? indent : 2],
3594
+ "toml/indent": ["error", indent],
3569
3595
  "toml/inline-table-curly-spacing": "error",
3570
3596
  "toml/key-spacing": "error",
3571
3597
  "toml/padding-line-between-pairs": "error",
@@ -3584,7 +3610,7 @@ const typescript = async (options) => {
3584
3610
  const { componentExts, disableTypeAwareRules, erasableOnly, files, filesTypeAware, functionalEnforcement, lessOpinionated, mode, overrides, overridesTypeAware, parserOptions, projectRoot, stylistic, unsafe } = options;
3585
3611
  const [tsEslintPlugin, tsEslintParser] = await loadPackages(["@typescript-eslint/eslint-plugin", "@typescript-eslint/parser"]);
3586
3612
  const [erasableSyntaxPlugin] = erasableOnly !== false && !lessOpinionated ? await loadPackages(["eslint-plugin-erasable-syntax-only"]) : [void 0];
3587
- const isTypeAware = typeof projectRoot === "string";
3613
+ const isTypeAware = typeof projectRoot === "string" && parserOptions.projectService !== false;
3588
3614
  const stylisticEnabled = stylistic !== false;
3589
3615
  return [
3590
3616
  {
@@ -3595,7 +3621,7 @@ const typescript = async (options) => {
3595
3621
  parserOptions: {
3596
3622
  ecmaFeatures: { jsx: true },
3597
3623
  ecmaVersion: "latest",
3598
- extraFileExtensions: componentExts.map((ext) => `**/*.${ext}`),
3624
+ extraFileExtensions: componentExts.map((ext) => `.${ext}`),
3599
3625
  jsxPragma: void 0,
3600
3626
  sourceType: "module",
3601
3627
  warnOnUnsupportedTypeScriptVersion: true,
@@ -3892,7 +3918,7 @@ const typescript = async (options) => {
3892
3918
  parserOptions: {
3893
3919
  ecmaFeatures: { jsx: true },
3894
3920
  ecmaVersion: "latest",
3895
- extraFileExtensions: componentExts.map((ext) => `**/*.${ext}`),
3921
+ extraFileExtensions: componentExts.map((ext) => `.${ext}`),
3896
3922
  jsxPragma: void 0,
3897
3923
  projectService: true,
3898
3924
  sourceType: "module",
@@ -3904,7 +3930,7 @@ const typescript = async (options) => {
3904
3930
  rules: {
3905
3931
  ...(assert.ok(!Array.isArray(tsEslintPlugin.configs?.["recommended-type-checked-only"])), tsEslintPlugin.configs?.["recommended-type-checked-only"]?.rules),
3906
3932
  "no-implied-eval": "off",
3907
- "only-throw-error": "off",
3933
+ "no-throw-literal": "off",
3908
3934
  "prefer-destructuring": "off",
3909
3935
  "prefer-promise-reject-errors": "off",
3910
3936
  "require-await": "off",
@@ -4460,7 +4486,7 @@ const vue = async (options) => {
4460
4486
  name: "moso/nuxt/rules",
4461
4487
  files: [
4462
4488
  `**/app.{${GLOB_SRC_EXT},vue}`,
4463
- `**/components/*/**/*.{${GLOB_SRC_EXT},vue}`,
4489
+ `**/components/**/*.{${GLOB_SRC_EXT},vue}`,
4464
4490
  `**/error.{${GLOB_SRC_EXT},vue}`,
4465
4491
  `**/layouts/**/*.{${GLOB_SRC_EXT},vue}`,
4466
4492
  `**/pages/**/*.{${GLOB_SRC_EXT},vue}`
@@ -4544,35 +4570,40 @@ const VuePackages = [
4544
4570
  /**
4545
4571
  * Construct an array of ESLint flat config items.
4546
4572
  *
4547
- * @param {OptionsConfig & TypedFlatConfigItem} options - Options for generating the ESLint configurations.
4573
+ * @param {OptionsConfig & TypedFlatConfigItem} [options={}] - Options for generating the ESLint configurations.
4548
4574
  * @param {Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]>[]} userConfigs - User configurations to be merged with the generated configurations
4549
4575
  * @returns {Promise<TypedFlatConfigItem[]>} - The merged ESLint configurations
4550
4576
  */
4551
- async function moso(options, ...userConfigs) {
4552
- const { componentExts = [], isInEditor = isInEditorEnv(), jsdoc: jsdocOptions = false, jsonc: jsoncOptions = false, jsx: jsxOptions = true } = options;
4553
- const typescriptRequested = options.typescript ?? isPackageExists("typescript");
4577
+ async function moso(options = {}, ...userConfigs) {
4578
+ const { componentExts: componentExtsOption = [], isInEditor = isInEditorEnv(), jsdoc: jsdocOptions = false, jsonc: jsoncOptions = false, jsx: jsxOptions = true } = options;
4579
+ 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.");
4580
+ const mut_packageExistsCache = /* @__PURE__ */ new Map();
4581
+ const packageExists = (name) => {
4582
+ const cached = mut_packageExistsCache.get(name);
4583
+ if (cached !== void 0) return cached;
4584
+ const found = isPackageExists(name);
4585
+ mut_packageExistsCache.set(name, found);
4586
+ return found;
4587
+ };
4588
+ const anyPackageExists = (names) => names.some((x) => packageExists(x));
4589
+ const typescriptRequested = options.typescript ?? packageExists("typescript");
4554
4590
  const typescriptVersion = (typescriptRequested === false ? void 0 : await getPackageInfo("typescript"))?.version;
4555
4591
  const typescriptUnsupported = typescriptVersion !== void 0 && Number(typescriptVersion.split(".")[0]) >= 7;
4556
4592
  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`;
4593
+ 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
4594
  if (options.typescript !== void 0) throw new Error(message);
4563
4595
  console.warn(message);
4564
4596
  }
4565
4597
  const typescriptOptions = typescriptUnsupported ? false : typescriptRequested;
4566
- const astroOptions = options.astro ?? AstroPackages.some((x) => isPackageExists(x));
4567
- const nextjsOptions = options.nextjs ?? NextJSPackages.some((x) => isPackageExists(x));
4568
- const reactOptions = options.react ?? ReactPackages.some((x) => isPackageExists(x));
4569
- const tailwindOptions = options.tailwind ?? isPackageExists("tailwindcss");
4570
- const vueOptions = options.vue ?? VuePackages.some((x) => isPackageExists(x));
4571
- if (vueOptions !== false) componentExts.push("vue");
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.");
4598
+ const astroOptions = options.astro ?? anyPackageExists(AstroPackages);
4599
+ const nextjsOptions = options.nextjs ?? anyPackageExists(NextJSPackages);
4600
+ const reactOptions = options.react ?? anyPackageExists(ReactPackages);
4601
+ const tailwindOptions = options.tailwind ?? packageExists("tailwindcss");
4602
+ const vueOptions = options.vue ?? anyPackageExists(VuePackages);
4603
+ const componentExts = vueOptions === false ? [...componentExtsOption] : [.../* @__PURE__ */ new Set([...componentExtsOption, "vue"])];
4573
4604
  const baselineOptions = options.baseline === false ? false : typeof options.baseline === "object" ? options.baseline : typeof options.baseline === "string" || typeof options.baseline === "number" ? { baseline: options.baseline } : {};
4574
4605
  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 ?? "recommended" : options.functional ? "recommended" : options.functional === false || options.lessOpinionated === true ? "none" : "lite";
4606
+ 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
4607
  const hasTypeScript = Boolean(typescriptOptions);
4577
4608
  const ignoreOptions = typeof options.ignores === "object" ? options.ignores : {};
4578
4609
  const modeOptions = typeof options.mode === "string" ? options.mode : "none";
@@ -4582,7 +4613,7 @@ async function moso(options, ...userConfigs) {
4582
4613
  jsx: typeof jsxOptions === "boolean" ? jsxOptions : true,
4583
4614
  ...typeof options.stylistic === "object" && options.stylistic
4584
4615
  };
4585
- const { filesTypeAware, ignoresTypeAware, parserOptions, projectRoot: typescriptProjectRoot, useDefaultDefaultProject, ...typescriptSubOptions } = resolveSubOptions(options, "typescript");
4616
+ const { filesTypeAware, ignoresTypeAware, parserOptions, projectRoot: typescriptProjectRoot, unsafe: typescriptUnsafe, useDefaultDefaultProject, ...typescriptSubOptions } = resolveSubOptions(options, "typescript");
4586
4617
  const deprecatedProjectRoot = options.projectRoot;
4587
4618
  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
4619
  const projectRootOptions = typeof typescriptProjectRoot === "string" ? checkFilePath(typescriptProjectRoot) : typeof deprecatedProjectRoot === "string" ? checkFilePath(deprecatedProjectRoot) : void 0;
@@ -4596,7 +4627,6 @@ async function moso(options, ...userConfigs) {
4596
4627
  GLOB_TS,
4597
4628
  GLOB_TSX
4598
4629
  ];
4599
- const withRoot = (glob) => projectRootOptions === void 0 ? glob : path.join(projectRootOptions, glob);
4600
4630
  const typescriptConfigOptions = {
4601
4631
  ...typescriptSubOptions,
4602
4632
  filesTypeAware: filesTypeAware ?? defaultFilesTypesAware,
@@ -4605,13 +4635,7 @@ async function moso(options, ...userConfigs) {
4605
4635
  tsconfigRootDir: projectRootOptions,
4606
4636
  ...parserOptions,
4607
4637
  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
- ],
4638
+ allowDefaultProject: [GLOB_ROOT_JS, GLOB_ROOT_JSX],
4615
4639
  ...projectServiceUserConfig
4616
4640
  }
4617
4641
  }
@@ -4621,50 +4645,49 @@ async function moso(options, ...userConfigs) {
4621
4645
  ignoreNamePattern: ["^[mM]ut_"],
4622
4646
  ...resolveSubOptions(options, "functional")
4623
4647
  };
4624
- const mut_configs = [
4625
- comments({ overrides: getOverrides(options, "comments") }),
4626
- ignores({
4627
- ...ignoreOptions,
4628
- ...resolveSubOptions(options, "ignores")
4629
- }),
4630
- imports({
4631
- ...typescriptConfigOptions,
4632
- files: [
4633
- GLOB_DTS,
4634
- GLOB_TS,
4635
- GLOB_TSX
4636
- ],
4637
- overrides: getOverrides(options, "imports"),
4638
- stylistic: stylisticOptions,
4639
- typescript: hasTypeScript
4640
- }),
4641
- javascript({
4642
- ...functionalConfigOptions,
4643
- isInEditor,
4644
- lessOpinionated: options.lessOpinionated,
4645
- perfectionist: perfectionistOptions,
4646
- overrides: getOverrides(options, "javascript")
4647
- }),
4648
- node({
4649
- files: [GLOB_SRC],
4650
- hasReact: Boolean(reactOptions),
4651
- lessOpinionated: options.lessOpinionated,
4652
- overrides: getOverrides(options, "node"),
4653
- typescript: hasTypeScript,
4654
- ...resolveSubOptions(options, "node")
4655
- }),
4656
- promise({
4657
- lessOpinionated: options.lessOpinionated,
4658
- overrides: getOverrides(options, "promise"),
4659
- typescript: hasTypeScript
4660
- }),
4661
- regexp({ overrides: getOverrides(options, "regexp") }),
4662
- unicorn({
4663
- files: [GLOB_SRC],
4664
- lessOpinionated: options.lessOpinionated,
4665
- overrides: getOverrides(options, "unicorn")
4666
- })
4667
- ];
4648
+ const mut_configs = [];
4649
+ if (options.comments !== false) mut_configs.push(comments({ overrides: getOverrides(options, "comments") }));
4650
+ if (options.ignores !== false) mut_configs.push(ignores({
4651
+ ...ignoreOptions,
4652
+ ...resolveSubOptions(options, "ignores")
4653
+ }));
4654
+ if (options.imports !== false) mut_configs.push(imports({
4655
+ ...typescriptConfigOptions,
4656
+ files: [
4657
+ GLOB_DTS,
4658
+ GLOB_TS,
4659
+ GLOB_TSX
4660
+ ],
4661
+ overrides: getOverrides(options, "imports"),
4662
+ stylistic: stylisticOptions,
4663
+ typescript: hasTypeScript
4664
+ }));
4665
+ mut_configs.push(javascript({
4666
+ ...functionalConfigOptions,
4667
+ isInEditor,
4668
+ lessOpinionated: options.lessOpinionated,
4669
+ perfectionist: perfectionistOptions,
4670
+ overrides: getOverrides(options, "javascript")
4671
+ }));
4672
+ if (options.node !== false) mut_configs.push(node({
4673
+ files: [GLOB_SRC],
4674
+ hasReact: Boolean(reactOptions),
4675
+ lessOpinionated: options.lessOpinionated,
4676
+ overrides: getOverrides(options, "node"),
4677
+ typescript: hasTypeScript,
4678
+ ...resolveSubOptions(options, "node")
4679
+ }));
4680
+ if (options.promise !== false) mut_configs.push(promise({
4681
+ lessOpinionated: options.lessOpinionated,
4682
+ overrides: getOverrides(options, "promise"),
4683
+ typescript: hasTypeScript
4684
+ }));
4685
+ if (options.regexp !== false) mut_configs.push(regexp({ overrides: getOverrides(options, "regexp") }));
4686
+ if (options.unicorn !== false) mut_configs.push(unicorn({
4687
+ files: [GLOB_SRC],
4688
+ lessOpinionated: options.lessOpinionated,
4689
+ overrides: getOverrides(options, "unicorn")
4690
+ }));
4668
4691
  if (stylisticOptions !== false) mut_configs.push(stylistic({
4669
4692
  ...stylisticOptions,
4670
4693
  lessOpinionated: options.lessOpinionated,
@@ -4687,6 +4710,7 @@ async function moso(options, ...userConfigs) {
4687
4710
  if (astroOptions !== false) mut_configs.push(astro({
4688
4711
  ...typescriptConfigOptions,
4689
4712
  files: [GLOB_ASTRO],
4713
+ lessOpinionated: options.lessOpinionated,
4690
4714
  overrides: getOverrides(options, "astro"),
4691
4715
  stylistic: stylisticOptions,
4692
4716
  typescript: hasTypeScript,
@@ -4708,8 +4732,11 @@ async function moso(options, ...userConfigs) {
4708
4732
  }));
4709
4733
  if (jsdocOptions !== false) mut_configs.push(jsdoc({
4710
4734
  files: [GLOB_SRC],
4735
+ lessOpinionated: options.lessOpinionated,
4711
4736
  overrides: getOverrides(options, "jsdoc"),
4712
- stylistic: stylisticOptions
4737
+ stylistic: stylisticOptions,
4738
+ typescript: hasTypeScript,
4739
+ ...resolveSubOptions(options, "jsdoc")
4713
4740
  }));
4714
4741
  if (jsoncOptions !== false) mut_configs.push(jsonc({
4715
4742
  files: [
@@ -4730,18 +4757,14 @@ async function moso(options, ...userConfigs) {
4730
4757
  if (nextjsOptions !== false) mut_configs.push(nextjs({
4731
4758
  files: [GLOB_SRC],
4732
4759
  mode: modeOptions,
4733
- overrides: getOverrides(options, "nextjs")
4760
+ overrides: getOverrides(options, "nextjs"),
4761
+ ...resolveSubOptions(options, "nextjs")
4734
4762
  }));
4735
4763
  if (perfectionistOptions) mut_configs.push(perfectionist({ overrides: getOverrides(options, "perfectionist") }));
4736
4764
  if (reactOptions !== false) mut_configs.push(react({
4737
4765
  ...typescriptConfigOptions,
4738
4766
  files: [GLOB_SRC],
4739
- filesTypeAware: [
4740
- GLOB_DTS,
4741
- GLOB_JSX,
4742
- GLOB_TS,
4743
- GLOB_TSX
4744
- ],
4767
+ filesTypeAware: defaultFilesTypesAware,
4745
4768
  ignoresTypeAware: [GLOB_ASTRO_TS, `${GLOB_MARKDOWN}/**`],
4746
4769
  lessOpinionated: options.lessOpinionated,
4747
4770
  nextjs: Boolean(nextjsOptions),
@@ -4771,7 +4794,8 @@ async function moso(options, ...userConfigs) {
4771
4794
  mode: modeOptions,
4772
4795
  overrides: getOverrides(options, "typescript"),
4773
4796
  projectRoot: projectRootOptions,
4774
- unsafe: "warn"
4797
+ stylistic: stylisticOptions,
4798
+ unsafe: typescriptUnsafe ?? "warn"
4775
4799
  }));
4776
4800
  if (vueOptions !== false) mut_configs.push(vue({
4777
4801
  ...typescriptConfigOptions,
@@ -4804,7 +4828,7 @@ async function moso(options, ...userConfigs) {
4804
4828
  overrides: getOverrides(options, "yaml"),
4805
4829
  stylistic: stylisticOptions
4806
4830
  }));
4807
- mut_configs.push(disables());
4831
+ mut_configs.push(disables(functionalEnforcement !== "none"));
4808
4832
  let mut_composer = new FlatConfigComposer().append(...mut_configs, ...userConfigs);
4809
4833
  if (isInEditor) mut_composer = mut_composer.disableRulesFix([
4810
4834
  "unused-imports/no-unused-imports",
@@ -4842,7 +4866,7 @@ const full = {
4842
4866
  },
4843
4867
  test: true,
4844
4868
  toml: true,
4845
- typescript: { projectRoot: path.resolve(import.meta.dirname, "..") },
4869
+ typescript: { projectRoot: process.cwd() },
4846
4870
  unicorn: true,
4847
4871
  vue: {
4848
4872
  a11y: true,
@@ -4878,4 +4902,4 @@ const off = {
4878
4902
  yaml: false
4879
4903
  };
4880
4904
  //#endregion
4881
- export { GLOB_AI, GLOB_ALL_SRC, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CJS, GLOB_CSS, GLOB_CSS_IN_JS, GLOB_CTS, GLOB_DIST, GLOB_DTS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_LOCKFILE, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_MJS, GLOB_MTS, GLOB_NODE_MODULES, GLOB_POSTCSS, GLOB_ROOT_DTS, GLOB_ROOT_JS, GLOB_ROOT_JSX, GLOB_ROOT_TS, GLOB_ROOT_TSX, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVELTE, GLOB_SVG, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_TYPINGS, GLOB_VUE, GLOB_XML, 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 };
4905
+ 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 };