Skip to content

Commit

Permalink
Avoid destructuring and just build the expected object once (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed May 9, 2021
1 parent 4cfdc72 commit 8e1801c
Showing 1 changed file with 25 additions and 35 deletions.
60 changes: 25 additions & 35 deletions index.js
Expand Up @@ -23,49 +23,39 @@ const {
mergeOptions
} = require('./lib/options-manager');

/** Merge multiple reports into a single report */
const mergeReports = reports => {
// Merge multiple reports into a single report
let results = [];
let errorCount = 0;
let warningCount = 0;

for (const report of reports) {
results = results.concat(report.results);
errorCount += report.errorCount;
warningCount += report.warningCount;
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;
}

return {
errorCount,
warningCount,
results
};
return report;
};

const getReportStatistics = results => {
let errorCount = 0;
let warningCount = 0;
let fixableErrorCount = 0;
let fixableWarningCount = 0;

for (const {
errorCount: currentErrorCount,
warningCount: currentWarningCount,
fixableErrorCount: currentFixableErrorCount,
fixableWarningCount: currentFixableWarningCount
} of results) {
errorCount += currentErrorCount;
warningCount += currentWarningCount;
fixableErrorCount += currentFixableErrorCount;
fixableWarningCount += currentFixableWarningCount;
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 {
errorCount,
warningCount,
fixableErrorCount,
fixableWarningCount
};
return statistics;
};

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

0 comments on commit 8e1801c

Please sign in to comment.