@w5s/eslint-config 3.14.0 → 3.17.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/dist/index.js CHANGED
@@ -4,9 +4,13 @@ import eslintConfig from "@eslint/js";
4
4
  import globals from "globals";
5
5
  import { eslintIgnores } from "@w5s/eslint-config-ignore";
6
6
  import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";
7
+ //#region \0rolldown/runtime.js
8
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
9
+ //#endregion
7
10
  //#region src/glob.ts
8
11
  const sourceGlob$1 = `**/${Project.extensionsToGlob(Project.sourceExtensions())}`;
9
12
  const esSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(["javascript", "javascriptreact"]))}`;
13
+ const jsxSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(["javascriptreact", "typescriptreact"]))}`;
10
14
  const jsonSourceGlob = `**/${Project.extensionsToGlob([
11
15
  ".json",
12
16
  ".json5",
@@ -60,7 +64,7 @@ const StylisticConfig = {
60
64
  };
61
65
  //#endregion
62
66
  //#region src/config/e18e.ts
63
- const defaultFiles$10 = [sourceGlob$1];
67
+ const defaultFiles$11 = [sourceGlob$1];
64
68
  /**
65
69
  * @see https://e18e.dev
66
70
  * @param options
@@ -73,7 +77,7 @@ async function e18e(options = {}) {
73
77
  name: "w5s/e18e/setup",
74
78
  plugins: { e18e: e18ePlugin }
75
79
  }, {
76
- files: withDefaultFiles(files, defaultFiles$10),
80
+ files: withDefaultFiles(files, defaultFiles$11),
77
81
  name: "w5s/e18e/rules",
78
82
  rules: {
79
83
  ...modernization ? e18ePlugin.configs.modernization.rules : {},
@@ -426,7 +430,7 @@ const esRules = () => ({
426
430
  });
427
431
  //#endregion
428
432
  //#region src/config/es.ts
429
- const defaultFiles$9 = [esSourceGlob];
433
+ const defaultFiles$10 = [esSourceGlob];
430
434
  async function es(options) {
431
435
  const { recommended = true, rules = {} } = options;
432
436
  return [{
@@ -453,7 +457,7 @@ async function es(options) {
453
457
  linterOptions: { reportUnusedDisableDirectives: true },
454
458
  name: "w5s/es/setup"
455
459
  }, {
456
- files: defaultFiles$9,
460
+ files: defaultFiles$10,
457
461
  name: "w5s/es/rules",
458
462
  rules: {
459
463
  ...recommended ? es["recommended"] : {},
@@ -573,7 +577,7 @@ async function jsdoc(options = {}) {
573
577
  }
574
578
  //#endregion
575
579
  //#region src/config/jsonc.ts
576
- const defaultFiles$8 = [jsonSourceGlob];
580
+ const defaultFiles$9 = [jsonSourceGlob];
577
581
  async function jsonc(options = {}) {
578
582
  const [jsoncPlugin, jsoncParser] = await Promise.all([interopDefault(import("eslint-plugin-jsonc")), interopDefault(import("jsonc-eslint-parser"))]);
579
583
  const { files, recommended = true, rules = {}, stylistic = true } = options;
@@ -584,7 +588,7 @@ async function jsonc(options = {}) {
584
588
  plugins: { jsonc: jsoncPlugin }
585
589
  },
586
590
  {
587
- files: withDefaultFiles(files, defaultFiles$8),
591
+ files: withDefaultFiles(files, defaultFiles$9),
588
592
  languageOptions: { parser: jsoncParser },
589
593
  name: "w5s/jsonc/rules",
590
594
  rules: {
@@ -811,12 +815,30 @@ function sortTsconfigJson() {
811
815
  };
812
816
  }
813
817
  //#endregion
818
+ //#region src/config/jsx.ts
819
+ const defaultFiles$8 = [jsxSourceGlob];
820
+ async function jsx(options = {}) {
821
+ const { files, jsxA11y = false, recommended = true, rules = {} } = options;
822
+ const [jsxA11yPlugin] = await Promise.all([jsxA11y ? interopDefault(import("eslint-plugin-jsx-a11y")) : void 0]);
823
+ return [{
824
+ languageOptions: {
825
+ parserOptions: { ecmaFeatures: { jsx: true } },
826
+ sourceType: "module"
827
+ },
828
+ name: "w5s/jsx/setup",
829
+ plugins: { ...jsxA11yPlugin ? { "jsx-a11y": jsxA11yPlugin } : {} }
830
+ }, {
831
+ files: withDefaultFiles(files, defaultFiles$8),
832
+ name: "w5s/jsx/rules",
833
+ rules: {
834
+ ...recommended && jsxA11yPlugin != null ? jsxA11yPlugin.configs["recommended"].rules : {},
835
+ ...rules
836
+ }
837
+ }];
838
+ }
839
+ //#endregion
814
840
  //#region src/config/markdown.ts
815
- const defaultFiles$7 = [
816
- `**/${Project.extensionsToGlob(Project.queryExtensions(["markdown"]))}`,
817
- "**/CHANGELOG.md",
818
- "**/CODE_OF_CONDUCT.md"
819
- ];
841
+ const defaultFiles$7 = [`**/${Project.extensionsToGlob(Project.queryExtensions(["markdown"]))}`];
820
842
  async function markdown(options = {}) {
821
843
  const [markdownPlugin] = await Promise.all([interopDefault(import("@eslint/markdown"))]);
822
844
  const { files, language = "markdown/gfm", languageOptions, recommended = true, rules = {}, stylistic = true } = options;
@@ -912,10 +934,307 @@ async function perfectionist(options = {}) {
912
934
  }
913
935
  //#endregion
914
936
  //#region src/config/react.ts
937
+ var import_dist = (/* @__PURE__ */ __commonJSMin(((exports) => {
938
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
939
+ /**
940
+ * Concat multiple flat configs into a single flat config array.
941
+ *
942
+ * It also resolves promises and flattens the result.
943
+ *
944
+ * @example
945
+ *
946
+ * ```ts
947
+ * import eslint from '@eslint/js'
948
+ *
949
+ * export default ESLintConfig.concat(
950
+ * {
951
+ * plugins: {},
952
+ * rules: {},
953
+ * },
954
+ * // It can also takes a array of configs:
955
+ * [
956
+ * {
957
+ * plugins: {},
958
+ * rules: {},
959
+ * }
960
+ * // ...
961
+ * ],
962
+ * // Or promises:
963
+ * Promise.resolve({
964
+ * files: ['*.ts'],
965
+ * rules: {},
966
+ * })
967
+ * );
968
+ * ```
969
+ * @param configs
970
+ */
971
+ async function concat(...configs) {
972
+ return (await Promise.all(configs)).flat();
973
+ }
974
+ /**
975
+ * Always return 'off'. `_status` is the previous rule value.
976
+ *
977
+ * @param _status
978
+ */
979
+ function fixme(_status) {
980
+ return "off";
981
+ }
982
+ /**
983
+ * Return a new merged flat configuration
984
+ *
985
+ * @param configs
986
+ */
987
+ function merge(...configs) {
988
+ const keys = new Set(configs.flatMap((i) => Object.keys(i)));
989
+ const merged = configs.reduce((acc, cur) => {
990
+ return {
991
+ ...acc,
992
+ ...cur,
993
+ files: [...acc.files ?? [], ...cur.files ?? []],
994
+ ignores: [...acc.ignores ?? [], ...cur.ignores ?? []],
995
+ languageOptions: {
996
+ ...acc.languageOptions,
997
+ ...cur.languageOptions
998
+ },
999
+ linterOptions: {
1000
+ ...acc.linterOptions,
1001
+ ...cur.linterOptions
1002
+ },
1003
+ plugins: {
1004
+ ...acc.plugins,
1005
+ ...cur.plugins
1006
+ },
1007
+ rules: {
1008
+ ...acc.rules,
1009
+ ...cur.rules
1010
+ }
1011
+ };
1012
+ }, {});
1013
+ for (const key of Object.keys(merged)) if (!keys.has(key)) delete merged[key];
1014
+ return merged;
1015
+ }
1016
+ /**
1017
+ * Renames rules in the given object according to the given map.
1018
+ *
1019
+ * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
1020
+ * `{ 'old-prefix/rule-name': 'error' }`, this function will return
1021
+ * `{ 'new-prefix/rule-name': 'error' }`.
1022
+ *
1023
+ * @param rules The object containing the rules to rename.
1024
+ * @param map The object containing the rename map.
1025
+ */
1026
+ function renameRules(rules, map) {
1027
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
1028
+ for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
1029
+ else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
1030
+ return [key, value];
1031
+ }));
1032
+ }
1033
+ /**
1034
+ * @namespace
1035
+ */
1036
+ const ESLintConfig = Object.freeze({
1037
+ concat,
1038
+ fixme,
1039
+ merge,
1040
+ renameRules
1041
+ });
1042
+ const getDefaultOrElse = (_) => _?.default ?? _;
1043
+ function interopDefault(m) {
1044
+ return m != null && typeof m.then === "function" ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);
1045
+ }
1046
+ const meta = Object.freeze({
1047
+ buildNumber: 1,
1048
+ name: "@w5s/dev",
1049
+ version: "3.8.0"
1050
+ });
1051
+ /**
1052
+ * Supported ECMA version
1053
+ *
1054
+ * @example
1055
+ * ```ts
1056
+ * Project.ecmaVersion() // 2022
1057
+ * ```
1058
+ */
1059
+ function ecmaVersion() {
1060
+ return 2022;
1061
+ }
1062
+ function escapeRegExp(value) {
1063
+ return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
1064
+ }
1065
+ const registry = {
1066
+ css: [".css"],
1067
+ graphql: [".gql", ".graphql"],
1068
+ javascript: [
1069
+ ".js",
1070
+ ".cjs",
1071
+ ".mjs"
1072
+ ],
1073
+ javascriptreact: [".jsx"],
1074
+ jpeg: [".jpg", ".jpeg"],
1075
+ json: [".json"],
1076
+ jsonc: [".jsonc"],
1077
+ less: [".less"],
1078
+ markdown: [
1079
+ ".markdown",
1080
+ ".mdown",
1081
+ ".mkd",
1082
+ ".md"
1083
+ ],
1084
+ sass: [".sass"],
1085
+ scss: [".scss"],
1086
+ typescript: [
1087
+ ".ts",
1088
+ ".cts",
1089
+ ".mts"
1090
+ ],
1091
+ typescriptreact: [".tsx"],
1092
+ vue: [".vue"],
1093
+ yaml: [".yaml", ".yml"]
1094
+ };
1095
+ /**
1096
+ * Return a list of extensions
1097
+ *
1098
+ * @example
1099
+ * ```ts
1100
+ * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]
1101
+ * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']
1102
+ * ```
1103
+ *
1104
+ * @param languages
1105
+ */
1106
+ function queryExtensions(languages) {
1107
+ return languages.reduce((previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []), []).sort((left, right) => left.localeCompare(right));
1108
+ }
1109
+ /**
1110
+ * Supported file extensions
1111
+ *
1112
+ * @example
1113
+ * ```ts
1114
+ * Project.sourceExtensions() // ['.ts', '.js', ...]
1115
+ * ```
1116
+ */
1117
+ function sourceExtensions() {
1118
+ return queryExtensions([
1119
+ "javascript",
1120
+ "javascriptreact",
1121
+ "typescript",
1122
+ "typescriptreact"
1123
+ ]);
1124
+ }
1125
+ const RESOURCE_EXTENSIONS = Object.freeze([
1126
+ ".gif",
1127
+ ".png",
1128
+ ".svg",
1129
+ ...queryExtensions([
1130
+ "css",
1131
+ "graphql",
1132
+ "jpeg",
1133
+ "less",
1134
+ "sass",
1135
+ "sass",
1136
+ "yaml"
1137
+ ])
1138
+ ]);
1139
+ /**
1140
+ * Resource file extensions
1141
+ *
1142
+ * @example
1143
+ * ```ts
1144
+ * Project.resourceExtensions() // ['.css', '.sass', ...]
1145
+ * ```
1146
+ */
1147
+ function resourceExtensions() {
1148
+ return RESOURCE_EXTENSIONS;
1149
+ }
1150
+ const IGNORED = Object.freeze([
1151
+ "node_modules/",
1152
+ "build/",
1153
+ "cjs/",
1154
+ "coverage/",
1155
+ "dist/",
1156
+ "dts/",
1157
+ "esm/",
1158
+ "lib/",
1159
+ "mjs/",
1160
+ "umd/"
1161
+ ]);
1162
+ /**
1163
+ * Return a RegExp that will match any list of extensions
1164
+ *
1165
+ * @param extensions
1166
+ * @example
1167
+ * ```ts
1168
+ * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
1169
+ * ```
1170
+ */
1171
+ function extensionsToMatcher(extensions) {
1172
+ return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
1173
+ }
1174
+ /**
1175
+ * Files and folders to always ignore
1176
+ *
1177
+ * @example
1178
+ * ```ts
1179
+ * IGNORED // ['node_modules/', 'build/', ...]
1180
+ * ```
1181
+ */
1182
+ function ignored() {
1183
+ return IGNORED;
1184
+ }
1185
+ const reExtension = /^\./;
1186
+ /**
1187
+ * Return a glob matcher that will match any list of extensions
1188
+ *
1189
+ * @param extensions
1190
+ * @example
1191
+ * ```ts
1192
+ * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'
1193
+ * ```
1194
+ */
1195
+ function extensionsToGlob(extensions) {
1196
+ return `*.+(${extensions.map((_) => _.replace(reExtension, "")).join("|")})`;
1197
+ }
1198
+ const Project = Object.freeze({
1199
+ ecmaVersion,
1200
+ extensionsToGlob,
1201
+ extensionsToMatcher,
1202
+ ignored,
1203
+ queryExtensions,
1204
+ resourceExtensions,
1205
+ sourceExtensions
1206
+ });
1207
+ /**
1208
+ * Project common scripts
1209
+ */
1210
+ const ProjectScript = {
1211
+ Build: "build",
1212
+ Clean: "clean",
1213
+ CodeAnalysis: "code-analysis",
1214
+ Coverage: "coverage",
1215
+ Develop: "develop",
1216
+ Docs: "docs",
1217
+ Format: "format",
1218
+ Install: "install",
1219
+ Lint: "lint",
1220
+ Prepare: "prepare",
1221
+ Release: "release",
1222
+ Rescue: "rescue",
1223
+ Spellcheck: "spellcheck",
1224
+ Test: "test",
1225
+ Typecheck: "typecheck",
1226
+ Validate: "validate"
1227
+ };
1228
+ exports.ESLintConfig = ESLintConfig;
1229
+ exports.Project = Project;
1230
+ exports.ProjectScript = ProjectScript;
1231
+ exports.interopDefault = interopDefault;
1232
+ exports.meta = meta;
1233
+ })))();
915
1234
  const defaultFiles$4 = [sourceGlob$1];
916
1235
  async function react(options = {}) {
917
1236
  const [reactPlugin] = await Promise.all([interopDefault(import("@eslint-react/eslint-plugin"))]);
918
- const { files, recommended, rules = {} } = options;
1237
+ const { files, recommended = true, rules = {} } = options;
919
1238
  return [{
920
1239
  name: "w5s/react/setup",
921
1240
  plugins: { react: reactPlugin }
@@ -927,7 +1246,7 @@ async function react(options = {}) {
927
1246
  },
928
1247
  name: "w5s/react/rules",
929
1248
  rules: {
930
- ...recommended ? reactPlugin.configs["recommended"].rules : {},
1249
+ ...recommended ? import_dist.ESLintConfig.renameRules(reactPlugin.configs["recommended"].rules, { "@eslint-react": "react" }) : {},
931
1250
  ...rules
932
1251
  }
933
1252
  }];
@@ -1148,6 +1467,33 @@ async function unicorn(options = {}) {
1148
1467
  ];
1149
1468
  }
1150
1469
  //#endregion
1470
+ //#region src/config/unused-imports.ts
1471
+ async function unusedImports(options = {}) {
1472
+ const [unusedImportPlugin] = await Promise.all([interopDefault(import("eslint-plugin-unused-imports"))]);
1473
+ const { files = [sourceGlob$1], recommended = true, rules = {} } = options;
1474
+ return [{
1475
+ name: "w5s/unused-imports/setup",
1476
+ plugins: { "unused-imports": unusedImportPlugin }
1477
+ }, {
1478
+ files,
1479
+ name: "w5s/unused-imports/rules",
1480
+ rules: {
1481
+ ...recommended ? {
1482
+ "no-unused-vars": "off",
1483
+ "ts/no-unused-vars": "off",
1484
+ "unused-imports/no-unused-imports": "error",
1485
+ "unused-imports/no-unused-vars": ["error", {
1486
+ args: "after-used",
1487
+ argsIgnorePattern: "^_",
1488
+ vars: "all",
1489
+ varsIgnorePattern: "^_"
1490
+ }]
1491
+ } : {},
1492
+ ...rules
1493
+ }
1494
+ }];
1495
+ }
1496
+ //#endregion
1151
1497
  //#region src/config/yml.ts
1152
1498
  const defaultFiles = [ymlSourceGlob];
1153
1499
  async function yml(options = {}) {
@@ -1207,16 +1553,16 @@ async function defineConfig(options = {}) {
1207
1553
  ...optionsOrBoolean
1208
1554
  });
1209
1555
  const includeEnabled = (factory, input) => input.enabled ? [factory(input)] : [];
1210
- return ESLintConfig.concat(...includeEnabled(e18e, toOption(plugins.e18e)), ...includeEnabled(es, toOption(plugins.es)), ...includeEnabled(ts, toOption(plugins.ts)), ...includeEnabled(ignores, toOption(options)), ...includeEnabled(jsonc, toOption(plugins.jsonc)), ...includeEnabled(jsdoc, toOption(plugins.jsdoc)), ...includeEnabled(react, toOption(plugins.react)), ...includeEnabled(stylistic, toOption(plugins.stylistic)), ...includeEnabled(imports, toOption(plugins.import)), ...includeEnabled(markdown, toOption(plugins.markdown)), ...includeEnabled(next, toOption(plugins.next, false)), ...includeEnabled(node, toOption(plugins.node)), ...includeEnabled(perfectionist, toOption(plugins.perfectionist)), ...includeEnabled(unicorn, toOption(plugins.unicorn)), ...includeEnabled(yml, toOption(plugins.yml)), ...includeEnabled(test, toOption(plugins.test)), ...rules ? [{ rules }] : []);
1556
+ return ESLintConfig.concat(...includeEnabled(e18e, toOption(plugins.e18e)), ...includeEnabled(es, toOption(plugins.es)), ...includeEnabled(ts, toOption(plugins.ts)), ...includeEnabled(ignores, toOption(options)), ...includeEnabled(jsonc, toOption(plugins.jsonc)), ...includeEnabled(jsdoc, toOption(plugins.jsdoc)), ...includeEnabled(jsx, toOption(plugins.jsx)), ...includeEnabled(react, toOption(plugins.react)), ...includeEnabled(stylistic, toOption(plugins.stylistic)), ...includeEnabled(imports, toOption(plugins.import)), ...includeEnabled(markdown, toOption(plugins.markdown)), ...includeEnabled(next, toOption(plugins.next, false)), ...includeEnabled(node, toOption(plugins.node)), ...includeEnabled(perfectionist, toOption(plugins.perfectionist)), ...includeEnabled(unicorn, toOption(plugins.unicorn)), ...includeEnabled(yml, toOption(plugins.yml)), ...includeEnabled(test, toOption(plugins.test)), ...includeEnabled(unusedImports, toOption(plugins["unused-imports"])), ...rules ? [{ rules }] : []);
1211
1557
  }
1212
1558
  //#endregion
1213
1559
  //#region src/meta.ts
1214
1560
  const meta = Object.freeze({
1215
1561
  buildNumber: 1,
1216
1562
  name: "@w5s/eslint-config",
1217
- version: "3.14.0"
1563
+ version: "3.17.0"
1218
1564
  });
1219
1565
  //#endregion
1220
- export { StylisticConfig, defineConfig as default, defineConfig, e18e, es, ignores, imports, jsdoc, jsonc, markdown, meta, next, node, perfectionist, react, stylistic, test, ts, unicorn, yml };
1566
+ export { StylisticConfig, defineConfig as default, defineConfig, e18e, es, ignores, imports, jsdoc, jsonc, jsx, markdown, meta, next, node, perfectionist, react, stylistic, test, ts, unicorn, unusedImports, yml };
1221
1567
 
1222
1568
  //# sourceMappingURL=index.js.map