@coderwyd/eslint-config 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -46,32 +46,32 @@ var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
46
46
  var import_picocolors = __toESM(require("picocolors"), 1);
47
47
 
48
48
  // package.json
49
- var version = "2.2.1";
49
+ var version = "2.3.0";
50
50
  var devDependencies = {
51
51
  "@antfu/ni": "^0.21.12",
52
- "@types/eslint": "^8.56.5",
52
+ "@types/eslint": "^8.56.6",
53
53
  "@types/fs-extra": "^11.0.4",
54
- "@types/node": "^20.11.24",
54
+ "@types/node": "^20.11.30",
55
55
  "@types/prompts": "^2.4.9",
56
56
  "@types/yargs": "^17.0.32",
57
- "@unocss/eslint-plugin": "^0.58.5",
58
- bumpp: "^9.3.0",
57
+ "@unocss/eslint-plugin": "^0.58.6",
58
+ bumpp: "^9.4.0",
59
59
  eslint: "^8.57.0",
60
- "eslint-flat-config-viewer": "^0.1.11",
61
- "eslint-plugin-react": "^7.33.2",
60
+ "eslint-flat-config-viewer": "^0.1.14",
61
+ "eslint-plugin-react": "^7.34.1",
62
62
  "eslint-plugin-react-hooks": "^4.6.0",
63
- "eslint-plugin-react-refresh": "^0.4.5",
63
+ "eslint-plugin-react-refresh": "^0.4.6",
64
64
  "eslint-plugin-svelte": "^2.35.1",
65
- esno: "^4.0.0",
66
65
  execa: "^8.0.1",
67
66
  "fast-glob": "^3.3.2",
68
67
  "fs-extra": "^11.2.0",
69
68
  "lint-staged": "^15.2.2",
70
69
  rimraf: "^5.0.5",
71
- "simple-git-hooks": "^2.10.0",
70
+ "simple-git-hooks": "^2.11.0",
72
71
  "svelte-eslint-parser": "^0.33.1",
73
72
  tsup: "^8.0.2",
74
- typescript: "^5.3.3"
73
+ tsx: "^4.7.1",
74
+ typescript: "^5.4.3"
75
75
  };
76
76
 
77
77
  // src/cli/constants.ts
@@ -196,7 +196,7 @@ ${coderwydConfig}
196
196
  const files = import_node_fs.default.readdirSync(cwd);
197
197
  const legacyConfig = [];
198
198
  files.forEach((file) => {
199
- if (file.includes("eslint") || file.includes("prettier"))
199
+ if (/eslint|prettier/.test(file) && !/eslint.config./.test(file))
200
200
  legacyConfig.push(file);
201
201
  });
202
202
  if (legacyConfig.length > 0) {
package/dist/cli.js CHANGED
@@ -17,32 +17,32 @@ import parse from "parse-gitignore";
17
17
  import c from "picocolors";
18
18
 
19
19
  // package.json
20
- var version = "2.2.1";
20
+ var version = "2.3.0";
21
21
  var devDependencies = {
22
22
  "@antfu/ni": "^0.21.12",
23
- "@types/eslint": "^8.56.5",
23
+ "@types/eslint": "^8.56.6",
24
24
  "@types/fs-extra": "^11.0.4",
25
- "@types/node": "^20.11.24",
25
+ "@types/node": "^20.11.30",
26
26
  "@types/prompts": "^2.4.9",
27
27
  "@types/yargs": "^17.0.32",
28
- "@unocss/eslint-plugin": "^0.58.5",
29
- bumpp: "^9.3.0",
28
+ "@unocss/eslint-plugin": "^0.58.6",
29
+ bumpp: "^9.4.0",
30
30
  eslint: "^8.57.0",
31
- "eslint-flat-config-viewer": "^0.1.11",
32
- "eslint-plugin-react": "^7.33.2",
31
+ "eslint-flat-config-viewer": "^0.1.14",
32
+ "eslint-plugin-react": "^7.34.1",
33
33
  "eslint-plugin-react-hooks": "^4.6.0",
34
- "eslint-plugin-react-refresh": "^0.4.5",
34
+ "eslint-plugin-react-refresh": "^0.4.6",
35
35
  "eslint-plugin-svelte": "^2.35.1",
36
- esno: "^4.0.0",
37
36
  execa: "^8.0.1",
38
37
  "fast-glob": "^3.3.2",
39
38
  "fs-extra": "^11.2.0",
40
39
  "lint-staged": "^15.2.2",
41
40
  rimraf: "^5.0.5",
42
- "simple-git-hooks": "^2.10.0",
41
+ "simple-git-hooks": "^2.11.0",
43
42
  "svelte-eslint-parser": "^0.33.1",
44
43
  tsup: "^8.0.2",
45
- typescript: "^5.3.3"
44
+ tsx: "^4.7.1",
45
+ typescript: "^5.4.3"
46
46
  };
47
47
 
48
48
  // src/cli/constants.ts
@@ -167,7 +167,7 @@ ${coderwydConfig}
167
167
  const files = fs.readdirSync(cwd);
168
168
  const legacyConfig = [];
169
169
  files.forEach((file) => {
170
- if (file.includes("eslint") || file.includes("prettier"))
170
+ if (/eslint|prettier/.test(file) && !/eslint.config./.test(file))
171
171
  legacyConfig.push(file);
172
172
  });
173
173
  if (legacyConfig.length > 0) {
package/dist/index.cjs CHANGED
@@ -30,7 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- defineConfig: () => defineConfig
33
+ combine: () => combine,
34
+ defaultPluginRenaming: () => defaultPluginRenaming,
35
+ defineConfig: () => defineConfig,
36
+ ensurePackages: () => ensurePackages,
37
+ getOverrides: () => getOverrides,
38
+ getVueVersion: () => getVueVersion,
39
+ interopDefault: () => interopDefault,
40
+ loadPrettierConfig: () => loadPrettierConfig,
41
+ parserPlain: () => parserPlain,
42
+ renamePluginInConfigs: () => renamePluginInConfigs,
43
+ renameRules: () => renameRules,
44
+ resolveSubOptions: () => resolveSubOptions,
45
+ toArray: () => toArray
34
46
  });
35
47
  module.exports = __toCommonJS(src_exports);
36
48
  var import_node_process4 = __toESM(require("process"), 1);
@@ -48,7 +60,7 @@ var DEFAULT_PRETTIER_RULES = {
48
60
  // src/plugins/index.ts
49
61
  var import_eslint_plugin_antfu = __toESM(require("eslint-plugin-antfu"), 1);
50
62
  var import_eslint_plugin_eslint_comments = __toESM(require("eslint-plugin-eslint-comments"), 1);
51
- var pluginImport = __toESM(require("eslint-plugin-i"), 1);
63
+ var pluginImport = __toESM(require("eslint-plugin-import-x"), 1);
52
64
  var import_eslint_plugin_n = __toESM(require("eslint-plugin-n"), 1);
53
65
  var import_eslint_plugin_unicorn = __toESM(require("eslint-plugin-unicorn"), 1);
54
66
  var import_eslint_plugin_unused_imports = __toESM(require("eslint-plugin-unused-imports"), 1);
@@ -124,6 +136,7 @@ var GLOB_EXCLUDE = [
124
136
  "**/.cache",
125
137
  "**/.output",
126
138
  "**/.vite-inspect",
139
+ "**/.yarn",
127
140
  "**/CHANGELOG*.md",
128
141
  "**/*.min.*",
129
142
  "**/LICENSE*",
@@ -179,10 +192,7 @@ async function imports() {
179
192
  ],
180
193
  ...{
181
194
  // format
182
- "import/newline-after-import": [
183
- "error",
184
- { considerComments: true, count: 1 }
185
- ]
195
+ "import/newline-after-import": ["error", { count: 1 }]
186
196
  }
187
197
  }
188
198
  },
@@ -256,6 +266,7 @@ async function javascript(options = {}) {
256
266
  "no-cond-assign": ["error", "always"],
257
267
  "no-console": ["error", { allow: ["warn", "error"] }],
258
268
  "no-const-assign": "error",
269
+ "no-constant-binary-expression": "error",
259
270
  "no-constant-condition": "error",
260
271
  "no-control-regex": "error",
261
272
  "no-debugger": "error",
@@ -486,15 +497,34 @@ async function combine(...configs) {
486
497
  const resolved = await Promise.all(configs);
487
498
  return resolved.flat();
488
499
  }
489
- function renameRules(rules, from, to) {
500
+ function renameRules(rules, map) {
490
501
  return Object.fromEntries(
491
502
  Object.entries(rules).map(([key, value]) => {
492
- if (key.startsWith(from))
493
- return [to + key.slice(from.length), value];
503
+ for (const [from, to] of Object.entries(map)) {
504
+ if (key.startsWith(`${from}/`))
505
+ return [to + key.slice(from.length), value];
506
+ }
494
507
  return [key, value];
495
508
  })
496
509
  );
497
510
  }
511
+ function renamePluginInConfigs(configs, map) {
512
+ return configs.map((i) => {
513
+ const clone = { ...i };
514
+ if (clone.rules)
515
+ clone.rules = renameRules(clone.rules, map);
516
+ if (clone.plugins) {
517
+ clone.plugins = Object.fromEntries(
518
+ Object.entries(clone.plugins).map(([key, value]) => {
519
+ if (key in map)
520
+ return [map[key], value];
521
+ return [key, value];
522
+ })
523
+ );
524
+ }
525
+ return clone;
526
+ });
527
+ }
498
528
  function getVueVersion() {
499
529
  const pkg = (0, import_local_pkg.getPackageInfoSync)("vue", { paths: [import_node_process.default.cwd()] });
500
530
  if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0]))
@@ -752,6 +782,22 @@ async function sortPackageJson() {
752
782
  {
753
783
  order: ["types", "import", "require", "default"],
754
784
  pathPattern: "^exports.*$"
785
+ },
786
+ {
787
+ order: [
788
+ // client hooks only
789
+ "pre-commit",
790
+ "prepare-commit-msg",
791
+ "commit-msg",
792
+ "post-commit",
793
+ "pre-rebase",
794
+ "post-rewrite",
795
+ "post-checkout",
796
+ "post-merge",
797
+ "pre-push",
798
+ "pre-auto-gc"
799
+ ],
800
+ pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
755
801
  }
756
802
  ]
757
803
  }
@@ -989,14 +1035,11 @@ async function typescript(options = {}) {
989
1035
  rules: {
990
1036
  ...renameRules(
991
1037
  pluginTs.configs["eslint-recommended"].overrides[0].rules,
992
- "@typescript-eslint/",
993
- "ts/"
994
- ),
995
- ...renameRules(
996
- pluginTs.configs.strict.rules,
997
- "@typescript-eslint/",
998
- "ts/"
1038
+ { "@typescript-eslint": "ts" }
999
1039
  ),
1040
+ ...renameRules(pluginTs.configs.strict.rules, {
1041
+ "@typescript-eslint": "ts"
1042
+ }),
1000
1043
  "no-dupe-class-members": "off",
1001
1044
  "no-loss-of-precision": "off",
1002
1045
  "no-redeclare": "off",
@@ -1164,6 +1207,26 @@ async function vue(options = {}) {
1164
1207
  }, {});
1165
1208
  return [
1166
1209
  {
1210
+ // This allows Vue plugin to work with auto imports
1211
+ // https://github.com/vuejs/eslint-plugin-vue/pull/2422
1212
+ languageOptions: {
1213
+ globals: {
1214
+ computed: "readonly",
1215
+ defineEmits: "readonly",
1216
+ defineExpose: "readonly",
1217
+ defineProps: "readonly",
1218
+ onMounted: "readonly",
1219
+ onUnmounted: "readonly",
1220
+ reactive: "readonly",
1221
+ ref: "readonly",
1222
+ shallowReactive: "readonly",
1223
+ shallowRef: "readonly",
1224
+ toRef: "readonly",
1225
+ toRefs: "readonly",
1226
+ watch: "readonly",
1227
+ watchEffect: "readonly"
1228
+ }
1229
+ },
1167
1230
  name: "coderwyd:vue:setup",
1168
1231
  plugins: {
1169
1232
  vue: pluginVue
@@ -1676,6 +1739,7 @@ async function tailwindcss(options = {}) {
1676
1739
  "tailwindcss/no-arbitrary-value": "off",
1677
1740
  "tailwindcss/no-contradicting-classname": "error",
1678
1741
  "tailwindcss/no-custom-classname": "off",
1742
+ "tailwindcss/no-unnecessary-arbitrary-value": "warn",
1679
1743
  ...overrides
1680
1744
  }
1681
1745
  }
@@ -1703,8 +1767,16 @@ var flatConfigProps = [
1703
1767
  "rules",
1704
1768
  "settings"
1705
1769
  ];
1770
+ var defaultPluginRenaming = {
1771
+ "@typescript-eslint": "ts",
1772
+ "import-x": "import",
1773
+ n: "node",
1774
+ vitest: "test",
1775
+ yml: "yaml"
1776
+ };
1706
1777
  async function defineConfig(options = {}, ...userConfigs) {
1707
1778
  const {
1779
+ autoRenamePlugins = true,
1708
1780
  componentExts = [],
1709
1781
  gitignore: enableGitignore = true,
1710
1782
  isInEditor: isInEditor2 = isInEditor,
@@ -1839,10 +1911,24 @@ async function defineConfig(options = {}, ...userConfigs) {
1839
1911
  }, {});
1840
1912
  if (Object.keys(fusedConfig).length > 0)
1841
1913
  configs.push([fusedConfig]);
1842
- const merged = combine(...configs, ...userConfigs);
1914
+ const merged = await combine(...configs, ...userConfigs);
1915
+ if (autoRenamePlugins)
1916
+ return renamePluginInConfigs(merged, defaultPluginRenaming);
1843
1917
  return merged;
1844
1918
  }
1845
1919
  // Annotate the CommonJS export names for ESM import in node:
1846
1920
  0 && (module.exports = {
1847
- defineConfig
1921
+ combine,
1922
+ defaultPluginRenaming,
1923
+ defineConfig,
1924
+ ensurePackages,
1925
+ getOverrides,
1926
+ getVueVersion,
1927
+ interopDefault,
1928
+ loadPrettierConfig,
1929
+ parserPlain,
1930
+ renamePluginInConfigs,
1931
+ renameRules,
1932
+ resolveSubOptions,
1933
+ toArray
1848
1934
  });
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FlatGitignoreOptions } from 'eslint-config-flat-gitignore';
2
2
  import { ParserOptions } from '@typescript-eslint/parser';
3
- import { RuleConfig, FlatESLintConfigItem, MergeIntersection, RenamePrefix, TypeScriptRules, VitestRules, NRules, Prefix, ReactHooksRules, ReactRules, JSDocRules, ImportRules, EslintRules, JsoncRules, VueRules, UnicornRules, EslintCommentsRules } from '@antfu/eslint-define-config';
4
- import { RequiredOptions, LiteralUnion, BuiltInParserName } from 'prettier';
3
+ import { RuleConfig, MergeIntersection, RenamePrefix, TypeScriptRules, VitestRules, NRules, Prefix, ReactHooksRules, ReactRules, JSDocRules, ImportRules, EslintRules, JsoncRules, VueRules, UnicornRules, EslintCommentsRules, FlatESLintConfigItem } from '@antfu/eslint-define-config';
4
+ import { BuiltInParserName, RequiredOptions, LiteralUnion } from 'prettier';
5
5
  import { Linter } from 'eslint';
6
6
  import { Rules } from 'eslint-plugin-antfu';
7
7
 
@@ -284,6 +284,44 @@ interface NoCustomClassnameRule {
284
284
  'tailwindcss/no-custom-classname': NoCustomClassnameRuleConfig
285
285
  }
286
286
 
287
+ /**
288
+ * Option.
289
+ */
290
+ interface NoUnnecessaryArbitraryValueOption {
291
+ callees?: string[]
292
+ ignoredKeys?: string[]
293
+ config?: string | Record<string, any>
294
+ tags?: string[]
295
+
296
+ [k: string]: any
297
+ }
298
+
299
+ /**
300
+ * Options.
301
+ */
302
+ type NoUnnecessaryArbitraryValueOptions = [
303
+ NoUnnecessaryArbitraryValueOption?,
304
+ ]
305
+
306
+ /**
307
+ * Avoid unjustified arbitrary classnames.
308
+ * @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
309
+ */
310
+ type NoUnnecessaryArbitraryValueRuleConfig =
311
+ RuleConfig<NoUnnecessaryArbitraryValueOptions>
312
+
313
+ /**
314
+ * Avoid unjustified arbitrary classnames.
315
+ * @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
316
+ */
317
+ interface NoUnnecessaryArbitraryValueRule {
318
+ /**
319
+ * Avoid unjustified arbitrary classnames.
320
+ * @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
321
+ */
322
+ 'tailwindcss/no-unnecessary-arbitrary-value': NoUnnecessaryArbitraryValueRuleConfig
323
+ }
324
+
287
325
  /**
288
326
  * All TailwindCss rules.
289
327
  */
@@ -293,7 +331,8 @@ type TailwindCssRules = ClassnamesOrderRule &
293
331
  MigrationFromTailwind_2Rule &
294
332
  NoArbitraryValueRule &
295
333
  NoContradictingClassnameRule &
296
- NoCustomClassnameRule
334
+ NoCustomClassnameRule &
335
+ NoUnnecessaryArbitraryValueRule
297
336
 
298
337
  type WrapRuleConfig<T extends {
299
338
  [key: string]: any;
@@ -318,6 +357,12 @@ type FlatConfigItem = Omit<FlatESLintConfigItem<EslintFlatRules, false>, 'plugin
318
357
  type UserConfigItem = FlatConfigItem | Linter.FlatConfig;
319
358
 
320
359
  type Awaitable<T> = T | Promise<T>;
360
+ interface OptionsFiles {
361
+ /**
362
+ * Override the `files` option to provide custom globs.
363
+ */
364
+ files?: string[];
365
+ }
321
366
  type OptionsTypescript = (OptionsTypeScriptWithTypes & OptionsOverrides) | (OptionsTypeScriptParserOptions & OptionsOverrides);
322
367
  interface OptionsFormatters {
323
368
  /**
@@ -372,6 +417,12 @@ interface OptionsTypeScriptWithTypes {
372
417
  */
373
418
  tsconfigPath?: string | string[];
374
419
  }
420
+ interface OptionsHasTypeScript {
421
+ typescript?: boolean;
422
+ }
423
+ interface OptionsIsInEditor {
424
+ isInEditor?: boolean;
425
+ }
375
426
  interface OptionsOverrides {
376
427
  overrides?: FlatConfigItem['rules'];
377
428
  }
@@ -521,11 +572,107 @@ interface OptionsConfig extends OptionsComponentExts {
521
572
  * @default auto-detect based on the process.env
522
573
  */
523
574
  isInEditor?: boolean;
575
+ /**
576
+ * Automatically rename plugins in the config.
577
+ *
578
+ * @default true
579
+ */
580
+ autoRenamePlugins?: boolean;
524
581
  }
525
-
582
+ type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
583
+
584
+ declare const parserPlain: {
585
+ meta: {
586
+ name: string;
587
+ };
588
+ parseForESLint: (code: string) => {
589
+ ast: {
590
+ body: never[];
591
+ comments: never[];
592
+ loc: {
593
+ end: number;
594
+ start: number;
595
+ };
596
+ range: number[];
597
+ tokens: never[];
598
+ type: string;
599
+ };
600
+ scopeManager: null;
601
+ services: {
602
+ isPlain: boolean;
603
+ };
604
+ visitorKeys: {
605
+ Program: never[];
606
+ };
607
+ };
608
+ };
609
+ /**
610
+ * Combine array and non-array configs into a single array.
611
+ */
612
+ declare function combine(...configs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
613
+ /**
614
+ * Rename plugin prefixes in a rule object.
615
+ * Accepts a map of prefixes to rename.
616
+ *
617
+ * @example
618
+ * ```ts
619
+ * import { renameRules } from '@coderwyd/eslint-config'
620
+ *
621
+ * export default [{
622
+ * rules: renameRules(
623
+ * {
624
+ * '@typescript-eslint/indent': 'error'
625
+ * },
626
+ * { '@typescript-eslint': 'ts' }
627
+ * )
628
+ * }]
629
+ * ```
630
+ */
631
+ declare function renameRules(rules: Record<string, any>, map: Record<string, string>): {
632
+ [k: string]: any;
633
+ };
634
+ /**
635
+ * Rename plugin names a flat configs array
636
+ *
637
+ * @example
638
+ * ```ts
639
+ * import { renamePluginInConfigs } from '@antfu/eslint-config'
640
+ * import someConfigs from './some-configs'
641
+ *
642
+ * export default renamePluginInConfigs(someConfigs, {
643
+ * '@typescript-eslint': 'ts',
644
+ * 'import-x': 'import',
645
+ * })
646
+ * ```
647
+ */
648
+ declare function renamePluginInConfigs(configs: UserConfigItem[], map: Record<string, string>): UserConfigItem[];
649
+ declare function getVueVersion(): number;
650
+ declare function toArray<T>(value: T | T[]): T[];
651
+ declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
652
+ default: infer U;
653
+ } ? U : T>;
654
+ declare function ensurePackages(packages: string[]): Promise<void>;
655
+ declare function loadPrettierConfig(cwd: string): Promise<Partial<PrettierOptions>>;
656
+ declare function resolveSubOptions<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolvedOptions<OptionsConfig[K]>;
657
+ declare function getOverrides<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): {};
658
+
659
+ declare const defaultPluginRenaming: {
660
+ '@typescript-eslint': string;
661
+ 'import-x': string;
662
+ n: string;
663
+ vitest: string;
664
+ yml: string;
665
+ };
526
666
  /**
527
667
  * Construct an array of ESLint flat config items.
668
+ *
669
+ * @param {OptionsConfig & FlatConfigItem} options
670
+ * The options for generating the ESLint configurations.
671
+ * @param {Awaitable<UserConfigItem | UserConfigItem[]>[]} userConfigs
672
+ * The user configurations to be merged with the generated configurations.
673
+ * @returns {Promise<UserConfigItem[]>}
674
+ * The merged ESLint configurations.
528
675
  */
529
676
  declare function defineConfig(options?: OptionsConfig & FlatConfigItem, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
530
677
 
531
- export { defineConfig };
678
+ export { type Awaitable, type EslintFlatRules, type FlatConfigItem, type OptionsComponentExts, type OptionsConfig, type OptionsFiles, type OptionsFormatters, type OptionsHasTypeScript, type OptionsIsInEditor, type OptionsOverrides, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type OptionsTypescript, type OptionsUnoCSS, type OptionsVue, type PartialPrettierExtendedOptions, type PrettierParser, type ResolvedOptions, type UserConfigItem, type WrapRuleConfig, combine, defaultPluginRenaming, defineConfig, ensurePackages, getOverrides, getVueVersion, interopDefault, loadPrettierConfig, parserPlain, renamePluginInConfigs, renameRules, resolveSubOptions, toArray };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FlatGitignoreOptions } from 'eslint-config-flat-gitignore';
2
2
  import { ParserOptions } from '@typescript-eslint/parser';
3
- import { RuleConfig, FlatESLintConfigItem, MergeIntersection, RenamePrefix, TypeScriptRules, VitestRules, NRules, Prefix, ReactHooksRules, ReactRules, JSDocRules, ImportRules, EslintRules, JsoncRules, VueRules, UnicornRules, EslintCommentsRules } from '@antfu/eslint-define-config';
4
- import { RequiredOptions, LiteralUnion, BuiltInParserName } from 'prettier';
3
+ import { RuleConfig, MergeIntersection, RenamePrefix, TypeScriptRules, VitestRules, NRules, Prefix, ReactHooksRules, ReactRules, JSDocRules, ImportRules, EslintRules, JsoncRules, VueRules, UnicornRules, EslintCommentsRules, FlatESLintConfigItem } from '@antfu/eslint-define-config';
4
+ import { BuiltInParserName, RequiredOptions, LiteralUnion } from 'prettier';
5
5
  import { Linter } from 'eslint';
6
6
  import { Rules } from 'eslint-plugin-antfu';
7
7
 
@@ -284,6 +284,44 @@ interface NoCustomClassnameRule {
284
284
  'tailwindcss/no-custom-classname': NoCustomClassnameRuleConfig
285
285
  }
286
286
 
287
+ /**
288
+ * Option.
289
+ */
290
+ interface NoUnnecessaryArbitraryValueOption {
291
+ callees?: string[]
292
+ ignoredKeys?: string[]
293
+ config?: string | Record<string, any>
294
+ tags?: string[]
295
+
296
+ [k: string]: any
297
+ }
298
+
299
+ /**
300
+ * Options.
301
+ */
302
+ type NoUnnecessaryArbitraryValueOptions = [
303
+ NoUnnecessaryArbitraryValueOption?,
304
+ ]
305
+
306
+ /**
307
+ * Avoid unjustified arbitrary classnames.
308
+ * @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
309
+ */
310
+ type NoUnnecessaryArbitraryValueRuleConfig =
311
+ RuleConfig<NoUnnecessaryArbitraryValueOptions>
312
+
313
+ /**
314
+ * Avoid unjustified arbitrary classnames.
315
+ * @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
316
+ */
317
+ interface NoUnnecessaryArbitraryValueRule {
318
+ /**
319
+ * Avoid unjustified arbitrary classnames.
320
+ * @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
321
+ */
322
+ 'tailwindcss/no-unnecessary-arbitrary-value': NoUnnecessaryArbitraryValueRuleConfig
323
+ }
324
+
287
325
  /**
288
326
  * All TailwindCss rules.
289
327
  */
@@ -293,7 +331,8 @@ type TailwindCssRules = ClassnamesOrderRule &
293
331
  MigrationFromTailwind_2Rule &
294
332
  NoArbitraryValueRule &
295
333
  NoContradictingClassnameRule &
296
- NoCustomClassnameRule
334
+ NoCustomClassnameRule &
335
+ NoUnnecessaryArbitraryValueRule
297
336
 
298
337
  type WrapRuleConfig<T extends {
299
338
  [key: string]: any;
@@ -318,6 +357,12 @@ type FlatConfigItem = Omit<FlatESLintConfigItem<EslintFlatRules, false>, 'plugin
318
357
  type UserConfigItem = FlatConfigItem | Linter.FlatConfig;
319
358
 
320
359
  type Awaitable<T> = T | Promise<T>;
360
+ interface OptionsFiles {
361
+ /**
362
+ * Override the `files` option to provide custom globs.
363
+ */
364
+ files?: string[];
365
+ }
321
366
  type OptionsTypescript = (OptionsTypeScriptWithTypes & OptionsOverrides) | (OptionsTypeScriptParserOptions & OptionsOverrides);
322
367
  interface OptionsFormatters {
323
368
  /**
@@ -372,6 +417,12 @@ interface OptionsTypeScriptWithTypes {
372
417
  */
373
418
  tsconfigPath?: string | string[];
374
419
  }
420
+ interface OptionsHasTypeScript {
421
+ typescript?: boolean;
422
+ }
423
+ interface OptionsIsInEditor {
424
+ isInEditor?: boolean;
425
+ }
375
426
  interface OptionsOverrides {
376
427
  overrides?: FlatConfigItem['rules'];
377
428
  }
@@ -521,11 +572,107 @@ interface OptionsConfig extends OptionsComponentExts {
521
572
  * @default auto-detect based on the process.env
522
573
  */
523
574
  isInEditor?: boolean;
575
+ /**
576
+ * Automatically rename plugins in the config.
577
+ *
578
+ * @default true
579
+ */
580
+ autoRenamePlugins?: boolean;
524
581
  }
525
-
582
+ type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
583
+
584
+ declare const parserPlain: {
585
+ meta: {
586
+ name: string;
587
+ };
588
+ parseForESLint: (code: string) => {
589
+ ast: {
590
+ body: never[];
591
+ comments: never[];
592
+ loc: {
593
+ end: number;
594
+ start: number;
595
+ };
596
+ range: number[];
597
+ tokens: never[];
598
+ type: string;
599
+ };
600
+ scopeManager: null;
601
+ services: {
602
+ isPlain: boolean;
603
+ };
604
+ visitorKeys: {
605
+ Program: never[];
606
+ };
607
+ };
608
+ };
609
+ /**
610
+ * Combine array and non-array configs into a single array.
611
+ */
612
+ declare function combine(...configs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
613
+ /**
614
+ * Rename plugin prefixes in a rule object.
615
+ * Accepts a map of prefixes to rename.
616
+ *
617
+ * @example
618
+ * ```ts
619
+ * import { renameRules } from '@coderwyd/eslint-config'
620
+ *
621
+ * export default [{
622
+ * rules: renameRules(
623
+ * {
624
+ * '@typescript-eslint/indent': 'error'
625
+ * },
626
+ * { '@typescript-eslint': 'ts' }
627
+ * )
628
+ * }]
629
+ * ```
630
+ */
631
+ declare function renameRules(rules: Record<string, any>, map: Record<string, string>): {
632
+ [k: string]: any;
633
+ };
634
+ /**
635
+ * Rename plugin names a flat configs array
636
+ *
637
+ * @example
638
+ * ```ts
639
+ * import { renamePluginInConfigs } from '@antfu/eslint-config'
640
+ * import someConfigs from './some-configs'
641
+ *
642
+ * export default renamePluginInConfigs(someConfigs, {
643
+ * '@typescript-eslint': 'ts',
644
+ * 'import-x': 'import',
645
+ * })
646
+ * ```
647
+ */
648
+ declare function renamePluginInConfigs(configs: UserConfigItem[], map: Record<string, string>): UserConfigItem[];
649
+ declare function getVueVersion(): number;
650
+ declare function toArray<T>(value: T | T[]): T[];
651
+ declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
652
+ default: infer U;
653
+ } ? U : T>;
654
+ declare function ensurePackages(packages: string[]): Promise<void>;
655
+ declare function loadPrettierConfig(cwd: string): Promise<Partial<PrettierOptions>>;
656
+ declare function resolveSubOptions<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolvedOptions<OptionsConfig[K]>;
657
+ declare function getOverrides<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): {};
658
+
659
+ declare const defaultPluginRenaming: {
660
+ '@typescript-eslint': string;
661
+ 'import-x': string;
662
+ n: string;
663
+ vitest: string;
664
+ yml: string;
665
+ };
526
666
  /**
527
667
  * Construct an array of ESLint flat config items.
668
+ *
669
+ * @param {OptionsConfig & FlatConfigItem} options
670
+ * The options for generating the ESLint configurations.
671
+ * @param {Awaitable<UserConfigItem | UserConfigItem[]>[]} userConfigs
672
+ * The user configurations to be merged with the generated configurations.
673
+ * @returns {Promise<UserConfigItem[]>}
674
+ * The merged ESLint configurations.
528
675
  */
529
676
  declare function defineConfig(options?: OptionsConfig & FlatConfigItem, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
530
677
 
531
- export { defineConfig };
678
+ export { type Awaitable, type EslintFlatRules, type FlatConfigItem, type OptionsComponentExts, type OptionsConfig, type OptionsFiles, type OptionsFormatters, type OptionsHasTypeScript, type OptionsIsInEditor, type OptionsOverrides, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type OptionsTypescript, type OptionsUnoCSS, type OptionsVue, type PartialPrettierExtendedOptions, type PrettierParser, type ResolvedOptions, type UserConfigItem, type WrapRuleConfig, combine, defaultPluginRenaming, defineConfig, ensurePackages, getOverrides, getVueVersion, interopDefault, loadPrettierConfig, parserPlain, renamePluginInConfigs, renameRules, resolveSubOptions, toArray };
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var DEFAULT_PRETTIER_RULES = {
14
14
  // src/plugins/index.ts
15
15
  import { default as default2 } from "eslint-plugin-antfu";
16
16
  import { default as default3 } from "eslint-plugin-eslint-comments";
17
- import * as pluginImport from "eslint-plugin-i";
17
+ import * as pluginImport from "eslint-plugin-import-x";
18
18
  import { default as default4 } from "eslint-plugin-n";
19
19
  import { default as default5 } from "eslint-plugin-unicorn";
20
20
  import { default as default6 } from "eslint-plugin-unused-imports";
@@ -90,6 +90,7 @@ var GLOB_EXCLUDE = [
90
90
  "**/.cache",
91
91
  "**/.output",
92
92
  "**/.vite-inspect",
93
+ "**/.yarn",
93
94
  "**/CHANGELOG*.md",
94
95
  "**/*.min.*",
95
96
  "**/LICENSE*",
@@ -145,10 +146,7 @@ async function imports() {
145
146
  ],
146
147
  ...{
147
148
  // format
148
- "import/newline-after-import": [
149
- "error",
150
- { considerComments: true, count: 1 }
151
- ]
149
+ "import/newline-after-import": ["error", { count: 1 }]
152
150
  }
153
151
  }
154
152
  },
@@ -222,6 +220,7 @@ async function javascript(options = {}) {
222
220
  "no-cond-assign": ["error", "always"],
223
221
  "no-console": ["error", { allow: ["warn", "error"] }],
224
222
  "no-const-assign": "error",
223
+ "no-constant-binary-expression": "error",
225
224
  "no-constant-condition": "error",
226
225
  "no-control-regex": "error",
227
226
  "no-debugger": "error",
@@ -452,15 +451,34 @@ async function combine(...configs) {
452
451
  const resolved = await Promise.all(configs);
453
452
  return resolved.flat();
454
453
  }
455
- function renameRules(rules, from, to) {
454
+ function renameRules(rules, map) {
456
455
  return Object.fromEntries(
457
456
  Object.entries(rules).map(([key, value]) => {
458
- if (key.startsWith(from))
459
- return [to + key.slice(from.length), value];
457
+ for (const [from, to] of Object.entries(map)) {
458
+ if (key.startsWith(`${from}/`))
459
+ return [to + key.slice(from.length), value];
460
+ }
460
461
  return [key, value];
461
462
  })
462
463
  );
463
464
  }
465
+ function renamePluginInConfigs(configs, map) {
466
+ return configs.map((i) => {
467
+ const clone = { ...i };
468
+ if (clone.rules)
469
+ clone.rules = renameRules(clone.rules, map);
470
+ if (clone.plugins) {
471
+ clone.plugins = Object.fromEntries(
472
+ Object.entries(clone.plugins).map(([key, value]) => {
473
+ if (key in map)
474
+ return [map[key], value];
475
+ return [key, value];
476
+ })
477
+ );
478
+ }
479
+ return clone;
480
+ });
481
+ }
464
482
  function getVueVersion() {
465
483
  const pkg = getPackageInfoSync("vue", { paths: [process.cwd()] });
466
484
  if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0]))
@@ -718,6 +736,22 @@ async function sortPackageJson() {
718
736
  {
719
737
  order: ["types", "import", "require", "default"],
720
738
  pathPattern: "^exports.*$"
739
+ },
740
+ {
741
+ order: [
742
+ // client hooks only
743
+ "pre-commit",
744
+ "prepare-commit-msg",
745
+ "commit-msg",
746
+ "post-commit",
747
+ "pre-rebase",
748
+ "post-rewrite",
749
+ "post-checkout",
750
+ "post-merge",
751
+ "pre-push",
752
+ "pre-auto-gc"
753
+ ],
754
+ pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
721
755
  }
722
756
  ]
723
757
  }
@@ -955,14 +989,11 @@ async function typescript(options = {}) {
955
989
  rules: {
956
990
  ...renameRules(
957
991
  pluginTs.configs["eslint-recommended"].overrides[0].rules,
958
- "@typescript-eslint/",
959
- "ts/"
960
- ),
961
- ...renameRules(
962
- pluginTs.configs.strict.rules,
963
- "@typescript-eslint/",
964
- "ts/"
992
+ { "@typescript-eslint": "ts" }
965
993
  ),
994
+ ...renameRules(pluginTs.configs.strict.rules, {
995
+ "@typescript-eslint": "ts"
996
+ }),
966
997
  "no-dupe-class-members": "off",
967
998
  "no-loss-of-precision": "off",
968
999
  "no-redeclare": "off",
@@ -1130,6 +1161,26 @@ async function vue(options = {}) {
1130
1161
  }, {});
1131
1162
  return [
1132
1163
  {
1164
+ // This allows Vue plugin to work with auto imports
1165
+ // https://github.com/vuejs/eslint-plugin-vue/pull/2422
1166
+ languageOptions: {
1167
+ globals: {
1168
+ computed: "readonly",
1169
+ defineEmits: "readonly",
1170
+ defineExpose: "readonly",
1171
+ defineProps: "readonly",
1172
+ onMounted: "readonly",
1173
+ onUnmounted: "readonly",
1174
+ reactive: "readonly",
1175
+ ref: "readonly",
1176
+ shallowReactive: "readonly",
1177
+ shallowRef: "readonly",
1178
+ toRef: "readonly",
1179
+ toRefs: "readonly",
1180
+ watch: "readonly",
1181
+ watchEffect: "readonly"
1182
+ }
1183
+ },
1133
1184
  name: "coderwyd:vue:setup",
1134
1185
  plugins: {
1135
1186
  vue: pluginVue
@@ -1642,6 +1693,7 @@ async function tailwindcss(options = {}) {
1642
1693
  "tailwindcss/no-arbitrary-value": "off",
1643
1694
  "tailwindcss/no-contradicting-classname": "error",
1644
1695
  "tailwindcss/no-custom-classname": "off",
1696
+ "tailwindcss/no-unnecessary-arbitrary-value": "warn",
1645
1697
  ...overrides
1646
1698
  }
1647
1699
  }
@@ -1669,8 +1721,16 @@ var flatConfigProps = [
1669
1721
  "rules",
1670
1722
  "settings"
1671
1723
  ];
1724
+ var defaultPluginRenaming = {
1725
+ "@typescript-eslint": "ts",
1726
+ "import-x": "import",
1727
+ n: "node",
1728
+ vitest: "test",
1729
+ yml: "yaml"
1730
+ };
1672
1731
  async function defineConfig(options = {}, ...userConfigs) {
1673
1732
  const {
1733
+ autoRenamePlugins = true,
1674
1734
  componentExts = [],
1675
1735
  gitignore: enableGitignore = true,
1676
1736
  isInEditor: isInEditor2 = isInEditor,
@@ -1805,9 +1865,23 @@ async function defineConfig(options = {}, ...userConfigs) {
1805
1865
  }, {});
1806
1866
  if (Object.keys(fusedConfig).length > 0)
1807
1867
  configs.push([fusedConfig]);
1808
- const merged = combine(...configs, ...userConfigs);
1868
+ const merged = await combine(...configs, ...userConfigs);
1869
+ if (autoRenamePlugins)
1870
+ return renamePluginInConfigs(merged, defaultPluginRenaming);
1809
1871
  return merged;
1810
1872
  }
1811
1873
  export {
1812
- defineConfig
1874
+ combine,
1875
+ defaultPluginRenaming,
1876
+ defineConfig,
1877
+ ensurePackages,
1878
+ getOverrides,
1879
+ getVueVersion,
1880
+ interopDefault,
1881
+ loadPrettierConfig,
1882
+ parserPlain,
1883
+ renamePluginInConfigs,
1884
+ renameRules,
1885
+ resolveSubOptions,
1886
+ toArray
1813
1887
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@coderwyd/eslint-config",
3
3
  "type": "module",
4
- "version": "2.2.1",
5
- "packageManager": "pnpm@8.15.4",
4
+ "version": "2.3.0",
5
+ "packageManager": "pnpm@8.15.5",
6
6
  "description": "Donny's ESLint config",
7
7
  "author": "Donny Wang <donny526@outlook.com> (https://github.com/coderwyd/)",
8
8
  "license": "MIT",
@@ -68,28 +68,28 @@
68
68
  "dependencies": {
69
69
  "@antfu/eslint-define-config": "1.23.0-2",
70
70
  "@antfu/install-pkg": "^0.3.1",
71
- "@eslint-types/jsdoc": "48.2.0",
72
- "@eslint-types/typescript-eslint": "^7.0.2",
71
+ "@eslint-types/jsdoc": "48.2.1",
72
+ "@eslint-types/typescript-eslint": "^7.2.0",
73
73
  "@eslint-types/unicorn": "^51.0.1",
74
74
  "@toml-tools/parser": "^1.0.0",
75
- "@typescript-eslint/eslint-plugin": "^7.1.0",
76
- "@typescript-eslint/parser": "^7.1.0",
75
+ "@typescript-eslint/eslint-plugin": "^7.3.1",
76
+ "@typescript-eslint/parser": "^7.3.1",
77
77
  "eslint-config-flat-gitignore": "^0.1.3",
78
78
  "eslint-config-prettier": "^9.1.0",
79
79
  "eslint-plugin-antfu": "^2.1.2",
80
80
  "eslint-plugin-eslint-comments": "^3.2.0",
81
- "eslint-plugin-i": "^2.29.1",
82
- "eslint-plugin-jsdoc": "^48.2.0",
83
- "eslint-plugin-jsonc": "^2.13.0",
81
+ "eslint-plugin-import-x": "^0.4.1",
82
+ "eslint-plugin-jsdoc": "^48.2.1",
83
+ "eslint-plugin-jsonc": "^2.14.1",
84
84
  "eslint-plugin-n": "^16.6.2",
85
85
  "eslint-plugin-no-only-tests": "^3.1.0",
86
- "eslint-plugin-perfectionist": "^2.5.0",
86
+ "eslint-plugin-perfectionist": "^2.7.0",
87
87
  "eslint-plugin-prettier": "^5.1.3",
88
- "eslint-plugin-tailwindcss": "^3.14.3",
88
+ "eslint-plugin-tailwindcss": "^3.15.1",
89
89
  "eslint-plugin-unicorn": "^51.0.1",
90
90
  "eslint-plugin-unused-imports": "^3.1.0",
91
- "eslint-plugin-vitest": "^0.3.22",
92
- "eslint-plugin-vue": "^9.22.0",
91
+ "eslint-plugin-vitest": "^0.3.26",
92
+ "eslint-plugin-vue": "^9.23.0",
93
93
  "globals": "^14.0.0",
94
94
  "jsonc-eslint-parser": "^2.4.0",
95
95
  "local-pkg": "^0.5.0",
@@ -103,29 +103,29 @@
103
103
  },
104
104
  "devDependencies": {
105
105
  "@antfu/ni": "^0.21.12",
106
- "@types/eslint": "^8.56.5",
106
+ "@types/eslint": "^8.56.6",
107
107
  "@types/fs-extra": "^11.0.4",
108
- "@types/node": "^20.11.24",
108
+ "@types/node": "^20.11.30",
109
109
  "@types/prompts": "^2.4.9",
110
110
  "@types/yargs": "^17.0.32",
111
- "@unocss/eslint-plugin": "^0.58.5",
112
- "bumpp": "^9.3.0",
111
+ "@unocss/eslint-plugin": "^0.58.6",
112
+ "bumpp": "^9.4.0",
113
113
  "eslint": "^8.57.0",
114
- "eslint-flat-config-viewer": "^0.1.11",
115
- "eslint-plugin-react": "^7.33.2",
114
+ "eslint-flat-config-viewer": "^0.1.14",
115
+ "eslint-plugin-react": "^7.34.1",
116
116
  "eslint-plugin-react-hooks": "^4.6.0",
117
- "eslint-plugin-react-refresh": "^0.4.5",
117
+ "eslint-plugin-react-refresh": "^0.4.6",
118
118
  "eslint-plugin-svelte": "^2.35.1",
119
- "esno": "^4.0.0",
120
119
  "execa": "^8.0.1",
121
120
  "fast-glob": "^3.3.2",
122
121
  "fs-extra": "^11.2.0",
123
122
  "lint-staged": "^15.2.2",
124
123
  "rimraf": "^5.0.5",
125
- "simple-git-hooks": "^2.10.0",
124
+ "simple-git-hooks": "^2.11.0",
126
125
  "svelte-eslint-parser": "^0.33.1",
127
126
  "tsup": "^8.0.2",
128
- "typescript": "^5.3.3"
127
+ "tsx": "^4.7.1",
128
+ "typescript": "^5.4.3"
129
129
  },
130
130
  "simple-git-hooks": {
131
131
  "pre-commit": "pnpx nano-staged"