-
Notifications
You must be signed in to change notification settings - Fork 1
/
eslint.ts
executable file
·58 lines (53 loc) · 1.58 KB
/
eslint.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
import { ESLint, Linter } from "eslint";
import { CheckResult } from ".";
import { GithubCheckAnnotation } from "./octokit-types";
export async function eslintCheck(
globs: string[],
overrides?: Linter.Config
): Promise<CheckResult> {
const eslint = new ESLint({
overrideConfig: overrides
});
const formatter = await eslint.loadFormatter("stylish");
const results = await eslint.lintFiles(globs);
const consoleOutput = formatter.format(results);
const out: {
consoleOutput: string;
annotations: GithubCheckAnnotation[];
errorCount: number;
warningCount: number;
} = {
consoleOutput,
annotations: [],
errorCount: 0,
warningCount: 0
};
for (const result of results) {
out.errorCount += result.errorCount;
out.warningCount += result.warningCount;
for (const message of result.messages) {
if (message.severity !== 0) {
let annotation: GithubCheckAnnotation = {
annotation_level: message.severity === 2 ? "failure" : "warning",
path: result.filePath,
title: message.ruleId || undefined,
message: message.message,
start_line: message.line || 1,
end_line: message.endLine || message.line || 1
};
if (
annotation.start_line &&
annotation.start_line === annotation.end_line
) {
annotation = {
...annotation,
start_column: message.column,
end_column: message.endColumn || message.column
};
}
out.annotations.push(annotation);
}
}
}
return out;
}