Skip to content

Commit

Permalink
Update: --quiet should not supress --max-warnings (fixes #14202) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Mar 25, 2021
1 parent 909c727 commit 43f1685
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/cli.js
Expand Up @@ -301,12 +301,16 @@ const cli = {
await ESLint.outputFixes(results);
}

let resultsToPrint = results;

if (options.quiet) {
debug("Quiet mode enabled - filtering out warnings");
results = ESLint.getErrorResults(results);
resultsToPrint = ESLint.getErrorResults(resultsToPrint);
}

if (await printResults(engine, results, options.format, options.outputFile)) {
if (await printResults(engine, resultsToPrint, options.format, options.outputFile)) {

// Errors and warnings from the original unfiltered results should determine the exit code
const { errorCount, warningCount } = countErrors(results);
const tooManyWarnings =
options.maxWarnings >= 0 && warningCount > options.maxWarnings;
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/cli.js
Expand Up @@ -778,6 +778,16 @@ describe("cli", () => {
assert.include(log.error.getCall(0).args[0], "ESLint found too many warnings");
});

it("should exit with exit code 1 without printing warnings if the quiet option is enabled and warning count exceeds threshold", async () => {
const filePath = getFixturePath("max-warnings");
const exitCode = await cli.execute(`--no-ignore --quiet --max-warnings 5 ${filePath}`);

assert.strictEqual(exitCode, 1);
assert.ok(log.error.calledOnce);
assert.include(log.error.getCall(0).args[0], "ESLint found too many warnings");
assert.ok(log.info.notCalled); // didn't print warnings
});

it("should not change exit code if warning count equals threshold", async () => {
const filePath = getFixturePath("max-warnings");
const exitCode = await cli.execute(`--no-ignore --max-warnings 6 ${filePath}`);
Expand Down

0 comments on commit 43f1685

Please sign in to comment.