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

fix: Ensure config keys are printed for config errors #18067

Merged
merged 1 commit into from Feb 1, 2024
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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -66,7 +66,7 @@
"@eslint-community/regexpp": "^4.6.1",
"@eslint/eslintrc": "^2.1.4",
"@eslint/js": "8.56.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",
"@ungap/structured-clone": "^1.2.0",
Expand Down
15 changes: 15 additions & 0 deletions tests/bin/eslint.js
Expand Up @@ -440,6 +440,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]);
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/bin/eslint.config-invalid-key.js
@@ -0,0 +1,5 @@
module.exports = [{
linterOptions: {
reportUnusedDisableDirectives: "banana"
}
}];
3 changes: 2 additions & 1 deletion tests/lib/config/flat-config-array.js
Expand Up @@ -1039,7 +1039,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([
Expand Down Expand Up @@ -2054,4 +2054,5 @@ describe("FlatConfigArray", () => {
});

});

});