-
-
Notifications
You must be signed in to change notification settings - Fork 285
/
open-report.js
43 lines (34 loc) · 907 Bytes
/
open-report.js
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
import openEditor from 'open-editor';
const sortResults = (a, b) => a.errorCount + b.errorCount > 0 ? (a.errorCount - b.errorCount) : (a.warningCount - b.warningCount);
const resultToFile = result => {
const [message] = result.messages
.sort((a, b) => {
if (a.severity < b.severity) {
return 1;
}
if (a.severity > b.severity) {
return -1;
}
if (a.line < b.line) {
return -1;
}
if (a.line > b.line) {
return 1;
}
return 0;
});
return {
file: result.filePath,
line: message.line,
column: message.column,
};
};
const getFiles = (report, predicate) => report.results
.filter(result => predicate(result))
.sort(sortResults)
.map(result => resultToFile(result));
export default report => {
const count = report.errorCount > 0 ? 'errorCount' : 'warningCount';
const files = getFiles(report, result => result[count] > 0);
openEditor(files);
};