-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathconvertResults.ts
34 lines (28 loc) · 1.16 KB
/
convertResults.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
import { FileError, Issue, ToolResult } from "codacy-seed"
import { ESLint } from "eslint"
import { isBlacklisted } from "./blacklist"
import { computeSuggestion } from "./computeSuggestion"
import { patternIdToCodacy } from "./model/patterns"
export function convertResults (eslintResults: ESLint.LintResult[]): ToolResult[] {
const results: ToolResult[] = []
eslintResults.forEach((result) => {
const { "filePath": filename, messages } = result
if (result.fatalErrorCount > 0) {
results.push(new FileError(filename, messages.filter((m) => m.fatal).map((m) => m.message).join("\\n")))
return
}
const issues = messages
.filter((r) => r.ruleId && !isBlacklisted(r.ruleId))
.map((m) => {
const { ruleId, line, endLine, message, fix, suggestions } = m
const patternId = patternIdToCodacy(ruleId)
const suggestion
= process.env.SUGGESTIONS === "true" && result.source
? computeSuggestion(result.source, line, endLine, fix, suggestions)
: undefined
return new Issue(filename, message, patternId, line, suggestion)
})
results.push(...issues)
})
return results
}