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

Also check non-test files in isolation #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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