-
-
Notifications
You must be signed in to change notification settings - Fork 285
/
report.js
86 lines (71 loc) · 1.76 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import defineLazyProperty from 'define-lazy-prop';
import {ESLint} from 'eslint';
/** Merge multiple reports into a single report */
const mergeReports = reports => {
const report = {
results: [],
errorCount: 0,
warningCount: 0,
};
for (const currentReport of reports) {
report.results.push(...currentReport.results);
report.errorCount += currentReport.errorCount;
report.warningCount += currentReport.warningCount;
report.rulesMeta = {...report.rulesMeta, ...currentReport.rulesMeta};
}
return report;
};
const processReport = (report, {isQuiet = false, rulesMeta} = {}) => {
if (isQuiet) {
report = ESLint.getErrorResults(report);
}
const result = {
results: report,
rulesMeta,
...getReportStatistics(report),
};
defineLazyProperty(result, 'usedDeprecatedRules', () => {
const seenRules = new Set();
const rules = [];
for (const {usedDeprecatedRules} of report) {
for (const rule of usedDeprecatedRules) {
if (seenRules.has(rule.ruleId)) {
continue;
}
seenRules.add(rule.ruleId);
rules.push(rule);
}
}
return rules;
});
return result;
};
const getReportStatistics = results => {
const statistics = {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
};
for (const result of results) {
statistics.errorCount += result.errorCount;
statistics.warningCount += result.warningCount;
statistics.fixableErrorCount += result.fixableErrorCount;
statistics.fixableWarningCount += result.fixableWarningCount;
}
return statistics;
};
const getIgnoredReport = filePath => ({
errorCount: 0,
warningCount: 0,
results: [
{
errorCount: 0,
warningCount: 0,
filePath,
messages: [],
},
],
isIgnored: true,
});
export {mergeReports, processReport, getIgnoredReport};