Show invalid config filename in error message (#6865)
This commit is contained in:
1 parent
304acbea01
commit
91c5235a3f
4 files changed
+32
-5
No files matched your search
@@ -1406,6 +1406,20 @@ async function f() {
|
||||
}
|
||||
```
|
||||
|
||||
#### CLI: Display invalid config filename in error message ([#6865] by [@fisker])
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```bash
|
||||
# Input
|
||||
$ prettier filename.js --config .invalid-config
|
||||
|
||||
# Output (Prettier stable)
|
||||
Invalid configuration file: ...
|
||||
|
||||
# Output (Prettier master)
|
||||
Invalid configuration file `.invalid-config`: ...
|
||||
```
|
||||
|
||||
[#5682]: https://github.com/prettier/prettier/pull/5682
|
||||
[#6657]: https://github.com/prettier/prettier/pull/6657
|
||||
[#5910]: https://github.com/prettier/prettier/pull/5910
|
||||
@@ -1456,6 +1470,7 @@ async function f() {
|
||||
[#6796]: https://github.com/prettier/prettier/pull/6796
|
||||
[#6848]: https://github.com/prettier/prettier/pull/6848
|
||||
[#6856]: https://github.com/prettier/prettier/pull/6856
|
||||
[#6865]: https://github.com/prettier/prettier/pull/6865
|
||||
[#6863]: https://github.com/prettier/prettier/pull/6863
|
||||
[@brainkim]: https://github.com/brainkim
|
||||
[@duailibe]: https://github.com/duailibe
|
||||
@@ -1478,4 +1493,5 @@ async function f() {
|
||||
[@andersk]: https://github.com/andersk
|
||||
[@lydell]: https://github.com/lydell
|
||||
[@aymericbouzy]: https://github.com/aymericbouzy
|
||||
[@fisker]: https://github.com/fisker
|
||||
[@jridgewell]: https://github.com/jridgewell
|
||||
+3
-1
@@ -284,7 +284,9 @@ function getOptionsOrDie(context, filePath) {
|
||||
context.logger.debug("loaded options `" + JSON.stringify(options) + "`");
|
||||
return options;
|
||||
} catch (error) {
|
||||
context.logger.error("Invalid configuration file: " + error.message);
|
||||
context.logger.error(
|
||||
`Invalid configuration file \`${filePath}\`: ` + error.message
|
||||
);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ exports[`show warning with unknown option (stdout) 1`] = `""`;
|
||||
exports[`show warning with unknown option (write) 1`] = `Array []`;
|
||||
|
||||
exports[`throw error for unsupported extension (stderr) 1`] = `
|
||||
"[error] Invalid configuration file: No sync loader specified for extension \\".unsupported\\"
|
||||
"[error] Invalid configuration file \`<cwd>/tests_integration/cli/config/invalid\`: No sync loader specified for extension \\".unsupported\\"
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -28,7 +28,7 @@ exports[`throw error for unsupported extension (stdout) 1`] = `""`;
|
||||
exports[`throw error for unsupported extension (write) 1`] = `Array []`;
|
||||
|
||||
exports[`throw error with invalid config format (stderr) 1`] = `
|
||||
"[error] Invalid configuration file: Cannot find module '--invalid--' from '<cwd>/tests_integration/cli/config/invalid/file'
|
||||
"[error] Invalid configuration file \`<cwd>/tests_integration/cli/config/invalid\`: Cannot find module '--invalid--' from '<cwd>/tests_integration/cli/config/invalid/file'
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -64,7 +64,7 @@ exports[`throw error with invalid config precedence option (configPrecedence) (s
|
||||
exports[`throw error with invalid config precedence option (configPrecedence) (write) 1`] = `Array []`;
|
||||
|
||||
exports[`throw error with invalid config target (directory) (stderr) 1`] = `
|
||||
"[error] Invalid configuration file: EISDIR: illegal operation on a directory, read
|
||||
"[error] Invalid configuration file \`<cwd>/tests_integration/cli/config/invalid\`: EISDIR: illegal operation on a directory, read
|
||||
"
|
||||
`;
|
||||
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
const replaceCWD = text => {
|
||||
const cwd = process.cwd();
|
||||
while (text.indexOf(cwd) !== -1) {
|
||||
text = text.replace(cwd, "<cwd>");
|
||||
}
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
test: value =>
|
||||
typeof value === "string" &&
|
||||
(value.indexOf("\\") > -1 || value.indexOf(process.cwd()) > -1),
|
||||
print: (value, serializer) =>
|
||||
serializer(value.replace(process.cwd(), "<cwd>").replace(/\\/g, "/"))
|
||||
serializer(replaceCWD(value).replace(/\\/g, "/"))
|
||||
};
|
||||
Reference in new issue
Block a user