Skip to content

Commit

Permalink
fix: Ensure config keys are printed for config errors (#17980)
Browse files Browse the repository at this point in the history
* fix: Ensure config keys are printed for config errors

fixes #17960

* Remove unnecessary test
  • Loading branch information
nzakas committed Jan 11, 2024
1 parent 320787e commit 6d11f3d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions tests/bin/eslint.js
Expand Up @@ -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]);
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 @@ -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([
Expand Down Expand Up @@ -2264,4 +2264,5 @@ describe("FlatConfigArray", () => {
});

});

});

0 comments on commit 6d11f3d

Please sign in to comment.