@@ -100,13 +100,15 @@ export class ESLintAdapter {
100
100
private readonly configProvider : ConfigProvider ;
101
101
private readonly getSourceFile : ( fileName : string ) => ts . SourceFile | undefined ;
102
102
private readonly ignoredFilepathMap : Map < string , boolean > ;
103
+ private readonly eslint : ESLint ;
103
104
104
105
public constructor ( { logger, configProvider, getSourceFile } : ESLintAdapterOptions ) {
105
106
this . linter = new Linter ( ) ;
106
107
this . logger = logger ;
107
108
this . configProvider = configProvider ;
108
109
this . getSourceFile = getSourceFile ;
109
110
this . ignoredFilepathMap = new Map ( ) ;
111
+ this . eslint = new ESLint ( ) ;
110
112
}
111
113
112
114
private convertToESLintSourceCode ( src : ts . SourceFile , filename : string , options ?: ParserOptions | null ) {
@@ -132,7 +134,7 @@ export class ESLintAdapter {
132
134
}
133
135
134
136
private getESLintResult ( fileName : string , sourceFile : ts . SourceFile ) {
135
- if ( this . ignoredFilepathMap . get ( fileName . replace ( / \\ / g , '/' ) ) === true ) return [ ] ;
137
+ if ( this . shouldIgnoreFile ( fileName ) ) return [ ] ;
136
138
const configArray = this . configProvider . getConfigArrayForFile ( fileName ) ;
137
139
const configFileContent = configArray . extractConfig ( fileName ) . toCompatibleObjectAsConfigFileContent ( ) ;
138
140
if ( ! isParserModuleNameValid ( configFileContent . parser , path . join ( "@typescript-eslint" , "parser" ) ) ) {
@@ -145,13 +147,24 @@ export class ESLintAdapter {
145
147
return this . linter . verify ( sourceCode , configArray as any , { filename : fileName } ) ;
146
148
}
147
149
150
+ private shouldIgnoreFile ( fileName : string ) {
151
+ const normalized = fileName . replace ( / \\ / g, "/" ) ;
152
+ if ( / n o d e _ m o d u l e s \/ / i. test ( fileName ) || ! / \. t s x ? $ / i. test ( fileName ) ) {
153
+ return true ;
154
+ }
155
+ const cached = this . ignoredFilepathMap . get ( normalized ) ;
156
+ if ( cached !== undefined ) {
157
+ return cached ;
158
+ }
159
+ // don't know but we will next time
160
+ Promise . resolve ( this . eslint . isPathIgnored ( normalized ) ) . then ( ignored =>
161
+ this . ignoredFilepathMap . set ( normalized , ignored ) ,
162
+ ) ;
163
+ return undefined ;
164
+ }
165
+
148
166
public checkFileToBeIgnored ( fileName : string ) {
149
- if ( / n o d e _ m o d u l e s [ \\ / ] / i. test ( fileName ) || ! / \. t s x ? $ / i. test ( fileName ) ) return ;
150
- const normalized = fileName . replace ( / \\ / g, '/' ) ;
151
- Promise . resolve ( )
152
- . then ( ( ) => new ESLint ( ) )
153
- . then ( eslint => eslint . isPathIgnored ( normalized ) )
154
- . then ( result => this . ignoredFilepathMap . set ( normalized , result ) ) ;
167
+ this . shouldIgnoreFile ( fileName ) ;
155
168
}
156
169
157
170
public getSemanticDiagnostics (
0 commit comments