@@ -19,6 +19,10 @@ export async function typescript(
19
19
]
20
20
21
21
const filesTypeAware = options . filesTypeAware ?? [ GLOB_TS , GLOB_TSX ]
22
+ const tsconfigPath = options ?. tsconfigPath
23
+ ? toArray ( options . tsconfigPath )
24
+ : undefined
25
+ const isTypeAware = ! ! tsconfigPath
22
26
23
27
const typeAwareRules : FlatConfigItem [ 'rules' ] = {
24
28
'dot-notation' : 'off' ,
@@ -42,10 +46,6 @@ export async function typescript(
42
46
'ts/unbound-method' : 'error' ,
43
47
}
44
48
45
- const tsconfigPath = options ?. tsconfigPath
46
- ? toArray ( options . tsconfigPath )
47
- : undefined
48
-
49
49
const [
50
50
pluginTs ,
51
51
parserTs ,
@@ -54,23 +54,16 @@ export async function typescript(
54
54
interopDefault ( import ( '@typescript-eslint/parser' ) ) ,
55
55
] as const )
56
56
57
- return [
58
- {
59
- // Install the plugins without globs, so they can be configured separately.
60
- name : 'antfu:typescript:setup' ,
61
- plugins : {
62
- antfu : pluginAntfu ,
63
- ts : pluginTs as any ,
64
- } ,
65
- } ,
66
- {
57
+ function makeParser ( typeAware : boolean , files : string [ ] , ignores ?: string [ ] ) : FlatConfigItem {
58
+ return {
67
59
files,
60
+ ...ignores ? { ignores } : { } ,
68
61
languageOptions : {
69
62
parser : parserTs ,
70
63
parserOptions : {
71
64
extraFileExtensions : componentExts . map ( ext => `.${ ext } ` ) ,
72
65
sourceType : 'module' ,
73
- ...tsconfigPath
66
+ ...typeAware
74
67
? {
75
68
project : tsconfigPath ,
76
69
tsconfigRootDir : process . cwd ( ) ,
@@ -79,6 +72,28 @@ export async function typescript(
79
72
...parserOptions as any ,
80
73
} ,
81
74
} ,
75
+ name : `antfu:typescript:${ typeAware ? 'type-aware-parser' : 'parser' } ` ,
76
+ }
77
+ }
78
+
79
+ return [
80
+ {
81
+ // Install the plugins without globs, so they can be configured separately.
82
+ name : 'antfu:typescript:setup' ,
83
+ plugins : {
84
+ antfu : pluginAntfu ,
85
+ ts : pluginTs as any ,
86
+ } ,
87
+ } ,
88
+ // assign type-aware parser for type-aware files and type-unaware parser for the rest
89
+ ...isTypeAware
90
+ ? [
91
+ makeParser ( true , filesTypeAware ) ,
92
+ makeParser ( false , files , filesTypeAware ) ,
93
+ ]
94
+ : [ makeParser ( false , files ) ] ,
95
+ {
96
+ files,
82
97
name : 'antfu:typescript:rules' ,
83
98
rules : {
84
99
...renameRules (
0 commit comments