@w5s/eslint-config 3.14.0 → 3.16.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,6 +815,28 @@ 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
841
  const defaultFiles$7 = [
816
842
  `**/${Project.extensionsToGlob(Project.queryExtensions(["markdown"]))}`,
@@ -912,10 +938,307 @@ async function perfectionist(options = {}) {
912
938
  }
913
939
  //#endregion
914
940
  //#region src/config/react.ts
941
+ var import_dist = (/* @__PURE__ */ __commonJSMin(((exports) => {
942
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
943
+ /**
944
+ * Concat multiple flat configs into a single flat config array.
945
+ *
946
+ * It also resolves promises and flattens the result.
947
+ *
948
+ * @example
949
+ *
950
+ * ```ts
951
+ * import eslint from '@eslint/js'
952
+ *
953
+ * export default ESLintConfig.concat(
954
+ * {
955
+ * plugins: {},
956
+ * rules: {},
957
+ * },
958
+ * // It can also takes a array of configs:
959
+ * [
960
+ * {
961
+ * plugins: {},
962
+ * rules: {},
963
+ * }
964
+ * // ...
965
+ * ],
966
+ * // Or promises:
967
+ * Promise.resolve({
968
+ * files: ['*.ts'],
969
+ * rules: {},
970
+ * })
971
+ * );
972
+ * ```
973
+ * @param configs
974
+ */
975
+ async function concat(...configs) {
976
+ return (await Promise.all(configs)).flat();
977
+ }
978
+ /**
979
+ * Always return 'off'. `_status` is the previous rule value.
980
+ *
981
+ * @param _status
982
+ */
983
+ function fixme(_status) {
984
+ return "off";
985
+ }
986
+ /**
987
+ * Return a new merged flat configuration
988
+ *
989
+ * @param configs
990
+ */
991
+ function merge(...configs) {
992
+ const keys = new Set(configs.flatMap((i) => Object.keys(i)));
993
+ const merged = configs.reduce((acc, cur) => {
994
+ return {
995
+ ...acc,
996
+ ...cur,
997
+ files: [...acc.files ?? [], ...cur.files ?? []],
998
+ ignores: [...acc.ignores ?? [], ...cur.ignores ?? []],
999
+ languageOptions: {
1000
+ ...acc.languageOptions,
1001
+ ...cur.languageOptions
1002
+ },
1003
+ linterOptions: {
1004
+ ...acc.linterOptions,
1005
+ ...cur.linterOptions
1006
+ },
1007
+ plugins: {
1008
+ ...acc.plugins,
1009
+ ...cur.plugins
1010
+ },
1011
+ rules: {
1012
+ ...acc.rules,
1013
+ ...cur.rules
1014
+ }
1015
+ };
1016
+ }, {});
1017
+ for (const key of Object.keys(merged)) if (!keys.has(key)) delete merged[key];
1018
+ return merged;
1019
+ }
1020
+ /**
1021
+ * Renames rules in the given object according to the given map.
1022
+ *
1023
+ * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
1024
+ * `{ 'old-prefix/rule-name': 'error' }`, this function will return
1025
+ * `{ 'new-prefix/rule-name': 'error' }`.
1026
+ *
1027
+ * @param rules The object containing the rules to rename.
1028
+ * @param map The object containing the rename map.
1029
+ */
1030
+ function renameRules(rules, map) {
1031
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
1032
+ for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
1033
+ else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
1034
+ return [key, value];
1035
+ }));
1036
+ }
1037
+ /**
1038
+ * @namespace
1039
+ */
1040
+ const ESLintConfig = Object.freeze({
1041
+ concat,
1042
+ fixme,
1043
+ merge,
1044
+ renameRules
1045
+ });
1046
+ const getDefaultOrElse = (_) => _?.default ?? _;
1047
+ function interopDefault(m) {
1048
+ return m != null && typeof m.then === "function" ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);
1049
+ }
1050
+ const meta = Object.freeze({
1051
+ buildNumber: 1,
1052
+ name: "@w5s/dev",
1053
+ version: "3.7.0"
1054
+ });
1055
+ /**
1056
+ * Supported ECMA version
1057
+ *
1058
+ * @example
1059
+ * ```ts
1060
+ * Project.ecmaVersion() // 2022
1061
+ * ```
1062
+ */
1063
+ function ecmaVersion() {
1064
+ return 2022;
1065
+ }
1066
+ function escapeRegExp(value) {
1067
+ return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
1068
+ }
1069
+ const registry = {
1070
+ css: [".css"],
1071
+ graphql: [".gql", ".graphql"],
1072
+ javascript: [
1073
+ ".js",
1074
+ ".cjs",
1075
+ ".mjs"
1076
+ ],
1077
+ javascriptreact: [".jsx"],
1078
+ jpeg: [".jpg", ".jpeg"],
1079
+ json: [".json"],
1080
+ jsonc: [".jsonc"],
1081
+ less: [".less"],
1082
+ markdown: [
1083
+ ".markdown",
1084
+ ".mdown",
1085
+ ".mkd",
1086
+ ".md"
1087
+ ],
1088
+ sass: [".sass"],
1089
+ scss: [".scss"],
1090
+ typescript: [
1091
+ ".ts",
1092
+ ".cts",
1093
+ ".mts"
1094
+ ],
1095
+ typescriptreact: [".tsx"],
1096
+ vue: [".vue"],
1097
+ yaml: [".yaml", ".yml"]
1098
+ };
1099
+ /**
1100
+ * Return a list of extensions
1101
+ *
1102
+ * @example
1103
+ * ```ts
1104
+ * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]
1105
+ * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']
1106
+ * ```
1107
+ *
1108
+ * @param languages
1109
+ */
1110
+ function queryExtensions(languages) {
1111
+ return languages.reduce((previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []), []).sort((left, right) => left.localeCompare(right));
1112
+ }
1113
+ /**
1114
+ * Supported file extensions
1115
+ *
1116
+ * @example
1117
+ * ```ts
1118
+ * Project.sourceExtensions() // ['.ts', '.js', ...]
1119
+ * ```
1120
+ */
1121
+ function sourceExtensions() {
1122
+ return queryExtensions([
1123
+ "javascript",
1124
+ "javascriptreact",
1125
+ "typescript",
1126
+ "typescriptreact"
1127
+ ]);
1128
+ }
1129
+ const RESOURCE_EXTENSIONS = Object.freeze([
1130
+ ".gif",
1131
+ ".png",
1132
+ ".svg",
1133
+ ...queryExtensions([
1134
+ "css",
1135
+ "graphql",
1136
+ "jpeg",
1137
+ "less",
1138
+ "sass",
1139
+ "sass",
1140
+ "yaml"
1141
+ ])
1142
+ ]);
1143
+ /**
1144
+ * Resource file extensions
1145
+ *
1146
+ * @example
1147
+ * ```ts
1148
+ * Project.resourceExtensions() // ['.css', '.sass', ...]
1149
+ * ```
1150
+ */
1151
+ function resourceExtensions() {
1152
+ return RESOURCE_EXTENSIONS;
1153
+ }
1154
+ const IGNORED = Object.freeze([
1155
+ "node_modules/",
1156
+ "build/",
1157
+ "cjs/",
1158
+ "coverage/",
1159
+ "dist/",
1160
+ "dts/",
1161
+ "esm/",
1162
+ "lib/",
1163
+ "mjs/",
1164
+ "umd/"
1165
+ ]);
1166
+ /**
1167
+ * Return a RegExp that will match any list of extensions
1168
+ *
1169
+ * @param extensions
1170
+ * @example
1171
+ * ```ts
1172
+ * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
1173
+ * ```
1174
+ */
1175
+ function extensionsToMatcher(extensions) {
1176
+ return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
1177
+ }
1178
+ /**
1179
+ * Files and folders to always ignore
1180
+ *
1181
+ * @example
1182
+ * ```ts
1183
+ * IGNORED // ['node_modules/', 'build/', ...]
1184
+ * ```
1185
+ */
1186
+ function ignored() {
1187
+ return IGNORED;
1188
+ }
1189
+ const reExtension = /^\./;
1190
+ /**
1191
+ * Return a glob matcher that will match any list of extensions
1192
+ *
1193
+ * @param extensions
1194
+ * @example
1195
+ * ```ts
1196
+ * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'
1197
+ * ```
1198
+ */
1199
+ function extensionsToGlob(extensions) {
1200
+ return `*.+(${extensions.map((_) => _.replace(reExtension, "")).join("|")})`;
1201
+ }
1202
+ const Project = Object.freeze({
1203
+ ecmaVersion,
1204
+ extensionsToGlob,
1205
+ extensionsToMatcher,
1206
+ ignored,
1207
+ queryExtensions,
1208
+ resourceExtensions,
1209
+ sourceExtensions
1210
+ });
1211
+ /**
1212
+ * Project common scripts
1213
+ */
1214
+ const ProjectScript = {
1215
+ Build: "build",
1216
+ Clean: "clean",
1217
+ CodeAnalysis: "code-analysis",
1218
+ Coverage: "coverage",
1219
+ Develop: "develop",
1220
+ Docs: "docs",
1221
+ Format: "format",
1222
+ Install: "install",
1223
+ Lint: "lint",
1224
+ Prepare: "prepare",
1225
+ Release: "release",
1226
+ Rescue: "rescue",
1227
+ Spellcheck: "spellcheck",
1228
+ Test: "test",
1229
+ Typecheck: "typecheck",
1230
+ Validate: "validate"
1231
+ };
1232
+ exports.ESLintConfig = ESLintConfig;
1233
+ exports.Project = Project;
1234
+ exports.ProjectScript = ProjectScript;
1235
+ exports.interopDefault = interopDefault;
1236
+ exports.meta = meta;
1237
+ })))();
915
1238
  const defaultFiles$4 = [sourceGlob$1];
916
1239
  async function react(options = {}) {
917
1240
  const [reactPlugin] = await Promise.all([interopDefault(import("@eslint-react/eslint-plugin"))]);
918
- const { files, recommended, rules = {} } = options;
1241
+ const { files, recommended = true, rules = {} } = options;
919
1242
  return [{
920
1243
  name: "w5s/react/setup",
921
1244
  plugins: { react: reactPlugin }
@@ -927,7 +1250,7 @@ async function react(options = {}) {
927
1250
  },
928
1251
  name: "w5s/react/rules",
929
1252
  rules: {
930
- ...recommended ? reactPlugin.configs["recommended"].rules : {},
1253
+ ...recommended ? import_dist.ESLintConfig.renameRules(reactPlugin.configs["recommended"].rules, { "@eslint-react": "react" }) : {},
931
1254
  ...rules
932
1255
  }
933
1256
  }];
@@ -1207,16 +1530,16 @@ async function defineConfig(options = {}) {
1207
1530
  ...optionsOrBoolean
1208
1531
  });
1209
1532
  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 }] : []);
1533
+ 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)), ...rules ? [{ rules }] : []);
1211
1534
  }
1212
1535
  //#endregion
1213
1536
  //#region src/meta.ts
1214
1537
  const meta = Object.freeze({
1215
1538
  buildNumber: 1,
1216
1539
  name: "@w5s/eslint-config",
1217
- version: "3.14.0"
1540
+ version: "3.16.0"
1218
1541
  });
1219
1542
  //#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 };
1543
+ export { StylisticConfig, defineConfig as default, defineConfig, e18e, es, ignores, imports, jsdoc, jsonc, jsx, markdown, meta, next, node, perfectionist, react, stylistic, test, ts, unicorn, yml };
1221
1544
 
1222
1545
  //# sourceMappingURL=index.js.map