diff --git a/src/linter.ts b/src/linter.ts index f2bed57b2d1..e85eb77fd8c 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -80,8 +80,7 @@ class Linter { * files and excludes declaration (".d.ts") files. */ public static getFileNames(program: ts.Program): string[] { - const currentDirectory = program.getCurrentDirectory(); - return program.getSourceFiles().map((s) => path.resolve(currentDirectory, s.fileName)).filter((l) => l.substr(-5) !== ".d.ts"); + return program.getSourceFiles().map((s) => s.fileName).filter((l) => l.substr(-5) !== ".d.ts"); } constructor(private options: ILinterOptions, private program?: ts.Program) { diff --git a/src/runner.ts b/src/runner.ts index 08e80c746bc..c505683bd56 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -216,33 +216,34 @@ export class Runner { let lastFolder: string | undefined; let configFile: IConfigurationFile | undefined; for (const file of files) { - if (!fs.existsSync(file)) { - console.error(`Unable to open file: ${file}`); + const absoluteFilePath = path.resolve(file); + if (!fs.existsSync(absoluteFilePath)) { + console.error(`Unable to open file: ${absoluteFilePath}`); return onComplete(1); } const buffer = new Buffer(256); - const fd = fs.openSync(file, "r"); + const fd = fs.openSync(absoluteFilePath, "r"); try { fs.readSync(fd, buffer, 0, 256, 0); if (buffer.readInt8(0, true) === 0x47 && buffer.readInt8(188, true) === 0x47) { // MPEG transport streams use the '.ts' file extension. They use 0x47 as the frame // separator, repeating every 188 bytes. It is unlikely to find that pattern in // TypeScript source, so tslint ignores files with the specific pattern. - console.warn(`${file}: ignoring MPEG transport stream`); + console.warn(`${absoluteFilePath}: ignoring MPEG transport stream`); continue; } } finally { fs.closeSync(fd); } - const contents = fs.readFileSync(file, "utf8"); - const folder = path.dirname(file); + const contents = fs.readFileSync(absoluteFilePath, "utf8"); + const folder = path.dirname(absoluteFilePath); if (lastFolder !== folder) { configFile = findConfiguration(possibleConfigAbsolutePath, folder).results; lastFolder = folder; } - linter.lint(file, contents, configFile); + linter.lint(absoluteFilePath, contents, configFile); } const lintResult = linter.getResult();