Skip to content
Permalink
Browse files
Update: --quiet should not supress --max-warnings (fixes #14202) (#…
  • Loading branch information
mdjermanovic committed Mar 25, 2021
1 parent 909c727 commit 43f1685356b9840e09631843ad9ccf0440a498b0
Showing with 16 additions and 2 deletions.
  1. +6 −2 lib/cli.js
  2. +10 −0 tests/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;
@@ -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}`);

0 comments on commit 43f1685

Please sign in to comment.