Add --debug-check cli option (#627)

This let's you run `pp(x) === pp(pp(x))` across an entire codebase quickly. I think it's small enough that we can merge it in to master while we are nailing down all the issues.

You can see the output in #610
master
Christopher Chedeau 2017-02-07 07:04:44 -08:00 committed by James Long
parent ee593bb645
commit 4df5250f74
2 changed files with 15 additions and 2 deletions

View File

@ -23,6 +23,7 @@ const argv = minimist(process.argv.slice(2), {
"help",
"version",
"debug-print-doc",
"debug-check",
// Deprecated in 0.0.10
"flow-parser"
],
@ -131,6 +132,17 @@ function format(input) {
const doc = prettier.__debug.printToDoc(input, options);
return prettier.__debug.formatDoc(doc);
}
if (argv["debug-check"]) {
const pp = prettier.format(input, options);
const pppp = prettier.format(pp, options);
if (pp !== pppp) {
const diff = require('diff').createTwoFilesPatch('', '', pp, pppp, '', '', {context: 2});
console.error(diff);
}
return;
}
return prettier.format(input, options);
}
@ -171,7 +183,7 @@ if (stdin) {
} else {
eachFilename(filepatterns, filename => {
fs.readFile(filename, "utf8", (err, input) => {
if (write) {
if (write || argv["debug-check"]) {
console.log(filename);
}

View File

@ -34,7 +34,8 @@
"rollup-plugin-node-builtins": "2.0.0",
"rollup-plugin-node-globals": "1.1.0",
"rollup-plugin-node-resolve": "2.0.0",
"rollup-plugin-real-babili": "1.0.0-alpha3"
"rollup-plugin-real-babili": "1.0.0-alpha3",
"diff": "3.2.0"
},
"scripts": {
"test": "jest",