Skip to content

Commit

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

* Remove unnecessary test

Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
  • Loading branch information
snitin315 and nzakas committed Feb 1, 2024
1 parent 9852a31 commit 69dd1d1
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 @@ -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", () => {
});

});

});

0 comments on commit 69dd1d1

Please sign in to comment.