From 5ca59859c300ba67ee43e8e805244ffcc342f232 Mon Sep 17 00:00:00 2001 From: A-Katopodis Date: Mon, 21 Jun 2021 22:55:16 +0200 Subject: [PATCH 1/8] Docs: Updated docs for exit-on-fatal-error --- docs/user-guide/command-line-interface.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/user-guide/command-line-interface.md b/docs/user-guide/command-line-interface.md index 99fd61eb950..1cb41a9a659 100644 --- a/docs/user-guide/command-line-interface.md +++ b/docs/user-guide/command-line-interface.md @@ -81,6 +81,7 @@ Miscellaneous: --init Run config initialization wizard - default: false --env-info Output execution environment information - default: false --no-error-on-unmatched-pattern Prevent errors when pattern is unmatched - default: false + --exit-on-fatal-error Exit with exit code 2 in case of fatal error. - default: false --debug Output debugging information -h, --help Show help -v, --version Output the version number @@ -467,6 +468,10 @@ This option outputs information about the execution environment, including the v This option prevents errors when a quoted glob pattern or `--ext` is unmatched. This will not prevent errors when your shell can't match a glob. +#### `--exit-on-fatal-error` + +This option makes ESLint to exit with exit code 2 in case of a fatal error. It allows you to detect if any file was not parsed correctly compared to having rule violations. + #### `--debug` This option outputs debugging information to the console. This information is useful when you're seeing a problem and having a hard time pinpointing it. The ESLint team may ask for this debugging information to help solve bugs. From 222ad197a9bb5deb90d12a730c6b92af01e044f9 Mon Sep 17 00:00:00 2001 From: A-Katopodis Date: Mon, 21 Jun 2021 22:55:38 +0200 Subject: [PATCH 2/8] New: Added exit-on-fatal-error feature --- lib/cli-engine/cli-engine.js | 6 ++++ lib/cli.js | 13 +++++++-- lib/eslint/eslint.js | 1 + lib/options.js | 6 ++++ tests/bin/eslint.js | 9 ++++++ .../exit-on-fatal-error/fatal-error.js | 1 + .../exit-on-fatal-error/no-fatal-error.js | 1 + tests/lib/cli-engine/cli-engine.js | 29 ++++++++++++++++--- tests/lib/cli.js | 23 +++++++++++++++ tests/lib/eslint/eslint.js | 22 +++++++++++--- 10 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 tests/fixtures/exit-on-fatal-error/fatal-error.js create mode 100644 tests/fixtures/exit-on-fatal-error/no-fatal-error.js diff --git a/lib/cli-engine/cli-engine.js b/lib/cli-engine/cli-engine.js index ca298f9c356..24f6a10d14b 100644 --- a/lib/cli-engine/cli-engine.js +++ b/lib/cli-engine/cli-engine.js @@ -156,6 +156,9 @@ function calculateStatsPerFile(messages) { return messages.reduce((stat, message) => { if (message.fatal || message.severity === 2) { stat.errorCount++; + if (message.fatal) { + stat.fatalErrorCount++; + } if (message.fix) { stat.fixableErrorCount++; } @@ -168,6 +171,7 @@ function calculateStatsPerFile(messages) { return stat; }, { errorCount: 0, + fatalErrorCount: 0, warningCount: 0, fixableErrorCount: 0, fixableWarningCount: 0 @@ -183,12 +187,14 @@ function calculateStatsPerFile(messages) { function calculateStatsPerRun(results) { return results.reduce((stat, result) => { stat.errorCount += result.errorCount; + stat.fatalErrorCount += result.fatalErrorCount; stat.warningCount += result.warningCount; stat.fixableErrorCount += result.fixableErrorCount; stat.fixableWarningCount += result.fixableWarningCount; return stat; }, { errorCount: 0, + fatalErrorCount: 0, warningCount: 0, fixableErrorCount: 0, fixableWarningCount: 0 diff --git a/lib/cli.js b/lib/cli.js index f766764546c..b42da22fb1d 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -131,14 +131,16 @@ function translateOptions({ */ function countErrors(results) { let errorCount = 0; + let fatalErrorCount = 0; let warningCount = 0; for (const result of results) { errorCount += result.errorCount; + fatalErrorCount += result.fatalErrorCount; warningCount += result.warningCount; } - return { errorCount, warningCount }; + return { errorCount, fatalErrorCount, warningCount }; } /** @@ -314,9 +316,12 @@ const cli = { 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 { errorCount, fatalErrorCount, warningCount } = countErrors(results); + const tooManyWarnings = options.maxWarnings >= 0 && warningCount > options.maxWarnings; + const fatalErrorExists = + options.exitOnFatalError && fatalErrorCount > 0; if (!errorCount && tooManyWarnings) { log.error( @@ -325,6 +330,10 @@ const cli = { ); } + if (fatalErrorExists) { + return 2; + } + return (errorCount || tooManyWarnings) ? 1 : 0; } diff --git a/lib/eslint/eslint.js b/lib/eslint/eslint.js index 056e04b5945..12e9cfae62a 100644 --- a/lib/eslint/eslint.js +++ b/lib/eslint/eslint.js @@ -59,6 +59,7 @@ const { version } = require("../../package.json"); * @property {string} [resolvePluginsRelativeTo] The folder where plugins should be resolved from, defaulting to the CWD. * @property {string[]} [rulePaths] An array of directories to load custom rules from. * @property {boolean} [useEslintrc] False disables looking for .eslintrc.* files. + * @property {number} exitOnFatalError Number of fatal errors for the result. */ /** diff --git a/lib/options.js b/lib/options.js index 92c140bd3c8..90d6edcaa0b 100644 --- a/lib/options.js +++ b/lib/options.js @@ -204,6 +204,12 @@ module.exports = optionator({ default: "-1", description: "Number of warnings to trigger nonzero exit code" }, + { + option: "exit-on-fatal-error", + type: "Boolean", + default: "false", + description: "Trigger exit code 2 on any fatal errors." + }, { heading: "Output" }, diff --git a/tests/bin/eslint.js b/tests/bin/eslint.js index 7500d6611ce..4fed66aedd7 100644 --- a/tests/bin/eslint.js +++ b/tests/bin/eslint.js @@ -89,6 +89,7 @@ describe("bin/eslint.js", () => { filePath: "", messages: [], errorCount: 0, + fatalErrorCount: 0, warningCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, @@ -117,6 +118,14 @@ describe("bin/eslint.js", () => { return assertExitCode(child, 1); }); + it("has exit code 2 if a syntax error is thrown when exit-on-fatal-error is true", () => { + const child = runESLint(["--stdin", "--no-eslintrc", "--exit-on-fatal-error"]); + + child.stdin.write("This is not valid JS syntax.\n"); + child.stdin.end(); + return assertExitCode(child, 2); + }); + it("has exit code 1 if a linting error occurs", () => { const child = runESLint(["--stdin", "--no-eslintrc", "--rule", "semi:2"]); diff --git a/tests/fixtures/exit-on-fatal-error/fatal-error.js b/tests/fixtures/exit-on-fatal-error/fatal-error.js new file mode 100644 index 00000000000..53a47a5b79e --- /dev/null +++ b/tests/fixtures/exit-on-fatal-error/fatal-error.js @@ -0,0 +1 @@ +var foo 1 \ No newline at end of file diff --git a/tests/fixtures/exit-on-fatal-error/no-fatal-error.js b/tests/fixtures/exit-on-fatal-error/no-fatal-error.js new file mode 100644 index 00000000000..d5814b856aa --- /dev/null +++ b/tests/fixtures/exit-on-fatal-error/no-fatal-error.js @@ -0,0 +1 @@ +var foo = 1; \ No newline at end of file diff --git a/tests/lib/cli-engine/cli-engine.js b/tests/lib/cli-engine/cli-engine.js index 59243b0b7dc..680317b29a3 100644 --- a/tests/lib/cli-engine/cli-engine.js +++ b/tests/lib/cli-engine/cli-engine.js @@ -144,6 +144,7 @@ describe("CLIEngine", () => { assert.strictEqual(report.results.length, 1); assert.strictEqual(report.errorCount, 5); assert.strictEqual(report.warningCount, 0); + assert.strictEqual(report.fatalErrorCount, 0); assert.strictEqual(report.fixableErrorCount, 3); assert.strictEqual(report.fixableWarningCount, 0); assert.strictEqual(report.results[0].messages.length, 5); @@ -310,6 +311,7 @@ describe("CLIEngine", () => { messages: [], errorCount: 0, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, output: "var bar = foo;" @@ -317,6 +319,7 @@ describe("CLIEngine", () => { ], errorCount: 0, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, usedDeprecatedRules: [] @@ -519,6 +522,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, source: "var bar = foo" @@ -526,6 +530,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, usedDeprecatedRules: [] @@ -562,6 +567,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 1, fixableErrorCount: 0, fixableWarningCount: 0, output: "var bar = foothis is a syntax error." @@ -569,6 +575,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 1, fixableErrorCount: 0, fixableWarningCount: 0, usedDeprecatedRules: [] @@ -604,6 +611,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 1, fixableErrorCount: 0, fixableWarningCount: 0, source: "var bar =" @@ -611,6 +619,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 1, fixableErrorCount: 0, fixableWarningCount: 0, usedDeprecatedRules: [] @@ -692,6 +701,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 1, fixableErrorCount: 0, fixableWarningCount: 0, source: "var bar = foothis is a syntax error.\n return bar;" @@ -699,6 +709,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 1, fixableErrorCount: 0, fixableWarningCount: 0, usedDeprecatedRules: [] @@ -1684,6 +1695,7 @@ describe("CLIEngine", () => { messages: [], errorCount: 0, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, output: "true ? \"yes\" : \"no\";\n" @@ -1693,6 +1705,7 @@ describe("CLIEngine", () => { messages: [], errorCount: 0, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0 }, @@ -1713,6 +1726,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, output: "var msg = \"hi\";\nif (msg == \"hi\") {\n\n}\n" @@ -1734,6 +1748,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, output: "var msg = \"hi\" + foo;\n" @@ -5077,6 +5092,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, source: "/* eslint-disable */" @@ -5084,6 +5100,7 @@ describe("CLIEngine", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, usedDeprecatedRules: [] @@ -6155,7 +6172,8 @@ describe("CLIEngine", () => { } ], source: "a == b", - warningCount: 0 + warningCount: 0, + fatalErrorCount: 0 } ]); }); @@ -6177,7 +6195,8 @@ describe("CLIEngine", () => { fixableErrorCount: 0, fixableWarningCount: 0, messages: [], - warningCount: 0 + warningCount: 0, + fatalErrorCount: 0 } ]); }); @@ -6223,7 +6242,8 @@ describe("CLIEngine", () => { fixableErrorCount: 0, fixableWarningCount: 0, messages: [], - warningCount: 0 + warningCount: 0, + fatalErrorCount: 0 } ]); }); @@ -6258,7 +6278,8 @@ describe("CLIEngine", () => { } ], source: "a == b", - warningCount: 0 + warningCount: 0, + fatalErrorCount: 0 } ]); }); diff --git a/tests/lib/cli.js b/tests/lib/cli.js index d1fea182db1..634e4db1501 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -803,6 +803,29 @@ describe("cli", () => { }); }); + describe("when given the exit-on-fatal-error flag", () => { + it("should not change exit code if no fatal errors are reported", async () => { + const filePath = getFixturePath("exit-on-fatal-error/no-fatal-error.js"); + const exitCode = await cli.execute(`--no-ignore --exit-on-fatal-error ${filePath}`); + + assert.strictEqual(exitCode, 0); + }); + + it("should exit with exit code 2 fatal error is found", async () => { + const filePath = getFixturePath("exit-on-fatal-error", "fatal-error.js"); + const exitCode = await cli.execute(`--no-ignore --exit-on-fatal-error ${filePath}`); + + assert.strictEqual(exitCode, 2); + }); + + it("should exit with exit code 2 fatal error is found in any file", async () => { + const filePath = getFixturePath("exit-on-fatal-error"); + const exitCode = await cli.execute(`--no-ignore --exit-on-fatal-error ${filePath}`); + + assert.strictEqual(exitCode, 2); + }); + }); + describe("when passed --no-inline-config", () => { let localCLI; diff --git a/tests/lib/eslint/eslint.js b/tests/lib/eslint/eslint.js index c5a1b7360c0..aa35b842eef 100644 --- a/tests/lib/eslint/eslint.js +++ b/tests/lib/eslint/eslint.js @@ -397,6 +397,7 @@ describe("ESLint", () => { messages: [], errorCount: 0, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, output: "var bar = foo;", @@ -597,6 +598,7 @@ describe("ESLint", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, source: "var bar = foo", @@ -636,6 +638,7 @@ describe("ESLint", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 1, fixableErrorCount: 0, fixableWarningCount: 0, output: "var bar = foothis is a syntax error.", @@ -674,6 +677,7 @@ describe("ESLint", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 1, fixableErrorCount: 0, fixableWarningCount: 0, source: "var bar =", @@ -761,6 +765,7 @@ describe("ESLint", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 1, fixableErrorCount: 0, fixableWarningCount: 0, source: "var bar = foothis is a syntax error.\n return bar;", @@ -1658,6 +1663,7 @@ describe("ESLint", () => { messages: [], errorCount: 0, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, output: "true ? \"yes\" : \"no\";\n", @@ -1668,6 +1674,7 @@ describe("ESLint", () => { messages: [], errorCount: 0, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, usedDeprecatedRules: [] @@ -1689,6 +1696,7 @@ describe("ESLint", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, output: "var msg = \"hi\";\nif (msg == \"hi\") {\n\n}\n", @@ -1711,6 +1719,7 @@ describe("ESLint", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, output: "var msg = \"hi\" + foo;\n", @@ -5006,6 +5015,7 @@ describe("ESLint", () => { ], errorCount: 1, warningCount: 0, + fatalErrorCount: 0, fixableErrorCount: 0, fixableWarningCount: 0, source: "/* eslint-disable */", @@ -6060,7 +6070,8 @@ describe("ESLint", () => { ], source: "a == b", usedDeprecatedRules: [], - warningCount: 0 + warningCount: 0, + fatalErrorCount: 0 } ]); }); @@ -6083,7 +6094,8 @@ describe("ESLint", () => { fixableWarningCount: 0, messages: [], usedDeprecatedRules: [], - warningCount: 0 + warningCount: 0, + fatalErrorCount: 0 } ]); }); @@ -6130,7 +6142,8 @@ describe("ESLint", () => { fixableWarningCount: 0, messages: [], usedDeprecatedRules: [], - warningCount: 0 + warningCount: 0, + fatalErrorCount: 0 } ]); }); @@ -6166,7 +6179,8 @@ describe("ESLint", () => { ], source: "a == b", usedDeprecatedRules: [], - warningCount: 0 + warningCount: 0, + fatalErrorCount: 0 } ]); }); From 46caeddfe21f944a196e60772f4d385b686b8389 Mon Sep 17 00:00:00 2001 From: A-Katopodis Date: Mon, 28 Jun 2021 17:14:42 +0200 Subject: [PATCH 3/8] Addressed PR feedback --- docs/user-guide/command-line-interface.md | 2 +- lib/cli.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/user-guide/command-line-interface.md b/docs/user-guide/command-line-interface.md index 1cb41a9a659..7fd51c59033 100644 --- a/docs/user-guide/command-line-interface.md +++ b/docs/user-guide/command-line-interface.md @@ -470,7 +470,7 @@ This option prevents errors when a quoted glob pattern or `--ext` is unmatched. #### `--exit-on-fatal-error` -This option makes ESLint to exit with exit code 2 in case of a fatal error. It allows you to detect if any file was not parsed correctly compared to having rule violations. +This option causes ESLint to exit with exit code 2 if one or more fatal parsing errors occur. Without this option, fatal parsing errors are reported as rule violations. #### `--debug` diff --git a/lib/cli.js b/lib/cli.js index b42da22fb1d..477310da585 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -320,7 +320,7 @@ const cli = { const tooManyWarnings = options.maxWarnings >= 0 && warningCount > options.maxWarnings; - const fatalErrorExists = + const shouldExitForFatalErrors = options.exitOnFatalError && fatalErrorCount > 0; if (!errorCount && tooManyWarnings) { @@ -330,7 +330,7 @@ const cli = { ); } - if (fatalErrorExists) { + if (shouldExitForFatalErrors) { return 2; } From ad8b5ea43076b0543c183cc00db66595fd5829ad Mon Sep 17 00:00:00 2001 From: A-Katopodis Date: Wed, 30 Jun 2021 18:59:00 +0200 Subject: [PATCH 4/8] Made description consistent --- lib/eslint/eslint.js | 1 - lib/options.js | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/eslint/eslint.js b/lib/eslint/eslint.js index 12e9cfae62a..056e04b5945 100644 --- a/lib/eslint/eslint.js +++ b/lib/eslint/eslint.js @@ -59,7 +59,6 @@ const { version } = require("../../package.json"); * @property {string} [resolvePluginsRelativeTo] The folder where plugins should be resolved from, defaulting to the CWD. * @property {string[]} [rulePaths] An array of directories to load custom rules from. * @property {boolean} [useEslintrc] False disables looking for .eslintrc.* files. - * @property {number} exitOnFatalError Number of fatal errors for the result. */ /** diff --git a/lib/options.js b/lib/options.js index 90d6edcaa0b..e3661ec81d5 100644 --- a/lib/options.js +++ b/lib/options.js @@ -204,12 +204,6 @@ module.exports = optionator({ default: "-1", description: "Number of warnings to trigger nonzero exit code" }, - { - option: "exit-on-fatal-error", - type: "Boolean", - default: "false", - description: "Trigger exit code 2 on any fatal errors." - }, { heading: "Output" }, @@ -296,6 +290,12 @@ module.exports = optionator({ default: "true", description: "Prevent errors when pattern is unmatched" }, + { + option: "exit-on-fatal-error", + type: "Boolean", + default: "false", + description: "Exit with exit code 2 in case of fatal error" + }, { option: "debug", type: "Boolean", From 8a82aadc526038a51a8a0c2e475ba0f31357b162 Mon Sep 17 00:00:00 2001 From: A-Katopodis Date: Wed, 7 Jul 2021 01:01:40 +0200 Subject: [PATCH 5/8] Updated dev docs for nodejs-api --- docs/developer-guide/nodejs-api.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md index daa56e76479..d7525bad919 100644 --- a/docs/developer-guide/nodejs-api.md +++ b/docs/developer-guide/nodejs-api.md @@ -355,7 +355,9 @@ The `LintResult` value is the information of the linting result of each file. Th * `fixableWarningCount` (`number`)
The number of warnings that can be fixed automatically by the `fix` constructor option. * `errorCount` (`number`)
- The number of errors. This includes fixable errors. + The number of errors. This includes fixable errors and fatal errors. + `fatalErrorCount` (`number`)
+ The number of fatal errors. * `warningCount` (`number`)
The number of warnings. This includes fixable warnings. * `output` (`string | undefined`)
From 205aca47bb68d4f425a396c4a69f613bc15a72db Mon Sep 17 00:00:00 2001 From: A-Katopodis Date: Wed, 7 Jul 2021 01:29:15 +0200 Subject: [PATCH 6/8] Updated cmd docs --- docs/user-guide/command-line-interface.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user-guide/command-line-interface.md b/docs/user-guide/command-line-interface.md index 7fd51c59033..1e2fdf715c6 100644 --- a/docs/user-guide/command-line-interface.md +++ b/docs/user-guide/command-line-interface.md @@ -81,7 +81,7 @@ Miscellaneous: --init Run config initialization wizard - default: false --env-info Output execution environment information - default: false --no-error-on-unmatched-pattern Prevent errors when pattern is unmatched - default: false - --exit-on-fatal-error Exit with exit code 2 in case of fatal error. - default: false + --exit-on-fatal-error Exit with exit code 2 in case of fatal error - default: false --debug Output debugging information -h, --help Show help -v, --version Output the version number From f9ff856f00fc76ea9d041d5f376018d8a9be714f Mon Sep 17 00:00:00 2001 From: A-Katopodis Date: Wed, 7 Jul 2021 01:29:26 +0200 Subject: [PATCH 7/8] Added test case for 1 exit code --- .../no-fatal-error-rule-violation.js | 3 +++ tests/lib/cli.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/exit-on-fatal-error/no-fatal-error-rule-violation.js diff --git a/tests/fixtures/exit-on-fatal-error/no-fatal-error-rule-violation.js b/tests/fixtures/exit-on-fatal-error/no-fatal-error-rule-violation.js new file mode 100644 index 00000000000..a23ad4a7965 --- /dev/null +++ b/tests/fixtures/exit-on-fatal-error/no-fatal-error-rule-violation.js @@ -0,0 +1,3 @@ +/*eslint no-unused-vars: "error"*/ + +var foo = 1; \ No newline at end of file diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 634e4db1501..26172265f86 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -805,12 +805,19 @@ describe("cli", () => { describe("when given the exit-on-fatal-error flag", () => { it("should not change exit code if no fatal errors are reported", async () => { - const filePath = getFixturePath("exit-on-fatal-error/no-fatal-error.js"); + const filePath = getFixturePath("exit-on-fatal-error", "no-fatal-error.js"); const exitCode = await cli.execute(`--no-ignore --exit-on-fatal-error ${filePath}`); assert.strictEqual(exitCode, 0); }); + it("should exit with exit code 1 if no fatal errors and rule violatios found", async () => { + const filePath = getFixturePath("exit-on-fatal-error", "no-fatal-error-rule-violation.js"); + const exitCode = await cli.execute(`--no-ignore --exit-on-fatal-error ${filePath}`); + + assert.strictEqual(exitCode, 1); + }); + it("should exit with exit code 2 fatal error is found", async () => { const filePath = getFixturePath("exit-on-fatal-error", "fatal-error.js"); const exitCode = await cli.execute(`--no-ignore --exit-on-fatal-error ${filePath}`); @@ -824,6 +831,8 @@ describe("cli", () => { assert.strictEqual(exitCode, 2); }); + + }); describe("when passed --no-inline-config", () => { From f2618b369dd54f2e61720bbb459d1537a616ad00 Mon Sep 17 00:00:00 2001 From: A-Katopodis Date: Mon, 19 Jul 2021 19:53:31 +0200 Subject: [PATCH 8/8] Fixed typos --- docs/developer-guide/nodejs-api.md | 2 +- docs/user-guide/command-line-interface.md | 2 +- tests/lib/cli.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md index d7525bad919..449d1ec08bb 100644 --- a/docs/developer-guide/nodejs-api.md +++ b/docs/developer-guide/nodejs-api.md @@ -356,7 +356,7 @@ The `LintResult` value is the information of the linting result of each file. Th The number of warnings that can be fixed automatically by the `fix` constructor option. * `errorCount` (`number`)
The number of errors. This includes fixable errors and fatal errors. - `fatalErrorCount` (`number`)
+* `fatalErrorCount` (`number`)
The number of fatal errors. * `warningCount` (`number`)
The number of warnings. This includes fixable warnings. diff --git a/docs/user-guide/command-line-interface.md b/docs/user-guide/command-line-interface.md index 1e2fdf715c6..4500e6ff613 100644 --- a/docs/user-guide/command-line-interface.md +++ b/docs/user-guide/command-line-interface.md @@ -81,7 +81,7 @@ Miscellaneous: --init Run config initialization wizard - default: false --env-info Output execution environment information - default: false --no-error-on-unmatched-pattern Prevent errors when pattern is unmatched - default: false - --exit-on-fatal-error Exit with exit code 2 in case of fatal error - default: false + --exit-on-fatal-error Exit with exit code 2 in case of fatal error - default: false --debug Output debugging information -h, --help Show help -v, --version Output the version number diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 26172265f86..dbfe03c26ea 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -811,21 +811,21 @@ describe("cli", () => { assert.strictEqual(exitCode, 0); }); - it("should exit with exit code 1 if no fatal errors and rule violatios found", async () => { + it("should exit with exit code 1 if no fatal errors are found, but rule violations are found", async () => { const filePath = getFixturePath("exit-on-fatal-error", "no-fatal-error-rule-violation.js"); const exitCode = await cli.execute(`--no-ignore --exit-on-fatal-error ${filePath}`); assert.strictEqual(exitCode, 1); }); - it("should exit with exit code 2 fatal error is found", async () => { + it("should exit with exit code 2 if fatal error is found", async () => { const filePath = getFixturePath("exit-on-fatal-error", "fatal-error.js"); const exitCode = await cli.execute(`--no-ignore --exit-on-fatal-error ${filePath}`); assert.strictEqual(exitCode, 2); }); - it("should exit with exit code 2 fatal error is found in any file", async () => { + it("should exit with exit code 2 if fatal error is found in any file", async () => { const filePath = getFixturePath("exit-on-fatal-error"); const exitCode = await cli.execute(`--no-ignore --exit-on-fatal-error ${filePath}`);