@w5s/eslint-config 3.6.0 → 3.7.1

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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ESLintConfig, Project, interopDefault } from "@w5s/dev";
2
+ import prettierConfig from "@w5s/prettier-config";
2
3
  import globals from "globals";
3
4
  import eslintConfig from "@eslint/js";
4
- import prettierConfig from "@w5s/prettier-config";
5
5
  import { eslintIgnores } from "@w5s/eslint-config-ignore";
6
6
  import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";
7
7
  //#region src/type/StylisticConfig.ts
@@ -36,6 +36,48 @@ const StylisticConfig = {
36
36
  }
37
37
  };
38
38
  //#endregion
39
+ //#region src/glob.ts
40
+ const sourceGlob$1 = `**/${Project.extensionsToGlob(Project.sourceExtensions())}`;
41
+ const esSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(["javascript", "javascriptreact"]))}`;
42
+ const jsonSourceGlob = `**/${Project.extensionsToGlob([
43
+ ".json",
44
+ ".json5",
45
+ ".jsonc"
46
+ ])}`;
47
+ const tsSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(["typescript", "typescriptreact"]))}`;
48
+ const ymlSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(["yaml"]))}`;
49
+ //#endregion
50
+ //#region src/config/e18e.ts
51
+ const defaultFiles$9 = [sourceGlob$1];
52
+ /**
53
+ * @see https://e18e.dev
54
+ * @param options
55
+ */
56
+ async function e18e(options = {}) {
57
+ const [e18ePlugin] = await Promise.all([interopDefault(import("@e18e/eslint-plugin"))]);
58
+ const { files = defaultFiles$9, rules = {}, stylistic = true, modernization = true, moduleReplacements = false, performanceImprovements = true } = options;
59
+ const { enabled: stylisticEnabled } = StylisticConfig.from(stylistic);
60
+ return [{
61
+ name: "w5s/e18e/setup",
62
+ plugins: { e18e: e18ePlugin }
63
+ }, {
64
+ name: "w5s/e18e/rules",
65
+ files,
66
+ rules: {
67
+ ...modernization ? e18ePlugin.configs.modernization.rules : {},
68
+ ...moduleReplacements ? e18ePlugin.configs.moduleReplacements.rules : {},
69
+ ...performanceImprovements ? e18ePlugin.configs.performanceImprovements.rules : {},
70
+ "e18e/prefer-array-from-map": "off",
71
+ "e18e/prefer-array-to-reversed": "off",
72
+ "e18e/prefer-array-to-sorted": "off",
73
+ "e18e/prefer-array-to-spliced": "off",
74
+ "e18e/prefer-spread-syntax": "off",
75
+ ...stylisticEnabled ? {} : {},
76
+ ...rules
77
+ }
78
+ }];
79
+ }
80
+ //#endregion
39
81
  //#region src/rules/esRules/bestPractices.ts
40
82
  const bestPractices = () => ({
41
83
  "accessor-pairs": "off",
@@ -439,21 +481,10 @@ const esRules = () => ({
439
481
  ...overrides()
440
482
  });
441
483
  //#endregion
442
- //#region src/glob.ts
443
- const sourceGlob$1 = `**/${Project.extensionsToGlob(Project.sourceExtensions())}`;
444
- const esSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(["javascript", "javascriptreact"]))}`;
445
- const jsonSourceGlob = `**/${Project.extensionsToGlob([
446
- ".json",
447
- ".json5",
448
- ".jsonc"
449
- ])}`;
450
- const tsSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(["typescript", "typescriptreact"]))}`;
451
- const ymlSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(["yaml"]))}`;
452
- //#endregion
453
484
  //#region src/config/es.ts
454
- const defaultFiles$7 = [esSourceGlob];
485
+ const defaultFiles$8 = [esSourceGlob];
455
486
  async function es(options) {
456
- const { rules = {} } = options;
487
+ const { recommended = true, rules = {} } = options;
457
488
  return [{
458
489
  name: "w5s/es/setup",
459
490
  languageOptions: {
@@ -479,14 +510,20 @@ async function es(options) {
479
510
  linterOptions: { reportUnusedDisableDirectives: true }
480
511
  }, {
481
512
  name: "w5s/es/rules",
482
- files: defaultFiles$7,
513
+ files: defaultFiles$8,
483
514
  rules: {
484
- ...eslintConfig.configs.recommended.rules,
485
- ...esRules(),
515
+ ...recommended ? es["recommended"] : {},
486
516
  ...rules
487
517
  }
488
518
  }];
489
519
  }
520
+ /**
521
+ * Recommended rules
522
+ */
523
+ es["recommended"] = {
524
+ ...eslintConfig.configs.recommended.rules,
525
+ ...esRules()
526
+ };
490
527
  //#endregion
491
528
  //#region src/config/ignores.ts
492
529
  async function ignores(options = {}) {
@@ -494,10 +531,10 @@ async function ignores(options = {}) {
494
531
  }
495
532
  //#endregion
496
533
  //#region src/config/jsdoc.ts
497
- const defaultFiles$6 = [sourceGlob$1];
534
+ const defaultFiles$7 = [sourceGlob$1];
498
535
  async function jsdoc(options = {}) {
499
536
  const [jsdocPlugin] = await Promise.all([interopDefault(import("eslint-plugin-jsdoc"))]);
500
- const { files = defaultFiles$6, rules = {}, stylistic = true } = options;
537
+ const { files = defaultFiles$7, recommended = true, rules = {}, stylistic = true } = options;
501
538
  const { enabled: stylisticEnabled } = StylisticConfig.from(stylistic);
502
539
  return [{
503
540
  name: "w5s/jsdoc/setup",
@@ -506,14 +543,16 @@ async function jsdoc(options = {}) {
506
543
  name: "w5s/jsdoc/rules",
507
544
  files,
508
545
  rules: {
509
- ...jsdocPlugin.configs["flat/recommended-typescript-flavor"].rules,
510
- "jsdoc/no-undefined-types": "off",
511
- "jsdoc/require-hyphen-before-param-description": ["warn", "always"],
512
- "jsdoc/require-jsdoc": "off",
513
- "jsdoc/require-param-description": "off",
514
- "jsdoc/require-param-type": "off",
515
- "jsdoc/require-returns": "off",
516
- "jsdoc/valid-types": "off",
546
+ ...recommended ? jsdocPlugin.configs["flat/recommended-typescript-flavor"].rules : {},
547
+ ...recommended ? {
548
+ "jsdoc/no-undefined-types": "off",
549
+ "jsdoc/require-hyphen-before-param-description": ["warn", "always"],
550
+ "jsdoc/require-jsdoc": "off",
551
+ "jsdoc/require-param-description": "off",
552
+ "jsdoc/require-param-type": "off",
553
+ "jsdoc/require-returns": "off",
554
+ "jsdoc/valid-types": "off"
555
+ } : {},
517
556
  ...stylisticEnabled ? {
518
557
  ...jsdocPlugin.configs["flat/stylistic-typescript"].rules,
519
558
  "jsdoc/check-alignment": "warn",
@@ -531,10 +570,10 @@ async function jsdoc(options = {}) {
531
570
  }
532
571
  //#endregion
533
572
  //#region src/config/jsonc.ts
534
- const defaultFiles$5 = [jsonSourceGlob];
573
+ const defaultFiles$6 = [jsonSourceGlob];
535
574
  async function jsonc(options = {}) {
536
575
  const [jsoncPlugin, jsoncParser] = await Promise.all([interopDefault(import("eslint-plugin-jsonc")), interopDefault(import("jsonc-eslint-parser"))]);
537
- const { files = defaultFiles$5, rules = {}, stylistic = true } = options;
576
+ const { files = defaultFiles$6, recommended = true, rules = {}, stylistic = true } = options;
538
577
  const { enabled: stylisticEnabled, indent } = StylisticConfig.from(stylistic);
539
578
  return [
540
579
  {
@@ -546,7 +585,7 @@ async function jsonc(options = {}) {
546
585
  languageOptions: { parser: jsoncParser },
547
586
  name: "w5s/jsonc/rules",
548
587
  rules: {
549
- ...jsoncPlugin.configs["flat/recommended-with-json"][0]?.rules,
588
+ ...recommended ? jsoncPlugin.configs["flat/recommended-with-json"][0]?.rules : {},
550
589
  ...stylisticEnabled ? {
551
590
  "jsonc/array-bracket-spacing": ["error", "never"],
552
591
  "jsonc/comma-dangle": ["error", "never"],
@@ -771,28 +810,38 @@ function sortPackageJson() {
771
810
  //#endregion
772
811
  //#region src/config/imports.ts
773
812
  async function imports(options = {}) {
774
- const { rules = {}, stylistic = true } = options;
813
+ const { rules = {}, recommended = true, stylistic = true } = options;
775
814
  const { enabled: stylisticEnabled } = StylisticConfig.from(stylistic);
776
815
  const [importPlugin] = await Promise.all([interopDefault(import("eslint-plugin-import"))]);
777
816
  return [{
778
817
  name: "w5s/import/rules",
779
818
  plugins: { import: importPlugin },
780
819
  rules: {
781
- "import/first": "error",
782
- "import/no-duplicates": "error",
783
- "import/no-mutable-exports": "error",
784
- "import/no-named-default": "error",
785
- ...stylisticEnabled ? { "import/newline-after-import": ["error", { count: 1 }] } : {},
820
+ ...recommended ? imports["recommended"] : {},
821
+ ...stylisticEnabled ? imports["stylistic"] : {},
786
822
  ...rules
787
823
  }
788
824
  }];
789
825
  }
826
+ /**
827
+ * Recommended rules
828
+ */
829
+ imports["recommended"] = {
830
+ "import/first": "error",
831
+ "import/no-duplicates": "error",
832
+ "import/no-mutable-exports": "error",
833
+ "import/no-named-default": "error"
834
+ };
835
+ /**
836
+ * Stylistic rules
837
+ */
838
+ imports["stylistic"] = { "import/newline-after-import": ["error", { count: 1 }] };
790
839
  //#endregion
791
840
  //#region src/config/markdown.ts
792
- const defaultFiles$4 = [`**/${Project.extensionsToGlob(Project.queryExtensions(["markdown"]))}`];
841
+ const defaultFiles$5 = [`**/${Project.extensionsToGlob(Project.queryExtensions(["markdown"]))}`];
793
842
  async function markdown(options = {}) {
794
843
  const [markdownPlugin] = await Promise.all([interopDefault(import("@eslint/markdown"))]);
795
- const { language = "markdown/gfm", files = defaultFiles$4, rules = {}, stylistic = true } = options;
844
+ const { language = "markdown/gfm", files = defaultFiles$5, recommended = true, rules = {}, stylistic = true } = options;
796
845
  const { enabled: stylisticEnabled } = StylisticConfig.from(stylistic);
797
846
  return [{
798
847
  name: "w5s/markdown/setup",
@@ -803,32 +852,58 @@ async function markdown(options = {}) {
803
852
  name: "w5s/markdown/rules",
804
853
  processor: mergeProcessors([markdownPlugin.processors.markdown, processorPassThrough]),
805
854
  rules: {
806
- ...markdownPlugin.configs.recommended.at(0)?.rules,
855
+ ...recommended ? markdownPlugin.configs.recommended.at(0)?.rules : {},
807
856
  ...stylisticEnabled ? {} : {},
808
857
  ...rules
809
858
  }
810
859
  }];
811
860
  }
812
861
  //#endregion
862
+ //#region src/config/next.ts
863
+ const defaultFiles$4 = [sourceGlob$1];
864
+ async function next(options = {}) {
865
+ const [nextPlugin] = await Promise.all([interopDefault(import("@next/eslint-plugin-next"))]);
866
+ const { files = defaultFiles$4, recommended = true, rules = {} } = options;
867
+ return [{
868
+ name: "w5s/next/setup",
869
+ plugins: { next: nextPlugin }
870
+ }, {
871
+ name: "w5s/next/rules",
872
+ files,
873
+ languageOptions: {
874
+ parserOptions: { ecmaFeatures: { jsx: true } },
875
+ sourceType: "module"
876
+ },
877
+ settings: { react: { version: "detect" } },
878
+ rules: {
879
+ ...recommended ? ESLintConfig.renameRules(nextPlugin.configs.recommended.rules ?? {}, { "@next/next": "next" }) : {},
880
+ ...recommended ? ESLintConfig.renameRules(nextPlugin.configs["core-web-vitals"].rules ?? {}, { "@next/next": "next" }) : {},
881
+ ...rules
882
+ }
883
+ }];
884
+ }
885
+ //#endregion
813
886
  //#region src/config/node.ts
814
887
  async function node(options = {}) {
815
888
  const [nodePlugin] = await Promise.all([interopDefault(import("eslint-plugin-n"))]);
816
- const { rules = {} } = options;
889
+ const { recommended, rules = {} } = options;
817
890
  return [{
818
891
  name: "w5s/node/setup",
819
892
  plugins: { node: nodePlugin }
820
893
  }, {
821
894
  name: "w5s/node/rules",
822
895
  rules: {
823
- "node/no-deprecated-api": "error",
824
- "node/no-exports-assign": "error",
825
- "node/no-new-require": "error",
826
- "node/no-path-concat": "error",
827
- "node/prefer-global/buffer": ["error", "never"],
828
- "node/prefer-global/console": ["error", "always"],
829
- "node/prefer-global/url": ["error", "always"],
830
- "node/prefer-global/url-search-params": ["error", "always"],
831
- "node/process-exit-as-throw": "error",
896
+ ...recommended ? {
897
+ "node/no-deprecated-api": "error",
898
+ "node/no-exports-assign": "error",
899
+ "node/no-new-require": "error",
900
+ "node/no-path-concat": "error",
901
+ "node/prefer-global/buffer": ["error", "never"],
902
+ "node/prefer-global/console": ["error", "always"],
903
+ "node/prefer-global/url": ["error", "always"],
904
+ "node/prefer-global/url-search-params": ["error", "always"],
905
+ "node/process-exit-as-throw": "error"
906
+ } : {},
832
907
  ...rules
833
908
  }
834
909
  }];
@@ -889,7 +964,7 @@ const defaultFiles$3 = [
889
964
  ];
890
965
  async function test(options = {}) {
891
966
  const [vitestPlugin] = await Promise.all([interopDefault(import("@vitest/eslint-plugin"))]);
892
- const { files = defaultFiles$3, rules = {}, stylistic = true } = options;
967
+ const { files = defaultFiles$3, recommended = true, rules = {}, stylistic = true } = options;
893
968
  const { enabled: stylisticEnabled } = StylisticConfig.from(stylistic);
894
969
  return [{
895
970
  name: "w5s/test/setup",
@@ -898,7 +973,9 @@ async function test(options = {}) {
898
973
  files,
899
974
  name: "w5s/test/rules",
900
975
  rules: {
901
- ...vitestPlugin.configs.recommended.rules,
976
+ ...recommended ? ESLintConfig.renameRules(vitestPlugin.configs.recommended.rules, { vitest: "test" }) : {},
977
+ "test/valid-title": ESLintConfig.fixme(void 0),
978
+ "e18e/prefer-static-regex": "off",
902
979
  ...stylisticEnabled ? {} : {},
903
980
  ...rules
904
981
  }
@@ -1011,7 +1088,7 @@ async function ts(options = {}) {
1011
1088
  const defaultFiles$1 = [sourceGlob$1];
1012
1089
  async function unicorn(options = {}) {
1013
1090
  const [unicornPlugin] = await Promise.all([interopDefault(import("eslint-plugin-unicorn"))]);
1014
- const { files = defaultFiles$1, rules = {}, stylistic = true } = options;
1091
+ const { files = defaultFiles$1, recommended = true, rules = {}, stylistic = true } = options;
1015
1092
  const { enabled: stylisticEnabled } = StylisticConfig.from(stylistic);
1016
1093
  return [
1017
1094
  {
@@ -1022,7 +1099,7 @@ async function unicorn(options = {}) {
1022
1099
  name: "w5s/unicorn/rules",
1023
1100
  files,
1024
1101
  rules: {
1025
- ...unicornPlugin.configs.recommended?.rules,
1102
+ ...recommended ? unicornPlugin.configs.recommended?.rules : {},
1026
1103
  "unicorn/consistent-destructuring": "off",
1027
1104
  "unicorn/consistent-function-scoping": "off",
1028
1105
  "unicorn/filename-case": "off",
@@ -1039,7 +1116,6 @@ async function unicorn(options = {}) {
1039
1116
  "unicorn/no-object-as-default-parameter": "off",
1040
1117
  "unicorn/no-process-exit": "off",
1041
1118
  "unicorn/no-unreadable-array-destructuring": "off",
1042
- "unicorn/no-unused-properties": "warn",
1043
1119
  "unicorn/no-useless-undefined": "off",
1044
1120
  "unicorn/prefer-add-event-listener": "off",
1045
1121
  "unicorn/prefer-default-parameters": "off",
@@ -1062,7 +1138,7 @@ async function unicorn(options = {}) {
1062
1138
  const defaultFiles = [ymlSourceGlob];
1063
1139
  async function yml(options = {}) {
1064
1140
  const [ymlPlugin] = await Promise.all([interopDefault(import("eslint-plugin-yml"))]);
1065
- const { files = defaultFiles, rules = {}, stylistic = true } = options;
1141
+ const { files = defaultFiles, recommended = true, rules = {}, stylistic = true } = options;
1066
1142
  const { enabled: stylisticEnabled, indent, quotes } = StylisticConfig.from(stylistic);
1067
1143
  return [{
1068
1144
  name: "w5s/yml/setup",
@@ -1072,10 +1148,10 @@ async function yml(options = {}) {
1072
1148
  language: "yml/yaml",
1073
1149
  name: "w5s/yml/rules",
1074
1150
  rules: {
1075
- ...ymlPlugin.configs["recommended"].reduce((acc, config) => ({
1151
+ ...recommended ? ymlPlugin.configs["recommended"].reduce((acc, config) => ({
1076
1152
  ...acc,
1077
1153
  ...config.rules
1078
- }), {}),
1154
+ }), {}) : {},
1079
1155
  ...stylisticEnabled ? {
1080
1156
  "style/spaced-comment": "off",
1081
1157
  "yml/block-mapping-question-indicator-newline": "error",
@@ -1115,40 +1191,17 @@ async function defineConfig(options = {}) {
1115
1191
  enabled: true,
1116
1192
  ...optionsOrBoolean
1117
1193
  });
1118
- const esOptions = toOption(options.es);
1119
- const importOptions = toOption(options.import);
1120
- const jsdocOptions = toOption(options.jsdoc);
1121
- const jsoncOptions = toOption(options.jsonc);
1122
- const markdownOptions = toOption(options.markdown);
1123
- const nodeOptions = toOption(options.node);
1124
- const tsOptions = toOption(options.ts);
1125
- const unicornOptions = toOption(options.unicorn);
1126
- const ymlOptions = toOption(options.yml);
1127
- const returnValue = [];
1128
- const append = (config) => {
1129
- returnValue.push(config);
1130
- };
1131
- append(es(esOptions));
1132
- append(ignores(options));
1133
- if (jsoncOptions.enabled) append(jsonc(jsoncOptions));
1134
- if (jsdocOptions.enabled) append(jsdoc(jsdocOptions));
1135
- if (stylisticOptions.enabled) append(stylistic(stylisticOptions));
1136
- if (importOptions.enabled) append(imports(importOptions));
1137
- if (markdownOptions.enabled) append(markdown(markdownOptions));
1138
- if (nodeOptions.enabled) append(node(nodeOptions));
1139
- if (tsOptions.enabled) append(ts(tsOptions));
1140
- if (ymlOptions.enabled) append(yml(ymlOptions));
1141
- if (unicornOptions.enabled) append(unicorn(unicornOptions));
1142
- return ESLintConfig.concat(...returnValue);
1194
+ const includeEnabled = (factory, input) => input.enabled ? [factory(input)] : [];
1195
+ return ESLintConfig.concat(...includeEnabled(e18e, toOption(options.e18e)), ...includeEnabled(es, toOption(options.es)), ...includeEnabled(ts, toOption(options.ts)), ...includeEnabled(ignores, toOption(options)), ...includeEnabled(jsonc, toOption(options.jsonc)), ...includeEnabled(jsdoc, toOption(options.jsdoc)), ...includeEnabled(stylistic, toOption(options.stylistic)), ...includeEnabled(imports, toOption(options.import)), ...includeEnabled(markdown, toOption(options.markdown)), ...includeEnabled(next, toOption(options.next)), ...includeEnabled(node, toOption(options.node)), ...includeEnabled(unicorn, toOption(options.unicorn)), ...includeEnabled(yml, toOption(options.yml)), ...includeEnabled(test, toOption(options.test)));
1143
1196
  }
1144
1197
  //#endregion
1145
1198
  //#region src/meta.ts
1146
1199
  const meta = Object.freeze({
1147
1200
  name: "@w5s/eslint-config",
1148
- version: "3.6.0",
1201
+ version: "3.7.1",
1149
1202
  buildNumber: 1
1150
1203
  });
1151
1204
  //#endregion
1152
- export { StylisticConfig, defineConfig as default, defineConfig, es, ignores, imports, jsdoc, jsonc, markdown, meta, node, stylistic, test, ts, unicorn, yml };
1205
+ export { StylisticConfig, defineConfig as default, defineConfig, e18e, es, ignores, imports, jsdoc, jsonc, markdown, meta, next, node, stylistic, test, ts, unicorn, yml };
1153
1206
 
1154
1207
  //# sourceMappingURL=index.js.map