-
Notifications
You must be signed in to change notification settings - Fork 1
/
tslint.ts
executable file
·66 lines (62 loc) · 1.95 KB
/
tslint.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Configuration, Formatters, Linter } from "tslint";
import { CheckResult } from ".";
import { GithubCheckAnnotation } from "./octokit-types";
/**
* Get all TSLint errors and warnings for the given Typescript project.
*/
export async function tslintCheck(options: {
tslintConfigFile?: string;
tsConfigFile: string;
}): Promise<CheckResult> {
const program = Linter.createProgram(options.tsConfigFile);
const linter = new Linter(
{
fix: false,
formatter: Formatters.CodeFrameFormatter
},
program
);
const files = Linter.getFileNames(program);
files.forEach(file => {
const fileContents = program.getSourceFile(file)?.getFullText() || "";
const configuration = Configuration.findConfiguration(
options.tslintConfigFile || null,
file
).results;
linter.lint(file, fileContents, configuration);
});
const results = linter.getResult();
const annotations: GithubCheckAnnotation[] = [];
for (const failure of results.failures) {
if (failure.getRuleSeverity() === "off") {
continue;
}
let annotation: GithubCheckAnnotation = {
annotation_level:
failure.getRuleSeverity() === "error" ? "failure" : "warning",
path: failure.getFileName(),
title: failure.getRuleName(),
message: failure.getFailure(),
start_line: failure.getStartPosition().getLineAndCharacter().line + 1,
end_line: failure.getEndPosition().getLineAndCharacter().line + 1
};
if (
annotation.start_line &&
annotation.start_line === annotation.end_line
) {
annotation = {
...annotation,
start_column:
failure.getStartPosition().getLineAndCharacter().character + 1,
end_column: failure.getEndPosition().getLineAndCharacter().character + 1
};
}
annotations.push(annotation);
}
return {
consoleOutput: results.output,
annotations,
errorCount: results.errorCount,
warningCount: results.warningCount
};
}