@@ -27,6 +27,11 @@ export async function typescript(
27
27
28
28
const filesTypeAware = options . filesTypeAware ?? [ GLOB_TS , GLOB_TSX ]
29
29
30
+ const tsconfigPath = options ?. tsconfigPath
31
+ ? toArray ( options . tsconfigPath )
32
+ : undefined
33
+ const isTypeAware = ! ! tsconfigPath
34
+
30
35
const typeAwareRules : FlatConfigItem [ 'rules' ] = {
31
36
'dot-notation' : 'off' ,
32
37
'no-implied-eval' : 'off' ,
@@ -49,32 +54,25 @@ export async function typescript(
49
54
'ts/unbound-method' : 'error' ,
50
55
}
51
56
52
- const tsconfigPath = options ?. tsconfigPath
53
- ? toArray ( options . tsconfigPath )
54
- : undefined
55
-
56
57
const [ pluginTs , parserTs ] = await Promise . all ( [
57
58
interopDefault ( import ( '@typescript-eslint/eslint-plugin' ) ) ,
58
59
interopDefault ( import ( '@typescript-eslint/parser' ) ) ,
59
60
] as const )
60
61
61
- return [
62
- {
63
- // Install the plugins without globs, so they can be configured separately.
64
- name : 'coderwyd:typescript:setup' ,
65
- plugins : {
66
- antfu : pluginAntfu ,
67
- ts : pluginTs as any ,
68
- } ,
69
- } ,
70
- {
62
+ function makeParser (
63
+ typeAware : boolean ,
64
+ files : string [ ] ,
65
+ ignores ?: string [ ] ,
66
+ ) : FlatConfigItem {
67
+ return {
71
68
files,
69
+ ...( ignores ? { ignores } : { } ) ,
72
70
languageOptions : {
73
71
parser : parserTs ,
74
72
parserOptions : {
75
73
extraFileExtensions : componentExts . map ( ext => `.${ ext } ` ) ,
76
74
sourceType : 'module' ,
77
- ...( tsconfigPath
75
+ ...( typeAware
78
76
? {
79
77
project : tsconfigPath ,
80
78
tsconfigRootDir : process . cwd ( ) ,
@@ -83,6 +81,28 @@ export async function typescript(
83
81
...( parserOptions as any ) ,
84
82
} ,
85
83
} ,
84
+ name : `coderwyd:typescript:${ typeAware ? 'type-aware-parser' : 'parser' } ` ,
85
+ }
86
+ }
87
+
88
+ return [
89
+ {
90
+ // Install the plugins without globs, so they can be configured separately.
91
+ name : 'coderwyd:typescript:setup' ,
92
+ plugins : {
93
+ antfu : pluginAntfu ,
94
+ ts : pluginTs as any ,
95
+ } ,
96
+ } ,
97
+ // assign type-aware parser for type-aware files and type-unaware parser for the rest
98
+ ...( isTypeAware
99
+ ? [
100
+ makeParser ( true , filesTypeAware ) ,
101
+ makeParser ( false , files , filesTypeAware ) ,
102
+ ]
103
+ : [ makeParser ( false , files ) ] ) ,
104
+ {
105
+ files,
86
106
name : 'coderwyd:typescript:rules' ,
87
107
rules : {
88
108
...renameRules (
0 commit comments