Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid destructuring and just build the expected object once #538

Merged
merged 2 commits into from
May 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 25 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
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