Skip to content

Commit 8e1801c

Browse files
authored
Avoid destructuring and just build the expected object once (#538)
1 parent 4cfdc72 commit 8e1801c

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

index.js

+25-35
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,39 @@ const {
2323
mergeOptions
2424
} = require('./lib/options-manager');
2525

26+
/** Merge multiple reports into a single report */
2627
const mergeReports = reports => {
27-
// Merge multiple reports into a single report
28-
let results = [];
29-
let errorCount = 0;
30-
let warningCount = 0;
31-
32-
for (const report of reports) {
33-
results = results.concat(report.results);
34-
errorCount += report.errorCount;
35-
warningCount += report.warningCount;
28+
const report = {
29+
results: [],
30+
errorCount: 0,
31+
warningCount: 0
32+
};
33+
34+
for (const currentReport of reports) {
35+
report.results.push(...currentReport.results);
36+
report.errorCount += currentReport.errorCount;
37+
report.warningCount += currentReport.warningCount;
3638
}
3739

38-
return {
39-
errorCount,
40-
warningCount,
41-
results
42-
};
40+
return report;
4341
};
4442

4543
const getReportStatistics = results => {
46-
let errorCount = 0;
47-
let warningCount = 0;
48-
let fixableErrorCount = 0;
49-
let fixableWarningCount = 0;
50-
51-
for (const {
52-
errorCount: currentErrorCount,
53-
warningCount: currentWarningCount,
54-
fixableErrorCount: currentFixableErrorCount,
55-
fixableWarningCount: currentFixableWarningCount
56-
} of results) {
57-
errorCount += currentErrorCount;
58-
warningCount += currentWarningCount;
59-
fixableErrorCount += currentFixableErrorCount;
60-
fixableWarningCount += currentFixableWarningCount;
44+
const statistics = {
45+
errorCount: 0,
46+
warningCount: 0,
47+
fixableErrorCount: 0,
48+
fixableWarningCount: 0
49+
};
50+
51+
for (const result of results) {
52+
statistics.errorCount += result.errorCount;
53+
statistics.warningCount += result.warningCount;
54+
statistics.fixableErrorCount += result.fixableErrorCount;
55+
statistics.fixableWarningCount += result.fixableWarningCount;
6156
}
6257

63-
return {
64-
errorCount,
65-
warningCount,
66-
fixableErrorCount,
67-
fixableWarningCount
68-
};
58+
return statistics;
6959
};
7060

7161
const processReport = (report, {isQuiet = false} = {}) => {

0 commit comments

Comments
 (0)