From 6d11f3dac1b76188d7fda6e772e89b5c3945ac4d Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 11 Jan 2024 11:19:07 -0700 Subject: [PATCH] fix: Ensure config keys are printed for config errors (#17980) * fix: Ensure config keys are printed for config errors fixes #17960 * Remove unnecessary test --- package.json | 2 +- tests/bin/eslint.js | 15 +++++++++++++++ tests/fixtures/bin/eslint.config-invalid-key.js | 5 +++++ tests/lib/config/flat-config-array.js | 3 ++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/bin/eslint.config-invalid-key.js diff --git a/package.json b/package.json index adc23204b1a..9c6bec19fd6 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "@eslint-community/regexpp": "^4.6.1", "@eslint/eslintrc": "^3.0.0", "@eslint/js": "9.0.0-alpha.0", - "@humanwhocodes/config-array": "^0.11.13", + "@humanwhocodes/config-array": "^0.11.14", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", "ajv": "^6.12.4", diff --git a/tests/bin/eslint.js b/tests/bin/eslint.js index c4c67b9594d..c15dbc46102 100644 --- a/tests/bin/eslint.js +++ b/tests/bin/eslint.js @@ -438,6 +438,21 @@ describe("bin/eslint.js", () => { }); }); + // https://github.com/eslint/eslint/issues/17960 + it("should include key information in the error message when there is an invalid config", () => { + + // The error message should include the key name + const config = path.join(__dirname, "../fixtures/bin/eslint.config-invalid-key.js"); + const child = runESLint(["--config", config, "conf", "tools"]); + const exitCodeAssertion = assertExitCode(child, 2); + const outputAssertion = getOutput(child).then(output => { + assert.include(output.stderr, "Key \"linterOptions\": Key \"reportUnusedDisableDirectives\""); + }); + + return Promise.all([exitCodeAssertion, outputAssertion]); + + }); + it("prints the error message pointing to line of code", () => { const invalidConfig = path.join(__dirname, "../fixtures/bin/eslint.config.js"); const child = runESLint(["--no-ignore", "-c", invalidConfig]); diff --git a/tests/fixtures/bin/eslint.config-invalid-key.js b/tests/fixtures/bin/eslint.config-invalid-key.js new file mode 100644 index 00000000000..d7840c15304 --- /dev/null +++ b/tests/fixtures/bin/eslint.config-invalid-key.js @@ -0,0 +1,5 @@ +module.exports = [{ + linterOptions: { + reportUnusedDisableDirectives: "banana" + } +}]; diff --git a/tests/lib/config/flat-config-array.js b/tests/lib/config/flat-config-array.js index bb76529250d..cfaa3ebd906 100644 --- a/tests/lib/config/flat-config-array.js +++ b/tests/lib/config/flat-config-array.js @@ -1043,7 +1043,7 @@ describe("FlatConfigArray", () => { reportUnusedDisableDirectives: {} } } - ], /Expected one of: "error", "warn", "off", 0, 1, 2, or a boolean./u); + ], /Key "linterOptions": Key "reportUnusedDisableDirectives": Expected one of: "error", "warn", "off", 0, 1, 2, or a boolean./u); }); it("should merge two objects when second object has overrides", () => assertMergedResult([ @@ -2264,4 +2264,5 @@ describe("FlatConfigArray", () => { }); }); + });