@@ -100,13 +100,15 @@ export class ESLintAdapter {
100100 private readonly configProvider : ConfigProvider ;
101101 private readonly getSourceFile : ( fileName : string ) => ts . SourceFile | undefined ;
102102 private readonly ignoredFilepathMap : Map < string , boolean > ;
103+ private readonly eslint : ESLint ;
103104
104105 public constructor ( { logger, configProvider, getSourceFile } : ESLintAdapterOptions ) {
105106 this . linter = new Linter ( ) ;
106107 this . logger = logger ;
107108 this . configProvider = configProvider ;
108109 this . getSourceFile = getSourceFile ;
109110 this . ignoredFilepathMap = new Map ( ) ;
111+ this . eslint = new ESLint ( ) ;
110112 }
111113
112114 private convertToESLintSourceCode ( src : ts . SourceFile , filename : string , options ?: ParserOptions | null ) {
@@ -132,7 +134,7 @@ export class ESLintAdapter {
132134 }
133135
134136 private getESLintResult ( fileName : string , sourceFile : ts . SourceFile ) {
135- if ( this . ignoredFilepathMap . get ( fileName . replace ( / \\ / g , '/' ) ) === true ) return [ ] ;
137+ if ( this . shouldIgnoreFile ( fileName ) ) return [ ] ;
136138 const configArray = this . configProvider . getConfigArrayForFile ( fileName ) ;
137139 const configFileContent = configArray . extractConfig ( fileName ) . toCompatibleObjectAsConfigFileContent ( ) ;
138140 if ( ! isParserModuleNameValid ( configFileContent . parser , path . join ( "@typescript-eslint" , "parser" ) ) ) {
@@ -145,13 +147,24 @@ export class ESLintAdapter {
145147 return this . linter . verify ( sourceCode , configArray as any , { filename : fileName } ) ;
146148 }
147149
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 ( normalized ) || ! / \. t s x ? $ / i. test ( normalized ) ) {
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+
148166 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 ) ;
155168 }
156169
157170 public getSemanticDiagnostics (
0 commit comments