From 5787d32a22865004024395a4422ffafb129a6fd4 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Sun, 26 Apr 2020 16:04:15 -0700 Subject: [PATCH] Also check non-test files in isolation --- src/lint.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lint.ts b/src/lint.ts index a0f41909..3c643b1a 100644 --- a/src/lint.ts +++ b/src/lint.ts @@ -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; @@ -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",