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

Commit 986b371

Browse files
authored
Also check non-test files in isolation
1 parent a6974eb commit 986b371

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/lint.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import assert = require("assert");
22
import { TypeScriptVersion } from "definitelytyped-header-parser";
3+
import * as fs from "fs";
34
import { pathExists } from "fs-extra";
4-
import { join as joinPaths, normalize } from "path";
5+
import { dirname, join as joinPaths, normalize } from "path";
56
import { Configuration, ILinterOptions, Linter } from "tslint";
67
import * as TsType from "typescript";
78
type Configuration = typeof Configuration;
@@ -27,6 +28,28 @@ export async function lint(
2728
if (errors) { return errors; }
2829
}
2930

31+
{
32+
const { config } = TsType.readConfigFile(tsconfigPath, TsType.sys.readFile);
33+
const parseConfigHost: TsType.ParseConfigHost = {
34+
fileExists: fs.existsSync,
35+
readDirectory: TsType.sys.readDirectory,
36+
readFile: file => fs.readFileSync(file, "utf8"),
37+
useCaseSensitiveFileNames: true,
38+
};
39+
const projectDirectory = dirname(tsconfigPath);
40+
const parsed = TsType.parseJsonConfigFileContent(config, parseConfigHost, projectDirectory, { noEmit: true });
41+
const program = TsType.createProgram(parsed.fileNames.filter(fileName => fileName.endsWith(".d.ts")), parsed.options);
42+
const diagnostics = TsType.getPreEmitDiagnostics(program);
43+
if (diagnostics.length) {
44+
const showDiags = TsType.formatDiagnostics(diagnostics, {
45+
getCanonicalFileName: f => f,
46+
getCurrentDirectory: () => dirPath,
47+
getNewLine: () => "\n",
48+
});
49+
return showDiags;
50+
}
51+
}
52+
3053
const lintOptions: ILinterOptions = {
3154
fix: false,
3255
formatter: "stylish",

0 commit comments

Comments
 (0)