Skip to content

Commit 66f5ee0

Browse files
committed
feat: add option features.import.plugin to swap plugin implementation, close #587
1 parent 920215b commit 66f5ee0

File tree

5 files changed

+284
-7
lines changed

5 files changed

+284
-7
lines changed

packages/eslint-config/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@
3636
},
3737
"peerDependencies": {
3838
"eslint": "^9.0.0",
39-
"eslint-plugin-format": "*"
39+
"eslint-plugin-format": "*",
40+
"eslint-plugin-import-x": "*"
4041
},
4142
"peerDependenciesMeta": {
4243
"eslint-plugin-format": {
4344
"optional": true
45+
},
46+
"eslint-plugin-import-x": {
47+
"optional": true
4448
}
4549
},
4650
"dependencies": {

packages/eslint-config/src/configs/import.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@ import type { Linter } from 'eslint'
33
import type { NuxtESLintConfigOptions } from '../types'
44
import { resolveOptions } from '../utils'
55

6-
export default function imports(options: NuxtESLintConfigOptions): Linter.Config[] {
6+
export default async function imports(options: NuxtESLintConfigOptions): Promise<Linter.Config[]> {
77
const resolved = resolveOptions(options)
88

9+
if (resolved.features.import === false) {
10+
return []
11+
}
12+
13+
const importOptions = resolved.features.import === true
14+
? {}
15+
: resolved.features.import || {}
16+
17+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
18+
const plugin: any = importOptions.package === 'eslint-plugin-import-x'
19+
? (await import('eslint-plugin-import-x')).default
20+
: pluginImportLite
21+
922
return [
1023
{
1124
name: 'nuxt/import/rules',
1225
plugins: {
13-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14-
import: pluginImportLite as any,
26+
import: plugin,
1527
},
1628
rules: {
1729
'import/consistent-type-specifier-style': ['error', 'top-level'],

packages/eslint-config/src/types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export interface NuxtESLintFeaturesOptions {
5050
*/
5151
tooling?: boolean | ToolingOptions
5252

53+
/**
54+
* Enable the import plugin
55+
*
56+
* @default true
57+
*/
58+
import?: boolean | ImportPluginOptions
59+
5360
/**
5461
* Enable stylistic ESLint rules for formatting and code style check
5562
*
@@ -91,6 +98,18 @@ export interface NuxtESLintFeaturesOptions {
9198
}
9299
}
93100

101+
export interface ImportPluginOptions {
102+
/**
103+
* The import plugin to use
104+
*
105+
* We did not ship `eslint-plugin-import-x` as dependency,
106+
* if you want to use it, you need to install it manually.
107+
*
108+
* @default 'eslint-plugin-import-lite'
109+
*/
110+
package?: 'eslint-plugin-import-lite' | 'eslint-plugin-import-x'
111+
}
112+
94113
export interface NuxtESLintConfigOptions {
95114
features?: NuxtESLintFeaturesOptions
96115

packages/eslint-config/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export function resolveOptions(
8181
tooling: false,
8282
formatters: false,
8383
nuxt: {},
84+
import: {},
8485
...config.features,
8586
},
8687
dirs,

0 commit comments

Comments
 (0)