Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Move path.resolve()
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Chen committed May 2, 2017
1 parent 6039fbb commit 31d3b3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/linter.ts
Expand Up @@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions src/runner.ts
Expand Up @@ -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();
Expand Down

0 comments on commit 31d3b3a

Please sign in to comment.