fix: ignore and show warning for unknown option from config file (#2929)
This commit is contained in:
1 parent
51d123b3f1
commit
0d756080b5
4 files changed
+24
-2
No files matched your search
+7
-2
@@ -581,8 +581,13 @@ function normalizeConfig(type, rawConfig, options) {
|
||||
|
||||
const option = constant.detailedOptionMap[key];
|
||||
|
||||
if (type === "cli" && option === undefined) {
|
||||
// unknown option
|
||||
// unknown option
|
||||
if (option === undefined) {
|
||||
// no need to warn for CLI since it's already warned in minimist
|
||||
if (type === "api") {
|
||||
console.warn(`Ignored unknown option: ${rawKey}`);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`show warning with unknown option 1`] = `
|
||||
"Ignored unknown option: hello
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`throw error with invalid config format 1`] = `
|
||||
"Error: Invalid configuration file.
|
||||
Failed to parse \\"<cwd>/tests_integration/cli/config/invalid/file/.prettierrc\\" as JSON, JS, or YAML.
|
||||
|
||||
@@ -45,3 +45,12 @@ test("throw error with invalid config precedence option (configPrecedence)", ()
|
||||
expect(output.stderr).toMatchSnapshot();
|
||||
expect(output.status).not.toBe(0);
|
||||
});
|
||||
|
||||
test("show warning with unknown option", () => {
|
||||
const output = runPrettier("cli/config/invalid", [
|
||||
"--config",
|
||||
"option/unknown"
|
||||
]);
|
||||
expect(output.stderr).toMatchSnapshot();
|
||||
expect(output.status).toBe(0);
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"hello": "world"
|
||||
}
|
||||
Reference in new issue
Block a user