@antfu/eslint-config 2.8.3 → 2.9.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/README.md CHANGED
@@ -278,7 +278,7 @@ Since flat config requires us to explicitly provide the plugin names (instead of
278
278
 
279
279
  | New Prefix | Original Prefix | Source Plugin |
280
280
  | ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
281
- | `import/*` | `i/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
281
+ | `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
282
282
  | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
283
283
  | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
284
284
  | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
@@ -294,6 +294,15 @@ When you want to override rules, or disable them inline, you need to update to t
294
294
  type foo = { bar: 2 }
295
295
  ```
296
296
 
297
+ > [!NOTE]
298
+ > About plugin renaming - it is actually rather a dangrous move that might leading to potential naming collisions, pointed out [here](https://github.com/eslint/eslint/discussions/17766) and [here](https://github.com/prettier/eslint-config-prettier#eslintconfigjs-flat-config-plugin-caveat). As this config also very **personal** and **opinionated**, I ambitiously poisition this config as the only **"top-level"** config per project, that might pivots the taste of how rules are named.
299
+ >
300
+ > This config cares more about the user-facings DX, and try to ease out the implementation details. For example, users could keep using the semantic `import/order` without ever knowing the underlying plugin has migrated twice to `eslint-plugin-i` and then to `eslint-plugin-import-x`. User are also not forced to migrate to the implicit `i/order` halfway only because we swapped the implementation to a fork.
301
+ >
302
+ > That said, it's probably still not a good idea. You might not want to doing this if you are maintaining your own eslint config.
303
+ >
304
+ > Feel free to open issues if you want to combine this config with some other config presets but faced naming collisions. I am happy to figure out a way to make them work. But at this moment I have no plan to revert the renaming.
305
+
297
306
  ### Rules Overrides
298
307
 
299
308
  Certain rules would only be enabled in specific files, for example, `ts/*` rules would only be enabled in `.ts` files and `vue/*` rules would only be enabled in `.vue` files. If you want to override the rules, you need to specify the file extension:
@@ -504,6 +513,21 @@ export default antfu({
504
513
  })
505
514
  ```
506
515
 
516
+ ### Editor Specific Disables
517
+
518
+ Some rules are disabled when inside ESLint IDE integrations, namely [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports) [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
519
+
520
+ This is to prevent unused imports from getting removed by the IDE during refactoring to get a better developer experience. Those rules will be applied when you run ESLint in the terminal or [Lint Staged](#lint-staged). If you don't want this behavior, you can disable them:
521
+
522
+ ```js
523
+ // eslint.config.js
524
+ import antfu from '@antfu/eslint-config'
525
+
526
+ export default antfu({
527
+ isInEditor: false
528
+ })
529
+ ```
530
+
507
531
  ### Lint Staged
508
532
 
509
533
  If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
package/dist/cli.cjs CHANGED
@@ -48,7 +48,7 @@ var import_picocolors = __toESM(require("picocolors"), 1);
48
48
  var package_default = {
49
49
  name: "@antfu/eslint-config",
50
50
  type: "module",
51
- version: "2.8.3",
51
+ version: "2.9.0",
52
52
  packageManager: "pnpm@8.15.4",
53
53
  description: "Anthony's ESLint config",
54
54
  author: "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
@@ -146,7 +146,7 @@ var package_default = {
146
146
  "eslint-merge-processors": "^0.1.0",
147
147
  "eslint-plugin-antfu": "^2.1.2",
148
148
  "eslint-plugin-eslint-comments": "^3.2.0",
149
- "eslint-plugin-i": "^2.29.1",
149
+ "eslint-plugin-import-x": "^0.4.1",
150
150
  "eslint-plugin-jsdoc": "^48.2.1",
151
151
  "eslint-plugin-jsonc": "^2.13.0",
152
152
  "eslint-plugin-markdown": "^4.0.1",
@@ -497,7 +497,7 @@ async function run(options = {}) {
497
497
  result = await p4.group({
498
498
  uncommittedConfirmed: () => {
499
499
  if (argSkipPrompt || isGitClean())
500
- return;
500
+ return Promise.resolve(true);
501
501
  return p4.confirm({
502
502
  initialValue: false,
503
503
  message: "There are uncommitted changes in the current repository, are you sure to continue?"
package/dist/cli.js CHANGED
@@ -19,7 +19,7 @@ import c from "picocolors";
19
19
  var package_default = {
20
20
  name: "@antfu/eslint-config",
21
21
  type: "module",
22
- version: "2.8.3",
22
+ version: "2.9.0",
23
23
  packageManager: "pnpm@8.15.4",
24
24
  description: "Anthony's ESLint config",
25
25
  author: "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
@@ -117,7 +117,7 @@ var package_default = {
117
117
  "eslint-merge-processors": "^0.1.0",
118
118
  "eslint-plugin-antfu": "^2.1.2",
119
119
  "eslint-plugin-eslint-comments": "^3.2.0",
120
- "eslint-plugin-i": "^2.29.1",
120
+ "eslint-plugin-import-x": "^0.4.1",
121
121
  "eslint-plugin-jsdoc": "^48.2.1",
122
122
  "eslint-plugin-jsonc": "^2.13.0",
123
123
  "eslint-plugin-markdown": "^4.0.1",
@@ -468,7 +468,7 @@ async function run(options = {}) {
468
468
  result = await p4.group({
469
469
  uncommittedConfirmed: () => {
470
470
  if (argSkipPrompt || isGitClean())
471
- return;
471
+ return Promise.resolve(true);
472
472
  return p4.confirm({
473
473
  initialValue: false,
474
474
  message: "There are uncommitted changes in the current repository, are you sure to continue?"
package/dist/index.cjs CHANGED
@@ -62,6 +62,7 @@ __export(src_exports, {
62
62
  combine: () => combine,
63
63
  comments: () => comments,
64
64
  default: () => src_default,
65
+ defaultPluginRenaming: () => defaultPluginRenaming,
65
66
  ensurePackages: () => ensurePackages,
66
67
  formatters: () => formatters,
67
68
  getOverrides: () => getOverrides,
@@ -76,6 +77,7 @@ __export(src_exports, {
76
77
  parserPlain: () => parserPlain,
77
78
  perfectionist: () => perfectionist,
78
79
  react: () => react,
80
+ renamePluginInConfigs: () => renamePluginInConfigs,
79
81
  renameRules: () => renameRules,
80
82
  resolveSubOptions: () => resolveSubOptions,
81
83
  sortPackageJson: () => sortPackageJson,
@@ -101,7 +103,7 @@ var import_local_pkg4 = require("local-pkg");
101
103
  // src/plugins.ts
102
104
  var import_eslint_plugin_antfu = __toESM(require("eslint-plugin-antfu"), 1);
103
105
  var import_eslint_plugin_eslint_comments = __toESM(require("eslint-plugin-eslint-comments"), 1);
104
- var pluginImport = __toESM(require("eslint-plugin-i"), 1);
106
+ var pluginImport = __toESM(require("eslint-plugin-import-x"), 1);
105
107
  var import_eslint_plugin_n = __toESM(require("eslint-plugin-n"), 1);
106
108
  var import_eslint_plugin_unicorn = __toESM(require("eslint-plugin-unicorn"), 1);
107
109
  var import_eslint_plugin_unused_imports = __toESM(require("eslint-plugin-unused-imports"), 1);
@@ -490,15 +492,34 @@ async function combine(...configs) {
490
492
  const resolved = await Promise.all(configs);
491
493
  return resolved.flat();
492
494
  }
493
- function renameRules(rules, from, to) {
495
+ function renameRules(rules, map) {
494
496
  return Object.fromEntries(
495
497
  Object.entries(rules).map(([key, value]) => {
496
- if (key.startsWith(from))
497
- return [to + key.slice(from.length), value];
498
+ for (const [from, to] of Object.entries(map)) {
499
+ if (key.startsWith(`${from}/`))
500
+ return [to + key.slice(from.length), value];
501
+ }
498
502
  return [key, value];
499
503
  })
500
504
  );
501
505
  }
506
+ function renamePluginInConfigs(configs, map) {
507
+ return configs.map((i) => {
508
+ const clone = { ...i };
509
+ if (clone.rules)
510
+ clone.rules = renameRules(clone.rules, map);
511
+ if (clone.plugins) {
512
+ clone.plugins = Object.fromEntries(
513
+ Object.entries(clone.plugins).map(([key, value]) => {
514
+ if (key in map)
515
+ return [map[key], value];
516
+ return [key, value];
517
+ })
518
+ );
519
+ }
520
+ return clone;
521
+ });
522
+ }
502
523
  function toArray(value) {
503
524
  return Array.isArray(value) ? value : [value];
504
525
  }
@@ -1202,6 +1223,22 @@ async function sortPackageJson() {
1202
1223
  "default"
1203
1224
  ],
1204
1225
  pathPattern: "^exports.*$"
1226
+ },
1227
+ {
1228
+ order: [
1229
+ // client hooks only
1230
+ "pre-commit",
1231
+ "prepare-commit-msg",
1232
+ "commit-msg",
1233
+ "post-commit",
1234
+ "pre-rebase",
1235
+ "post-rewrite",
1236
+ "post-checkout",
1237
+ "post-merge",
1238
+ "pre-push",
1239
+ "pre-auto-gc"
1240
+ ],
1241
+ pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
1205
1242
  }
1206
1243
  ]
1207
1244
  }
@@ -1557,13 +1594,11 @@ async function typescript(options = {}) {
1557
1594
  rules: {
1558
1595
  ...renameRules(
1559
1596
  pluginTs.configs["eslint-recommended"].overrides[0].rules,
1560
- "@typescript-eslint/",
1561
- "ts/"
1597
+ { "@typescript-eslint": "ts" }
1562
1598
  ),
1563
1599
  ...renameRules(
1564
1600
  pluginTs.configs.strict.rules,
1565
- "@typescript-eslint/",
1566
- "ts/"
1601
+ { "@typescript-eslint": "ts" }
1567
1602
  ),
1568
1603
  "no-dupe-class-members": "off",
1569
1604
  "no-loss-of-precision": "off",
@@ -2056,9 +2091,18 @@ var VuePackages = [
2056
2091
  "vitepress",
2057
2092
  "@slidev/cli"
2058
2093
  ];
2094
+ var defaultPluginRenaming = {
2095
+ "@stylistic": "style",
2096
+ "@typescript-eslint": "ts",
2097
+ "import-x": "import",
2098
+ "n": "node",
2099
+ "vitest": "test",
2100
+ "yml": "yaml"
2101
+ };
2059
2102
  async function antfu(options = {}, ...userConfigs) {
2060
2103
  const {
2061
2104
  astro: enableAstro = false,
2105
+ autoRenamePlugins = true,
2062
2106
  componentExts = [],
2063
2107
  gitignore: enableGitignore = true,
2064
2108
  isInEditor = !!((import_node_process3.default.env.VSCODE_PID || import_node_process3.default.env.VSCODE_CWD || import_node_process3.default.env.JETBRAINS_IDE || import_node_process3.default.env.VIM) && !import_node_process3.default.env.CI),
@@ -2197,10 +2241,12 @@ async function antfu(options = {}, ...userConfigs) {
2197
2241
  }, {});
2198
2242
  if (Object.keys(fusedConfig).length)
2199
2243
  configs.push([fusedConfig]);
2200
- const merged = combine(
2244
+ const merged = await combine(
2201
2245
  ...configs,
2202
2246
  ...userConfigs
2203
2247
  );
2248
+ if (autoRenamePlugins)
2249
+ return renamePluginInConfigs(merged, defaultPluginRenaming);
2204
2250
  return merged;
2205
2251
  }
2206
2252
  function resolveSubOptions(options, key) {
@@ -2249,6 +2295,7 @@ var src_default = antfu;
2249
2295
  astro,
2250
2296
  combine,
2251
2297
  comments,
2298
+ defaultPluginRenaming,
2252
2299
  ensurePackages,
2253
2300
  formatters,
2254
2301
  getOverrides,
@@ -2263,6 +2310,7 @@ var src_default = antfu;
2263
2310
  parserPlain,
2264
2311
  perfectionist,
2265
2312
  react,
2313
+ renamePluginInConfigs,
2266
2314
  renameRules,
2267
2315
  resolveSubOptions,
2268
2316
  sortPackageJson,
package/dist/index.d.cts CHANGED
@@ -388,6 +388,12 @@ interface OptionsConfig extends OptionsComponentExts {
388
388
  * @default auto-detect based on the process.env
389
389
  */
390
390
  isInEditor?: boolean;
391
+ /**
392
+ * Automatically rename plugins in the config.
393
+ *
394
+ * @default true
395
+ */
396
+ autoRenamePlugins?: boolean;
391
397
  /**
392
398
  * Provide overrides for rules for each integration.
393
399
  *
@@ -408,6 +414,14 @@ interface OptionsConfig extends OptionsComponentExts {
408
414
  };
409
415
  }
410
416
 
417
+ declare const defaultPluginRenaming: {
418
+ '@stylistic': string;
419
+ '@typescript-eslint': string;
420
+ 'import-x': string;
421
+ n: string;
422
+ vitest: string;
423
+ yml: string;
424
+ };
411
425
  /**
412
426
  * Construct an array of ESLint flat config items.
413
427
  *
@@ -540,13 +554,46 @@ declare const parserPlain: {
540
554
  * Combine array and non-array configs into a single array.
541
555
  */
542
556
  declare function combine(...configs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
543
- declare function renameRules(rules: Record<string, any>, from: string, to: string): {
557
+ /**
558
+ * Rename plugin prefixes in a rule object.
559
+ * Accepts a map of prefixes to rename.
560
+ *
561
+ * @example
562
+ * ```ts
563
+ * import { renameRules } from '@antfu/eslint-config'
564
+ *
565
+ * export default [{
566
+ * rules: renameRules(
567
+ * {
568
+ * '@typescript-eslint/indent': 'error'
569
+ * },
570
+ * { '@typescript-eslint': 'ts' }
571
+ * )
572
+ * }]
573
+ * ```
574
+ */
575
+ declare function renameRules(rules: Record<string, any>, map: Record<string, string>): {
544
576
  [k: string]: any;
545
577
  };
578
+ /**
579
+ * Rename plugin names a flat configs array
580
+ *
581
+ * @example
582
+ * ```ts
583
+ * import { renamePluginInConfigs } from '@antfu/eslint-config'
584
+ * import someConfigs from './some-configs'
585
+ *
586
+ * export default renamePluginInConfigs(someConfigs, {
587
+ * '@typescript-eslint': 'ts',
588
+ * 'import-x': 'import',
589
+ * })
590
+ * ```
591
+ */
592
+ declare function renamePluginInConfigs(configs: UserConfigItem[], map: Record<string, string>): UserConfigItem[];
546
593
  declare function toArray<T>(value: T | T[]): T[];
547
594
  declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
548
595
  default: infer U;
549
596
  } ? U : T>;
550
597
  declare function ensurePackages(packages: (string | undefined)[]): Promise<void>;
551
598
 
552
- export { type Awaitable, type FlatConfigItem, GLOB_ALL_SRC, GLOB_ASTRO, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVELTE, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_YAML, type OptionsComponentExts, type OptionsConfig, type OptionsFiles, type OptionsFormatters, type OptionsHasTypeScript, type OptionsIsInEditor, type OptionsOverrides, type OptionsStylistic, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type OptionsTypescript, type OptionsUnoCSS, type OptionsVue, type ResolvedOptions, type Rules, type StylisticConfig, StylisticConfigDefaults, type UserConfigItem, type WrapRuleConfig, antfu, astro, combine, comments, antfu as default, ensurePackages, formatters, getOverrides, ignores, imports, interopDefault, javascript, jsdoc, jsonc, markdown, node, parserPlain, perfectionist, react, renameRules, resolveSubOptions, sortPackageJson, sortTsconfig, stylistic, svelte, test, toArray, toml, typescript, unicorn, unocss, vue, yaml };
599
+ export { type Awaitable, type FlatConfigItem, GLOB_ALL_SRC, GLOB_ASTRO, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVELTE, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_YAML, type OptionsComponentExts, type OptionsConfig, type OptionsFiles, type OptionsFormatters, type OptionsHasTypeScript, type OptionsIsInEditor, type OptionsOverrides, type OptionsStylistic, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type OptionsTypescript, type OptionsUnoCSS, type OptionsVue, type ResolvedOptions, type Rules, type StylisticConfig, StylisticConfigDefaults, type UserConfigItem, type WrapRuleConfig, antfu, astro, combine, comments, antfu as default, defaultPluginRenaming, ensurePackages, formatters, getOverrides, ignores, imports, interopDefault, javascript, jsdoc, jsonc, markdown, node, parserPlain, perfectionist, react, renamePluginInConfigs, renameRules, resolveSubOptions, sortPackageJson, sortTsconfig, stylistic, svelte, test, toArray, toml, typescript, unicorn, unocss, vue, yaml };
package/dist/index.d.ts CHANGED
@@ -388,6 +388,12 @@ interface OptionsConfig extends OptionsComponentExts {
388
388
  * @default auto-detect based on the process.env
389
389
  */
390
390
  isInEditor?: boolean;
391
+ /**
392
+ * Automatically rename plugins in the config.
393
+ *
394
+ * @default true
395
+ */
396
+ autoRenamePlugins?: boolean;
391
397
  /**
392
398
  * Provide overrides for rules for each integration.
393
399
  *
@@ -408,6 +414,14 @@ interface OptionsConfig extends OptionsComponentExts {
408
414
  };
409
415
  }
410
416
 
417
+ declare const defaultPluginRenaming: {
418
+ '@stylistic': string;
419
+ '@typescript-eslint': string;
420
+ 'import-x': string;
421
+ n: string;
422
+ vitest: string;
423
+ yml: string;
424
+ };
411
425
  /**
412
426
  * Construct an array of ESLint flat config items.
413
427
  *
@@ -540,13 +554,46 @@ declare const parserPlain: {
540
554
  * Combine array and non-array configs into a single array.
541
555
  */
542
556
  declare function combine(...configs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
543
- declare function renameRules(rules: Record<string, any>, from: string, to: string): {
557
+ /**
558
+ * Rename plugin prefixes in a rule object.
559
+ * Accepts a map of prefixes to rename.
560
+ *
561
+ * @example
562
+ * ```ts
563
+ * import { renameRules } from '@antfu/eslint-config'
564
+ *
565
+ * export default [{
566
+ * rules: renameRules(
567
+ * {
568
+ * '@typescript-eslint/indent': 'error'
569
+ * },
570
+ * { '@typescript-eslint': 'ts' }
571
+ * )
572
+ * }]
573
+ * ```
574
+ */
575
+ declare function renameRules(rules: Record<string, any>, map: Record<string, string>): {
544
576
  [k: string]: any;
545
577
  };
578
+ /**
579
+ * Rename plugin names a flat configs array
580
+ *
581
+ * @example
582
+ * ```ts
583
+ * import { renamePluginInConfigs } from '@antfu/eslint-config'
584
+ * import someConfigs from './some-configs'
585
+ *
586
+ * export default renamePluginInConfigs(someConfigs, {
587
+ * '@typescript-eslint': 'ts',
588
+ * 'import-x': 'import',
589
+ * })
590
+ * ```
591
+ */
592
+ declare function renamePluginInConfigs(configs: UserConfigItem[], map: Record<string, string>): UserConfigItem[];
546
593
  declare function toArray<T>(value: T | T[]): T[];
547
594
  declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
548
595
  default: infer U;
549
596
  } ? U : T>;
550
597
  declare function ensurePackages(packages: (string | undefined)[]): Promise<void>;
551
598
 
552
- export { type Awaitable, type FlatConfigItem, GLOB_ALL_SRC, GLOB_ASTRO, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVELTE, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_YAML, type OptionsComponentExts, type OptionsConfig, type OptionsFiles, type OptionsFormatters, type OptionsHasTypeScript, type OptionsIsInEditor, type OptionsOverrides, type OptionsStylistic, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type OptionsTypescript, type OptionsUnoCSS, type OptionsVue, type ResolvedOptions, type Rules, type StylisticConfig, StylisticConfigDefaults, type UserConfigItem, type WrapRuleConfig, antfu, astro, combine, comments, antfu as default, ensurePackages, formatters, getOverrides, ignores, imports, interopDefault, javascript, jsdoc, jsonc, markdown, node, parserPlain, perfectionist, react, renameRules, resolveSubOptions, sortPackageJson, sortTsconfig, stylistic, svelte, test, toArray, toml, typescript, unicorn, unocss, vue, yaml };
599
+ export { type Awaitable, type FlatConfigItem, GLOB_ALL_SRC, GLOB_ASTRO, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVELTE, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_YAML, type OptionsComponentExts, type OptionsConfig, type OptionsFiles, type OptionsFormatters, type OptionsHasTypeScript, type OptionsIsInEditor, type OptionsOverrides, type OptionsStylistic, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type OptionsTypescript, type OptionsUnoCSS, type OptionsVue, type ResolvedOptions, type Rules, type StylisticConfig, StylisticConfigDefaults, type UserConfigItem, type WrapRuleConfig, antfu, astro, combine, comments, antfu as default, defaultPluginRenaming, ensurePackages, formatters, getOverrides, ignores, imports, interopDefault, javascript, jsdoc, jsonc, markdown, node, parserPlain, perfectionist, react, renamePluginInConfigs, renameRules, resolveSubOptions, sortPackageJson, sortTsconfig, stylistic, svelte, test, toArray, toml, typescript, unicorn, unocss, vue, yaml };
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { isPackageExists as isPackageExists4 } from "local-pkg";
6
6
  // src/plugins.ts
7
7
  import { default as default2 } from "eslint-plugin-antfu";
8
8
  import { default as default3 } from "eslint-plugin-eslint-comments";
9
- import * as pluginImport from "eslint-plugin-i";
9
+ import * as pluginImport from "eslint-plugin-import-x";
10
10
  import { default as default4 } from "eslint-plugin-n";
11
11
  import { default as default5 } from "eslint-plugin-unicorn";
12
12
  import { default as default6 } from "eslint-plugin-unused-imports";
@@ -395,15 +395,34 @@ async function combine(...configs) {
395
395
  const resolved = await Promise.all(configs);
396
396
  return resolved.flat();
397
397
  }
398
- function renameRules(rules, from, to) {
398
+ function renameRules(rules, map) {
399
399
  return Object.fromEntries(
400
400
  Object.entries(rules).map(([key, value]) => {
401
- if (key.startsWith(from))
402
- return [to + key.slice(from.length), value];
401
+ for (const [from, to] of Object.entries(map)) {
402
+ if (key.startsWith(`${from}/`))
403
+ return [to + key.slice(from.length), value];
404
+ }
403
405
  return [key, value];
404
406
  })
405
407
  );
406
408
  }
409
+ function renamePluginInConfigs(configs, map) {
410
+ return configs.map((i) => {
411
+ const clone = { ...i };
412
+ if (clone.rules)
413
+ clone.rules = renameRules(clone.rules, map);
414
+ if (clone.plugins) {
415
+ clone.plugins = Object.fromEntries(
416
+ Object.entries(clone.plugins).map(([key, value]) => {
417
+ if (key in map)
418
+ return [map[key], value];
419
+ return [key, value];
420
+ })
421
+ );
422
+ }
423
+ return clone;
424
+ });
425
+ }
407
426
  function toArray(value) {
408
427
  return Array.isArray(value) ? value : [value];
409
428
  }
@@ -1107,6 +1126,22 @@ async function sortPackageJson() {
1107
1126
  "default"
1108
1127
  ],
1109
1128
  pathPattern: "^exports.*$"
1129
+ },
1130
+ {
1131
+ order: [
1132
+ // client hooks only
1133
+ "pre-commit",
1134
+ "prepare-commit-msg",
1135
+ "commit-msg",
1136
+ "post-commit",
1137
+ "pre-rebase",
1138
+ "post-rewrite",
1139
+ "post-checkout",
1140
+ "post-merge",
1141
+ "pre-push",
1142
+ "pre-auto-gc"
1143
+ ],
1144
+ pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
1110
1145
  }
1111
1146
  ]
1112
1147
  }
@@ -1462,13 +1497,11 @@ async function typescript(options = {}) {
1462
1497
  rules: {
1463
1498
  ...renameRules(
1464
1499
  pluginTs.configs["eslint-recommended"].overrides[0].rules,
1465
- "@typescript-eslint/",
1466
- "ts/"
1500
+ { "@typescript-eslint": "ts" }
1467
1501
  ),
1468
1502
  ...renameRules(
1469
1503
  pluginTs.configs.strict.rules,
1470
- "@typescript-eslint/",
1471
- "ts/"
1504
+ { "@typescript-eslint": "ts" }
1472
1505
  ),
1473
1506
  "no-dupe-class-members": "off",
1474
1507
  "no-loss-of-precision": "off",
@@ -1961,9 +1994,18 @@ var VuePackages = [
1961
1994
  "vitepress",
1962
1995
  "@slidev/cli"
1963
1996
  ];
1997
+ var defaultPluginRenaming = {
1998
+ "@stylistic": "style",
1999
+ "@typescript-eslint": "ts",
2000
+ "import-x": "import",
2001
+ "n": "node",
2002
+ "vitest": "test",
2003
+ "yml": "yaml"
2004
+ };
1964
2005
  async function antfu(options = {}, ...userConfigs) {
1965
2006
  const {
1966
2007
  astro: enableAstro = false,
2008
+ autoRenamePlugins = true,
1967
2009
  componentExts = [],
1968
2010
  gitignore: enableGitignore = true,
1969
2011
  isInEditor = !!((process3.env.VSCODE_PID || process3.env.VSCODE_CWD || process3.env.JETBRAINS_IDE || process3.env.VIM) && !process3.env.CI),
@@ -2102,10 +2144,12 @@ async function antfu(options = {}, ...userConfigs) {
2102
2144
  }, {});
2103
2145
  if (Object.keys(fusedConfig).length)
2104
2146
  configs.push([fusedConfig]);
2105
- const merged = combine(
2147
+ const merged = await combine(
2106
2148
  ...configs,
2107
2149
  ...userConfigs
2108
2150
  );
2151
+ if (autoRenamePlugins)
2152
+ return renamePluginInConfigs(merged, defaultPluginRenaming);
2109
2153
  return merged;
2110
2154
  }
2111
2155
  function resolveSubOptions(options, key) {
@@ -2154,6 +2198,7 @@ export {
2154
2198
  combine,
2155
2199
  comments,
2156
2200
  src_default as default,
2201
+ defaultPluginRenaming,
2157
2202
  ensurePackages,
2158
2203
  formatters,
2159
2204
  getOverrides,
@@ -2168,6 +2213,7 @@ export {
2168
2213
  parserPlain,
2169
2214
  perfectionist,
2170
2215
  react,
2216
+ renamePluginInConfigs,
2171
2217
  renameRules,
2172
2218
  resolveSubOptions,
2173
2219
  sortPackageJson,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antfu/eslint-config",
3
3
  "type": "module",
4
- "version": "2.8.3",
4
+ "version": "2.9.0",
5
5
  "packageManager": "pnpm@8.15.4",
6
6
  "description": "Anthony's ESLint config",
7
7
  "author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
@@ -87,7 +87,7 @@
87
87
  "eslint-merge-processors": "^0.1.0",
88
88
  "eslint-plugin-antfu": "^2.1.2",
89
89
  "eslint-plugin-eslint-comments": "^3.2.0",
90
- "eslint-plugin-i": "^2.29.1",
90
+ "eslint-plugin-import-x": "^0.4.1",
91
91
  "eslint-plugin-jsdoc": "^48.2.1",
92
92
  "eslint-plugin-jsonc": "^2.13.0",
93
93
  "eslint-plugin-markdown": "^4.0.1",
@@ -147,7 +147,7 @@
147
147
  "typescript": "^5.4.2",
148
148
  "vitest": "^1.3.1",
149
149
  "vue": "^3.4.21",
150
- "@antfu/eslint-config": "2.8.3"
150
+ "@antfu/eslint-config": "2.9.0"
151
151
  },
152
152
  "simple-git-hooks": {
153
153
  "pre-commit": "pnpm lint-staged"