Skip to content

Commit

Permalink
Fix: getErrorResults function to not mutate passed parameter (#11592)
Browse files Browse the repository at this point in the history
* Chore: Changed getErrorResults to not alter passed `results` parameter

* Chore: Added tests for getErrorResults

Check that getErrorResults doesn't mutate passed argument
  • Loading branch information
danielamaia authored and not-an-aardvark committed Apr 9, 2019
1 parent ef7801e commit b92ca6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,14 @@ class CLIEngine {

if (filteredMessages.length > 0) {
filtered.push(
Object.assign(result, {
{
...result,
messages: filteredMessages,
errorCount: filteredMessages.length,
warningCount: 0,
fixableErrorCount: result.fixableErrorCount,
fixableWarningCount: 0
})
}
);
}
});
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3111,6 +3111,20 @@ describe("CLIEngine", () => {
assert.strictEqual(errorResults[0].messages[4].severity, 2);
});

it("should not mutate passed report.results parameter", () => {
process.chdir(originalDir);
const engine = new CLIEngine({
rules: { quotes: [1, "double"] }
});

const report = engine.executeOnText("var foo = 'bar';");
const reportResultsLength = report.results[0].messages.length;

CLIEngine.getErrorResults(report.results);

assert.lengthOf(report.results[0].messages, reportResultsLength);
});

it("should report a warningCount of 0 when looking for errors only", () => {

process.chdir(originalDir);
Expand Down

0 comments on commit b92ca6e

Please sign in to comment.