@@ -3,24 +3,31 @@ import type { ESLint } from "eslint";
3
3
import { GLOB_DTS , GLOB_MJS , GLOB_MTS , GLOB_TS , GLOB_TSX } from "../globs" ;
4
4
import type {
5
5
FlatConfigItem ,
6
+ OptionsHasTypeScript ,
6
7
OptionsTypeScriptParserOptions ,
7
8
RequiredOptionsStylistic ,
8
9
} from "../types" ;
9
10
import { loadPackages } from "../utils" ;
10
11
11
12
export async function imports (
12
13
options : Readonly <
13
- Required < RequiredOptionsStylistic & OptionsTypeScriptParserOptions >
14
+ Required <
15
+ RequiredOptionsStylistic &
16
+ OptionsTypeScriptParserOptions &
17
+ OptionsHasTypeScript
18
+ >
14
19
> ,
15
20
) : Promise < FlatConfigItem [ ] > {
16
- const { stylistic, parserOptions } = options ;
21
+ const { stylistic, parserOptions, typescript } = options ;
17
22
18
- const [ pluginImport ] = ( await loadPackages ( [
19
- "eslint-plugin-import-x" ,
20
- "eslint-import-resolver-typescript" ,
21
- ] ) ) as [ ESLint . Plugin , ESLint . Plugin ] ;
22
-
23
- const stylisticEnforcement = stylistic === false ? "off" : "error" ;
23
+ const [ pluginImport ] = ( await loadPackages (
24
+ typescript
25
+ ? [
26
+ "eslint-plugin-import-x" ,
27
+ "eslint-import-resolver-typescript" , // make sure it exists - we only implicitly use it
28
+ ]
29
+ : [ "eslint-plugin-import-x" ] ,
30
+ ) ) as [ ESLint . Plugin ] | [ ESLint . Plugin , unknown ] ;
24
31
25
32
return [
26
33
{
@@ -36,16 +43,24 @@ export async function imports(
36
43
"import-x/internal-regex" : "^(?:#|(?:@|~)\\/).*" ,
37
44
"import-x/extensions" : [ ".ts" , ".tsx" , ".js" , ".jsx" ] ,
38
45
"import-x/parsers" : {
39
- "@typescript-eslint/parser" : [ ".ts" , ".tsx" , ".cts" , ".mts" ] ,
46
+ ...( typescript
47
+ ? {
48
+ "@typescript-eslint/parser" : [ ".ts" , ".tsx" , ".cts" , ".mts" ] ,
49
+ }
50
+ : undefined ) ,
40
51
} ,
41
52
"import-x/resolver" : {
42
- typescript : {
43
- alwaysTryTypes : true ,
44
- projectService : parserOptions . projectService ,
45
- } ,
46
53
node : {
47
54
extensions : [ ".ts" , ".tsx" , ".js" , ".jsx" ] ,
48
55
} ,
56
+ ...( typescript
57
+ ? {
58
+ typescript : {
59
+ alwaysTryTypes : true ,
60
+ projectService : parserOptions . projectService ,
61
+ } ,
62
+ }
63
+ : undefined ) ,
49
64
} ,
50
65
} ,
51
66
rules : {
@@ -139,9 +154,12 @@ export async function imports(
139
154
// "import/prefer-default-export": "off",
140
155
// "import/unambiguous": "off",
141
156
142
- "import/newline-after-import" : [ stylisticEnforcement , { count : 1 } ] ,
157
+ "import/newline-after-import" : [
158
+ stylistic === false ? "off" : "error" ,
159
+ { count : 1 } ,
160
+ ] ,
143
161
"import/order" : [
144
- stylisticEnforcement ,
162
+ stylistic === false ? "off" : "error" ,
145
163
{
146
164
alphabetize : {
147
165
caseInsensitive : false ,
@@ -167,24 +185,28 @@ export async function imports(
167
185
"import/no-dynamic-require" : "error" ,
168
186
} ,
169
187
} ,
170
- {
171
- files : [ GLOB_TS , GLOB_TSX , GLOB_DTS ] ,
172
- rules : {
173
- "import/no-unresolved" : "off" ,
174
- "import/named" : "off" ,
175
- "import/default" : "off" ,
176
- "import/namespace" : "off" ,
177
-
178
- "ts/no-import-type-side-effects" : "error" ,
179
- "ts/consistent-type-imports" : [
180
- stylisticEnforcement ,
188
+ ...( ( typescript
189
+ ? [
181
190
{
182
- prefer : "type-imports" ,
183
- fixStyle : "inline-type-imports" ,
184
- disallowTypeAnnotations : false ,
191
+ files : [ GLOB_TS , GLOB_TSX , GLOB_DTS ] ,
192
+ rules : {
193
+ "import/no-unresolved" : "off" ,
194
+ "import/named" : "off" ,
195
+ "import/default" : "off" ,
196
+ "import/namespace" : "off" ,
197
+
198
+ "ts/no-import-type-side-effects" : "error" ,
199
+ "ts/consistent-type-imports" : [
200
+ stylistic === false ? "off" : "error" ,
201
+ {
202
+ prefer : "type-imports" ,
203
+ fixStyle : "inline-type-imports" ,
204
+ disallowTypeAnnotations : false ,
205
+ } ,
206
+ ] ,
207
+ } ,
185
208
} ,
186
- ] ,
187
- } ,
188
- } ,
209
+ ]
210
+ : [ ] ) satisfies FlatConfigItem [ ] ) ,
189
211
] ;
190
212
}
0 commit comments