Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,22 +368,26 @@ function getUnusedCheckedProgram(program: ts.Program, checkParameters: boolean):

function makeUnusedCheckedProgram(program: ts.Program, checkParameters: boolean): ts.Program {
const options = { ...program.getCompilerOptions(), noUnusedLocals: true, ...(checkParameters ? { noUnusedParameters: true } : null) };
const sourceFilesByName = new Map<string, ts.SourceFile>(program.getSourceFiles().map<[string, ts.SourceFile]>((s) => [s.fileName, s]));
const sourceFilesByName = new Map<string, ts.SourceFile>(
program.getSourceFiles().map<[string, ts.SourceFile]>((s) => [getCanonicalFileName(s.fileName), s]));

// tslint:disable object-literal-sort-keys
return ts.createProgram(Array.from(sourceFilesByName.keys()), options, {
fileExists: (f) => sourceFilesByName.has(f),
readFile(f) {
const s = sourceFilesByName.get(f)!;
return s.text;
},
getSourceFile: (f) => sourceFilesByName.get(f)!,
fileExists: (f) => sourceFilesByName.has(getCanonicalFileName(f)),
readFile: (f) => sourceFilesByName.get(getCanonicalFileName(f))!.text,
getSourceFile: (f) => sourceFilesByName.get(getCanonicalFileName(f))!,
getDefaultLibFileName: () => ts.getDefaultLibFileName(options),
writeFile: () => {}, // tslint:disable-line no-empty
getCurrentDirectory: () => "",
getDirectories: () => [],
getCanonicalFileName: (f) => f,
useCaseSensitiveFileNames: () => true,
getCanonicalFileName,
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
getNewLine: () => "\n",
});
// tslint:enable object-literal-sort-keys

// We need to be careful with file system case sensitivity
function getCanonicalFileName(fileName: string): string {
return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
}
}