@@ -3,17 +3,41 @@ import type { FlatESLintConfigItem } from 'eslint-define-config'
3
3
import { GLOB_TS , GLOB_TSX } from '../globs'
4
4
import { parserTs , pluginAntfu , pluginImport , pluginTs } from '../plugins'
5
5
import { OFF } from '../flags'
6
- import type { OptionsComponentExts , OptionsOverrides , OptionsTypeScriptWithTypes } from '../types'
6
+ import type { OptionsComponentExts , OptionsOverrides , OptionsTypeScriptParserOptions , OptionsTypeScriptWithTypes } from '../types'
7
7
import { renameRules } from '../utils'
8
8
9
9
export function typescript (
10
- options ?: OptionsComponentExts & OptionsOverrides ,
10
+ options ?: OptionsComponentExts & OptionsOverrides & OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions ,
11
11
) : FlatESLintConfigItem [ ] {
12
12
const {
13
13
componentExts = [ ] ,
14
14
overrides = { } ,
15
+ parserOptions = { } ,
16
+ tsconfigPath,
15
17
} = options ?? { }
16
18
19
+ const typeAwareRules : FlatESLintConfigItem [ 'rules' ] = {
20
+ 'dot-notation' : OFF ,
21
+ 'no-implied-eval' : OFF ,
22
+ 'no-throw-literal' : OFF ,
23
+ 'ts/await-thenable' : 'error' ,
24
+ 'ts/dot-notation' : [ 'error' , { allowKeywords : true } ] ,
25
+ 'ts/no-floating-promises' : 'error' ,
26
+ 'ts/no-for-in-array' : 'error' ,
27
+ 'ts/no-implied-eval' : 'error' ,
28
+ 'ts/no-misused-promises' : 'error' ,
29
+ 'ts/no-throw-literal' : 'error' ,
30
+ 'ts/no-unnecessary-type-assertion' : 'error' ,
31
+ 'ts/no-unsafe-argument' : 'error' ,
32
+ 'ts/no-unsafe-assignment' : 'error' ,
33
+ 'ts/no-unsafe-call' : 'error' ,
34
+ 'ts/no-unsafe-member-access' : 'error' ,
35
+ 'ts/no-unsafe-return' : 'error' ,
36
+ 'ts/restrict-plus-operands' : 'error' ,
37
+ 'ts/restrict-template-expressions' : 'error' ,
38
+ 'ts/unbound-method' : 'error' ,
39
+ }
40
+
17
41
return [
18
42
{
19
43
// Install the plugins without globs, so they can be configured separately.
@@ -33,6 +57,13 @@ export function typescript(
33
57
parser : parserTs ,
34
58
parserOptions : {
35
59
sourceType : 'module' ,
60
+ ...tsconfigPath
61
+ ? {
62
+ project : [ tsconfigPath ] ,
63
+ tsconfigRootDir : process . cwd ( ) ,
64
+ }
65
+ : { } ,
66
+ ...parserOptions as any ,
36
67
} ,
37
68
} ,
38
69
rules : {
@@ -78,6 +109,7 @@ export function typescript(
78
109
'ts/prefer-ts-expect-error' : 'error' ,
79
110
'ts/triple-slash-reference' : OFF ,
80
111
112
+ ...tsconfigPath ? typeAwareRules : { } ,
81
113
...overrides ,
82
114
} ,
83
115
} ,
@@ -104,54 +136,3 @@ export function typescript(
104
136
} ,
105
137
]
106
138
}
107
-
108
- export function typescriptWithTypes (
109
- options : OptionsTypeScriptWithTypes & OptionsComponentExts & OptionsOverrides ,
110
- ) : FlatESLintConfigItem [ ] {
111
- const {
112
- componentExts = [ ] ,
113
- tsconfigPath,
114
- tsconfigRootDir = process . cwd ( ) ,
115
- overrides = { } ,
116
- } = options
117
-
118
- return [
119
- {
120
- files : [
121
- GLOB_TS ,
122
- GLOB_TSX ,
123
- ...componentExts . map ( ext => `**/*.${ ext } ` ) ,
124
- '!**/*.md/*.*' ,
125
- ] ,
126
- languageOptions : {
127
- parser : parserTs ,
128
- parserOptions : {
129
- project : [ tsconfigPath ] ,
130
- tsconfigRootDir,
131
- } ,
132
- } ,
133
- rules : {
134
- 'dot-notation' : OFF ,
135
- 'no-implied-eval' : OFF ,
136
- 'no-throw-literal' : OFF ,
137
- 'ts/await-thenable' : 'error' ,
138
- 'ts/dot-notation' : [ 'error' , { allowKeywords : true } ] ,
139
- 'ts/no-floating-promises' : 'error' ,
140
- 'ts/no-for-in-array' : 'error' ,
141
- 'ts/no-implied-eval' : 'error' ,
142
- 'ts/no-misused-promises' : 'error' ,
143
- 'ts/no-throw-literal' : 'error' ,
144
- 'ts/no-unnecessary-type-assertion' : 'error' ,
145
- 'ts/no-unsafe-argument' : 'error' ,
146
- 'ts/no-unsafe-assignment' : 'error' ,
147
- 'ts/no-unsafe-call' : 'error' ,
148
- 'ts/no-unsafe-member-access' : 'error' ,
149
- 'ts/no-unsafe-return' : 'error' ,
150
- 'ts/restrict-plus-operands' : 'error' ,
151
- 'ts/restrict-template-expressions' : 'error' ,
152
- 'ts/unbound-method' : 'error' ,
153
- ...overrides ,
154
- } ,
155
- } ,
156
- ]
157
- }
0 commit comments