From 4c12dac075f774801a145cd29c4c7eff64f98fdc Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 6 Feb 2020 17:23:35 -0800 Subject: [PATCH] fix(typescript-estree): ts returning wrong file with project references (#1575) --- .../src/create-program/createProjectProgram.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/typescript-estree/src/create-program/createProjectProgram.ts b/packages/typescript-estree/src/create-program/createProjectProgram.ts index b81409e647e..c7949b02811 100644 --- a/packages/typescript-estree/src/create-program/createProjectProgram.ts +++ b/packages/typescript-estree/src/create-program/createProjectProgram.ts @@ -9,6 +9,13 @@ const log = debug('typescript-eslint:typescript-estree:createProjectProgram'); const DEFAULT_EXTRA_FILE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx']; +function getExtension(fileName: string | undefined): string | null { + if (!fileName) { + return null; + } + return fileName.endsWith('.d.ts') ? '.d.ts' : path.extname(fileName); +} + /** * @param code The code of the file being linted * @param createDefaultProgram True if the default program should be created @@ -26,6 +33,14 @@ function createProjectProgram( getProgramsForProjects(code, extra.filePath, extra), currentProgram => { const ast = currentProgram.getSourceFile(extra.filePath); + + // working around https://github.com/typescript-eslint/typescript-eslint/issues/1573 + const expectedExt = getExtension(extra.filePath); + const returnedExt = getExtension(ast?.fileName); + if (expectedExt !== returnedExt) { + return; + } + return ast && { ast, program: currentProgram }; }, );