Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Also check non-test files in isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed May 20, 2020
1 parent 6c5e0d6 commit 5787d32
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/lint.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { TypeScriptVersion } from "@definitelytyped/typescript-versions";
import { typeScriptPath } from "@definitelytyped/utils";
import assert = require("assert");
import * as fs from "fs";
import { pathExists } from "fs-extra";
import { join as joinPaths, normalize } from "path";
import { dirname, join as joinPaths, normalize } from "path";
import { Configuration, ILinterOptions, Linter } from "tslint";
import * as TsType from "typescript";
type Configuration = typeof Configuration;
Expand All @@ -27,6 +28,28 @@ export async function lint(
if (errors) { return errors; }
}

{
const { config } = TsType.readConfigFile(tsconfigPath, TsType.sys.readFile);
const parseConfigHost: TsType.ParseConfigHost = {
fileExists: fs.existsSync,
readDirectory: TsType.sys.readDirectory,
readFile: file => fs.readFileSync(file, "utf8"),
useCaseSensitiveFileNames: true,
};
const projectDirectory = dirname(tsconfigPath);
const parsed = TsType.parseJsonConfigFileContent(config, parseConfigHost, projectDirectory, { noEmit: true });
const program = TsType.createProgram(parsed.fileNames.filter(fileName => fileName.endsWith(".d.ts")), parsed.options);
const diagnostics = TsType.getPreEmitDiagnostics(program);
if (diagnostics.length) {
const showDiags = TsType.formatDiagnostics(diagnostics, {
getCanonicalFileName: f => f,
getCurrentDirectory: () => dirPath,
getNewLine: () => "\n",
});
return showDiags;
}
}

const lintOptions: ILinterOptions = {
fix: false,
formatter: "stylish",
Expand Down

0 comments on commit 5787d32

Please sign in to comment.