From 8e1801c7643405549833c0ec96261f02b1bf2c5c Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Sun, 9 May 2021 19:59:49 +0700 Subject: [PATCH] Avoid destructuring and just build the expected object once (#538) --- index.js | 60 +++++++++++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/index.js b/index.js index eedfe300..11255013 100644 --- a/index.js +++ b/index.js @@ -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} = {}) => {