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

Update: --quiet should not supress --max-warnings (fixes #14202) #14242

Merged
merged 1 commit into from Mar 25, 2021
Merged
Show file tree
Hide file tree
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
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