@coderwyd/eslint-config 2.2.2 → 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.2";
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.25",
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",
57
+ "@unocss/eslint-plugin": "^0.58.6",
58
58
  bumpp: "^9.4.0",
59
59
  eslint: "^8.57.0",
60
- "eslint-flat-config-viewer": "^0.1.11",
61
- "eslint-plugin-react": "^7.34.0",
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
65
  execa: "^8.0.1",
66
66
  "fast-glob": "^3.3.2",
67
67
  "fs-extra": "^11.2.0",
68
68
  "lint-staged": "^15.2.2",
69
69
  rimraf: "^5.0.5",
70
- "simple-git-hooks": "^2.10.0",
70
+ "simple-git-hooks": "^2.11.0",
71
71
  "svelte-eslint-parser": "^0.33.1",
72
72
  tsup: "^8.0.2",
73
73
  tsx: "^4.7.1",
74
- typescript: "^5.3.3"
74
+ typescript: "^5.4.3"
75
75
  };
76
76
 
77
77
  // src/cli/constants.ts
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.2";
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.25",
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",
28
+ "@unocss/eslint-plugin": "^0.58.6",
29
29
  bumpp: "^9.4.0",
30
30
  eslint: "^8.57.0",
31
- "eslint-flat-config-viewer": "^0.1.11",
32
- "eslint-plugin-react": "^7.34.0",
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
36
  execa: "^8.0.1",
37
37
  "fast-glob": "^3.3.2",
38
38
  "fs-extra": "^11.2.0",
39
39
  "lint-staged": "^15.2.2",
40
40
  rimraf: "^5.0.5",
41
- "simple-git-hooks": "^2.10.0",
41
+ "simple-git-hooks": "^2.11.0",
42
42
  "svelte-eslint-parser": "^0.33.1",
43
43
  tsup: "^8.0.2",
44
44
  tsx: "^4.7.1",
45
- typescript: "^5.3.3"
45
+ typescript: "^5.4.3"
46
46
  };
47
47
 
48
48
  // src/cli/constants.ts
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);
@@ -180,10 +192,7 @@ async function imports() {
180
192
  ],
181
193
  ...{
182
194
  // format
183
- "import/newline-after-import": [
184
- "error",
185
- { considerComments: true, count: 1 }
186
- ]
195
+ "import/newline-after-import": ["error", { count: 1 }]
187
196
  }
188
197
  }
189
198
  },
@@ -488,15 +497,34 @@ async function combine(...configs) {
488
497
  const resolved = await Promise.all(configs);
489
498
  return resolved.flat();
490
499
  }
491
- function renameRules(rules, from, to) {
500
+ function renameRules(rules, map) {
492
501
  return Object.fromEntries(
493
502
  Object.entries(rules).map(([key, value]) => {
494
- if (key.startsWith(from))
495
- 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
+ }
496
507
  return [key, value];
497
508
  })
498
509
  );
499
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
+ }
500
528
  function getVueVersion() {
501
529
  const pkg = (0, import_local_pkg.getPackageInfoSync)("vue", { paths: [import_node_process.default.cwd()] });
502
530
  if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0]))
@@ -754,6 +782,22 @@ async function sortPackageJson() {
754
782
  {
755
783
  order: ["types", "import", "require", "default"],
756
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)$"
757
801
  }
758
802
  ]
759
803
  }
@@ -991,14 +1035,11 @@ async function typescript(options = {}) {
991
1035
  rules: {
992
1036
  ...renameRules(
993
1037
  pluginTs.configs["eslint-recommended"].overrides[0].rules,
994
- "@typescript-eslint/",
995
- "ts/"
996
- ),
997
- ...renameRules(
998
- pluginTs.configs.strict.rules,
999
- "@typescript-eslint/",
1000
- "ts/"
1038
+ { "@typescript-eslint": "ts" }
1001
1039
  ),
1040
+ ...renameRules(pluginTs.configs.strict.rules, {
1041
+ "@typescript-eslint": "ts"
1042
+ }),
1002
1043
  "no-dupe-class-members": "off",
1003
1044
  "no-loss-of-precision": "off",
1004
1045
  "no-redeclare": "off",
@@ -1698,6 +1739,7 @@ async function tailwindcss(options = {}) {
1698
1739
  "tailwindcss/no-arbitrary-value": "off",
1699
1740
  "tailwindcss/no-contradicting-classname": "error",
1700
1741
  "tailwindcss/no-custom-classname": "off",
1742
+ "tailwindcss/no-unnecessary-arbitrary-value": "warn",
1701
1743
  ...overrides
1702
1744
  }
1703
1745
  }
@@ -1725,8 +1767,16 @@ var flatConfigProps = [
1725
1767
  "rules",
1726
1768
  "settings"
1727
1769
  ];
1770
+ var defaultPluginRenaming = {
1771
+ "@typescript-eslint": "ts",
1772
+ "import-x": "import",
1773
+ n: "node",
1774
+ vitest: "test",
1775
+ yml: "yaml"
1776
+ };
1728
1777
  async function defineConfig(options = {}, ...userConfigs) {
1729
1778
  const {
1779
+ autoRenamePlugins = true,
1730
1780
  componentExts = [],
1731
1781
  gitignore: enableGitignore = true,
1732
1782
  isInEditor: isInEditor2 = isInEditor,
@@ -1861,10 +1911,24 @@ async function defineConfig(options = {}, ...userConfigs) {
1861
1911
  }, {});
1862
1912
  if (Object.keys(fusedConfig).length > 0)
1863
1913
  configs.push([fusedConfig]);
1864
- const merged = combine(...configs, ...userConfigs);
1914
+ const merged = await combine(...configs, ...userConfigs);
1915
+ if (autoRenamePlugins)
1916
+ return renamePluginInConfigs(merged, defaultPluginRenaming);
1865
1917
  return merged;
1866
1918
  }
1867
1919
  // Annotate the CommonJS export names for ESM import in node:
1868
1920
  0 && (module.exports = {
1869
- 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
1870
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";
@@ -146,10 +146,7 @@ async function imports() {
146
146
  ],
147
147
  ...{
148
148
  // format
149
- "import/newline-after-import": [
150
- "error",
151
- { considerComments: true, count: 1 }
152
- ]
149
+ "import/newline-after-import": ["error", { count: 1 }]
153
150
  }
154
151
  }
155
152
  },
@@ -454,15 +451,34 @@ async function combine(...configs) {
454
451
  const resolved = await Promise.all(configs);
455
452
  return resolved.flat();
456
453
  }
457
- function renameRules(rules, from, to) {
454
+ function renameRules(rules, map) {
458
455
  return Object.fromEntries(
459
456
  Object.entries(rules).map(([key, value]) => {
460
- if (key.startsWith(from))
461
- 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
+ }
462
461
  return [key, value];
463
462
  })
464
463
  );
465
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
+ }
466
482
  function getVueVersion() {
467
483
  const pkg = getPackageInfoSync("vue", { paths: [process.cwd()] });
468
484
  if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0]))
@@ -720,6 +736,22 @@ async function sortPackageJson() {
720
736
  {
721
737
  order: ["types", "import", "require", "default"],
722
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)$"
723
755
  }
724
756
  ]
725
757
  }
@@ -957,14 +989,11 @@ async function typescript(options = {}) {
957
989
  rules: {
958
990
  ...renameRules(
959
991
  pluginTs.configs["eslint-recommended"].overrides[0].rules,
960
- "@typescript-eslint/",
961
- "ts/"
962
- ),
963
- ...renameRules(
964
- pluginTs.configs.strict.rules,
965
- "@typescript-eslint/",
966
- "ts/"
992
+ { "@typescript-eslint": "ts" }
967
993
  ),
994
+ ...renameRules(pluginTs.configs.strict.rules, {
995
+ "@typescript-eslint": "ts"
996
+ }),
968
997
  "no-dupe-class-members": "off",
969
998
  "no-loss-of-precision": "off",
970
999
  "no-redeclare": "off",
@@ -1664,6 +1693,7 @@ async function tailwindcss(options = {}) {
1664
1693
  "tailwindcss/no-arbitrary-value": "off",
1665
1694
  "tailwindcss/no-contradicting-classname": "error",
1666
1695
  "tailwindcss/no-custom-classname": "off",
1696
+ "tailwindcss/no-unnecessary-arbitrary-value": "warn",
1667
1697
  ...overrides
1668
1698
  }
1669
1699
  }
@@ -1691,8 +1721,16 @@ var flatConfigProps = [
1691
1721
  "rules",
1692
1722
  "settings"
1693
1723
  ];
1724
+ var defaultPluginRenaming = {
1725
+ "@typescript-eslint": "ts",
1726
+ "import-x": "import",
1727
+ n: "node",
1728
+ vitest: "test",
1729
+ yml: "yaml"
1730
+ };
1694
1731
  async function defineConfig(options = {}, ...userConfigs) {
1695
1732
  const {
1733
+ autoRenamePlugins = true,
1696
1734
  componentExts = [],
1697
1735
  gitignore: enableGitignore = true,
1698
1736
  isInEditor: isInEditor2 = isInEditor,
@@ -1827,9 +1865,23 @@ async function defineConfig(options = {}, ...userConfigs) {
1827
1865
  }, {});
1828
1866
  if (Object.keys(fusedConfig).length > 0)
1829
1867
  configs.push([fusedConfig]);
1830
- const merged = combine(...configs, ...userConfigs);
1868
+ const merged = await combine(...configs, ...userConfigs);
1869
+ if (autoRenamePlugins)
1870
+ return renamePluginInConfigs(merged, defaultPluginRenaming);
1831
1871
  return merged;
1832
1872
  }
1833
1873
  export {
1834
- 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
1835
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.2",
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,27 +68,27 @@
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.1",
76
- "@typescript-eslint/parser": "^7.1.1",
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",
81
+ "eslint-plugin-import-x": "^0.4.1",
82
82
  "eslint-plugin-jsdoc": "^48.2.1",
83
- "eslint-plugin-jsonc": "^2.13.0",
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.6.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.25",
91
+ "eslint-plugin-vitest": "^0.3.26",
92
92
  "eslint-plugin-vue": "^9.23.0",
93
93
  "globals": "^14.0.0",
94
94
  "jsonc-eslint-parser": "^2.4.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.25",
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",
111
+ "@unocss/eslint-plugin": "^0.58.6",
112
112
  "bumpp": "^9.4.0",
113
113
  "eslint": "^8.57.0",
114
- "eslint-flat-config-viewer": "^0.1.11",
115
- "eslint-plugin-react": "^7.34.0",
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
119
  "execa": "^8.0.1",
120
120
  "fast-glob": "^3.3.2",
121
121
  "fs-extra": "^11.2.0",
122
122
  "lint-staged": "^15.2.2",
123
123
  "rimraf": "^5.0.5",
124
- "simple-git-hooks": "^2.10.0",
124
+ "simple-git-hooks": "^2.11.0",
125
125
  "svelte-eslint-parser": "^0.33.1",
126
126
  "tsup": "^8.0.2",
127
127
  "tsx": "^4.7.1",
128
- "typescript": "^5.3.3"
128
+ "typescript": "^5.4.3"
129
129
  },
130
130
  "simple-git-hooks": {
131
131
  "pre-commit": "pnpx nano-staged"