From 43f1685356b9840e09631843ad9ccf0440a498b0 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Thu, 25 Mar 2021 01:32:39 +0100 Subject: [PATCH] Update: `--quiet` should not supress `--max-warnings` (fixes #14202) (#14242) --- lib/cli.js | 8 ++++++-- tests/lib/cli.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 4216126b6ce..de6e16e02e0 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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; diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 0f8a24c2e28..d1fea182db1 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -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}`);