CLI: Don't suggest -_ for unknown flags (#8934)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-08-10 21:57:54 +08:00
1 parent 25398a943f
commit a340799a3d
4 files changed
+36 -1

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
#### Stop suggesting `-_` for unknown options ([#8934](https://github.com/prettier/prettier/pull/8934) by [@fisker](https://github.com/fisker))
```console
# Prettier stable
$ prettier foo.js -a
[warn] Ignored unknown option -a. Did you mean -_?
# Prettier master
$ prettier foo.js -a
[warn] Ignored unknown option -a. Did you mean -c?
```
+8 -1
View File
@@ -55,7 +55,14 @@ function normalizeOptions(
{ logger, isCLI = false, passThrough = false } = {}
) {
const unknown = !passThrough
? vnopts.levenUnknownHandler
? (key, value, options) => {
// Don't suggest `_` for unknown flags
const { _, ...schemas } = options.schemas;
return vnopts.levenUnknownHandler(key, value, {
...options,
schemas,
});
}
: Array.isArray(passThrough)
? (key, value) =>
!passThrough.includes(key) ? undefined : { [key]: value }
@@ -45,3 +45,13 @@ exports[`unknown options are warned (stdout) 1`] = `
`;
exports[`unknown options are warned (write) 1`] = `Array []`;
exports[`unknown options not suggestion \`_\` (stderr) 1`] = `
"[warn] Ignored unknown option -a. Did you mean -c?
"
`;
exports[`unknown options not suggestion \`_\` (stdout) 1`] = `
"console.log(\\"could be single quote and without semi\\");
"
`;
@@ -46,6 +46,13 @@ describe("unknown negated options are warned", () => {
});
});
describe("unknown options not suggestion `_`", () => {
runPrettier("cli/arg-parsing", ["file.js", "-a"]).test({
status: 0,
write: [],
});
});
describe("allow overriding flags", () => {
runPrettier(
"cli/arg-parsing",