Skip to content

Commit

Permalink
fix(typescript-estree): ts returning wrong file with project referenc…
Browse files Browse the repository at this point in the history
…es (#1575)
  • Loading branch information
bradzacher committed Feb 7, 2020
1 parent e9cf734 commit 4c12dac
Showing 1 changed file with 15 additions and 0 deletions.
Expand Up @@ -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
Expand All @@ -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 };
},
);
Expand Down

0 comments on commit 4c12dac

Please sign in to comment.