Skip to content

Commit f8f0f47

Browse files
committed
feat: automatically rename plugins in factory
1 parent b195ca9 commit f8f0f47

File tree

8 files changed

+195
-69
lines changed

8 files changed

+195
-69
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"eslint-config-prettier": "^9.1.0",
8989
"eslint-plugin-antfu": "^2.1.2",
9090
"eslint-plugin-eslint-comments": "^3.2.0",
91-
"eslint-plugin-i": "^2.29.1",
91+
"eslint-plugin-import-x": "^0.4.1",
9292
"eslint-plugin-jsdoc": "^48.2.1",
9393
"eslint-plugin-jsonc": "^2.13.0",
9494
"eslint-plugin-n": "^16.6.2",

pnpm-lock.yaml

Lines changed: 108 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/configs/typescript.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,11 @@ export async function typescript(
107107
rules: {
108108
...renameRules(
109109
pluginTs.configs['eslint-recommended'].overrides![0].rules!,
110-
'@typescript-eslint/',
111-
'ts/',
112-
),
113-
...renameRules(
114-
pluginTs.configs.strict.rules!,
115-
'@typescript-eslint/',
116-
'ts/',
110+
{ '@typescript-eslint': 'ts' },
117111
),
112+
...renameRules(pluginTs.configs.strict.rules!, {
113+
'@typescript-eslint': 'ts',
114+
}),
118115
'no-dupe-class-members': 'off',
119116
'no-loss-of-precision': 'off',
120117
'no-redeclare': 'off',

src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
getOverrides,
2929
interopDefault,
3030
loadPrettierConfig,
31+
renamePluginInConfigs,
3132
resolveSubOptions,
3233
} from './shared'
3334
import {
@@ -55,6 +56,14 @@ const flatConfigProps: (keyof FlatConfigItem)[] = [
5556
'settings',
5657
]
5758

59+
export const defaultPluginRenaming = {
60+
'@typescript-eslint': 'ts',
61+
'import-x': 'import',
62+
n: 'node',
63+
vitest: 'test',
64+
yml: 'yaml',
65+
}
66+
5867
/**
5968
* Construct an array of ESLint flat config items.
6069
*
@@ -70,6 +79,7 @@ export async function defineConfig(
7079
...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]
7180
): Promise<UserConfigItem[]> {
7281
const {
82+
autoRenamePlugins = true,
7383
componentExts = [],
7484
gitignore: enableGitignore = true,
7585
isInEditor = defaultIsInEditor,
@@ -222,7 +232,13 @@ export async function defineConfig(
222232
}, {} as FlatConfigItem)
223233
if (Object.keys(fusedConfig).length > 0) configs.push([fusedConfig])
224234

225-
const merged = combine(...configs, ...userConfigs)
235+
const merged = await combine(...configs, ...userConfigs)
236+
237+
if (autoRenamePlugins)
238+
return renamePluginInConfigs(merged, defaultPluginRenaming)
226239

227240
return merged
228241
}
242+
243+
export * from './shared'
244+
export * from './types'

src/plugins/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
export { default as pluginAntfu } from 'eslint-plugin-antfu'
55
export { default as pluginComments } from 'eslint-plugin-eslint-comments'
6-
export * as pluginImport from 'eslint-plugin-i'
6+
export * as pluginImport from 'eslint-plugin-import-x'
77
export { default as pluginNode } from 'eslint-plugin-n'
88
export { default as pluginUnicorn } from 'eslint-plugin-unicorn'
99
export { default as pluginUnusedImports } from 'eslint-plugin-unused-imports'

0 commit comments

Comments
 (0)