Skip to content

Commit 69dd1d1

Browse files
snitin315nzakas
andauthored
fix: Ensure config keys are printed for config errors (#18067)
* fix: Ensure config keys are printed for config errors * Remove unnecessary test Co-authored-by: Nicholas C. Zakas <[email protected]>
1 parent 9852a31 commit 69dd1d1

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@eslint-community/regexpp": "^4.6.1",
6767
"@eslint/eslintrc": "^2.1.4",
6868
"@eslint/js": "8.56.0",
69-
"@humanwhocodes/config-array": "^0.11.13",
69+
"@humanwhocodes/config-array": "^0.11.14",
7070
"@humanwhocodes/module-importer": "^1.0.1",
7171
"@nodelib/fs.walk": "^1.2.8",
7272
"@ungap/structured-clone": "^1.2.0",

tests/bin/eslint.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,21 @@ describe("bin/eslint.js", () => {
440440
});
441441
});
442442

443+
// https://github.com/eslint/eslint/issues/17960
444+
it("should include key information in the error message when there is an invalid config", () => {
445+
446+
// The error message should include the key name
447+
const config = path.join(__dirname, "../fixtures/bin/eslint.config-invalid-key.js");
448+
const child = runESLint(["--config", config, "conf", "tools"]);
449+
const exitCodeAssertion = assertExitCode(child, 2);
450+
const outputAssertion = getOutput(child).then(output => {
451+
assert.include(output.stderr, "Key \"linterOptions\": Key \"reportUnusedDisableDirectives\"");
452+
});
453+
454+
return Promise.all([exitCodeAssertion, outputAssertion]);
455+
456+
});
457+
443458
it("prints the error message pointing to line of code", () => {
444459
const invalidConfig = path.join(__dirname, "../fixtures/bin/eslint.config.js");
445460
const child = runESLint(["--no-ignore", "-c", invalidConfig]);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = [{
2+
linterOptions: {
3+
reportUnusedDisableDirectives: "banana"
4+
}
5+
}];

tests/lib/config/flat-config-array.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ describe("FlatConfigArray", () => {
10391039
reportUnusedDisableDirectives: {}
10401040
}
10411041
}
1042-
], /Expected one of: "error", "warn", "off", 0, 1, 2, or a boolean./u);
1042+
], /Key "linterOptions": Key "reportUnusedDisableDirectives": Expected one of: "error", "warn", "off", 0, 1, 2, or a boolean./u);
10431043
});
10441044

10451045
it("should merge two objects when second object has overrides", () => assertMergedResult([
@@ -2054,4 +2054,5 @@ describe("FlatConfigArray", () => {
20542054
});
20552055

20562056
});
2057+
20572058
});

0 commit comments

Comments
 (0)