Mention --debug-check in CLI section of README (#1562)
* Prevent using --write with --debug-check This addresses https://github.com/prettier/prettier/issues/1552#issuecomment-300043294 * Exit with a non-zero code if --debug-check fails This makes it easier to use programmatically. See https://github.com/prettier/prettier/issues/1552#issuecomment-300042417 * Mention --debug-check in CLI section of README This addresses https://github.com/prettier/prettier/issues/1552#issuecomment-300043294master
parent
09fd8de526
commit
225fa57780
|
@ -156,6 +156,10 @@ expands the globs rather than your shell, for cross-platform usage.)
|
|||
|
||||
In the future we will have better support for formatting whole projects.
|
||||
|
||||
If you're worried that Prettier will change the correctness of your code, add `--debug-check` to the command.
|
||||
This will cause Prettier to print an error message if it detects that code correctness might have changed.
|
||||
Note that `--write` cannot be used with `--debug-check`.
|
||||
|
||||
#### Pre-commit hook for changed files
|
||||
|
||||
You can use this with a pre-commit tool. This can re-format your files that are marked as "staged" via `git add` before you commit.
|
||||
|
|
|
@ -53,6 +53,11 @@ const filepatterns = argv["_"];
|
|||
const write = argv["write"];
|
||||
const stdin = argv["stdin"] || (!filepatterns.length && !process.stdin.isTTY);
|
||||
|
||||
if (write && argv["debug-check"]) {
|
||||
console.error("Cannot use --write and --debug-check together.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function getParserOption() {
|
||||
const optionName = "parser";
|
||||
const value = argv[optionName];
|
||||
|
@ -151,6 +156,7 @@ function format(input) {
|
|||
process.stdout.write("\n");
|
||||
console.error('prettier(input) !== prettier(prettier(input))');
|
||||
console.error(diff(pp, pppp));
|
||||
process.exitCode = 2;
|
||||
} else {
|
||||
const ast = cleanAST(prettier.__debug.parse(input, options));
|
||||
const past = cleanAST(prettier.__debug.parse(pp, options));
|
||||
|
@ -160,6 +166,7 @@ function format(input) {
|
|||
console.error('ast(input) !== ast(prettier(input))');
|
||||
console.error(diff(ast, past));
|
||||
console.error(diff(input, pp));
|
||||
process.exitCode = 2;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -292,6 +299,8 @@ if (stdin) {
|
|||
process.stdout.write("\n");
|
||||
if (output) {
|
||||
console.log(output);
|
||||
} else {
|
||||
process.exitCode = 2;
|
||||
}
|
||||
} else {
|
||||
// Don't use `console.log` here since it adds an extra newline at the end.
|
||||
|
|
Loading…
Reference in New Issue