diff --git a/src/cli-util.js b/src/cli-util.js index 8b4eff34d..ad4f6535f 100644 --- a/src/cli-util.js +++ b/src/cli-util.js @@ -58,14 +58,12 @@ function handleError(filename, error) { // parser has mistakenly thrown arrays sometimes.) if (isParseError) { console.error(`${filename}: ${String(error)}`); - } else if ( - isValidationError || - error instanceof errors.ConfigError || - error instanceof errors.DebugError - ) { + } else if (isValidationError || error instanceof errors.ConfigError) { console.error(String(error)); // If validation fails for one file, it will fail for all of them. process.exit(1); + } else if (error instanceof errors.DebugError) { + console.error(`${filename}: ${error.message}`); } else { console.error(filename + ":", error.stack || error); } diff --git a/tests_integration/__tests__/__snapshots__/debug-check.js.snap b/tests_integration/__tests__/__snapshots__/debug-check.js.snap index e6df59357..1a9a58157 100644 --- a/tests_integration/__tests__/__snapshots__/debug-check.js.snap +++ b/tests_integration/__tests__/__snapshots__/debug-check.js.snap @@ -3,3 +3,65 @@ exports[`checks stdin with --debug-check (write) 1`] = `Array []`; exports[`doesn't crash when --debug-check is passed (write) 1`] = `Array []`; + +exports[`show diff for 2+ error files with --debug-check (stderr) 1`] = ` +"a.js: ast(input) !== ast(prettier(input)) +Index: +=================================================================== +--- ++++ +@@ -17,6 +17,6 @@ + \\"method\\": false, + \\"key\\": { +- \\"type\\": \\"StringLiteral\\", +- \\"value\\": \\"a\\" ++ \\"type\\": \\"Identifier\\", ++ \\"name\\": \\"a\\" + }, + \\"computed\\": false, + +Index: +=================================================================== +--- ++++ +@@ -1,3 +1,3 @@ + const a = { +- 'a': 1 ++ a: 1 + }; + +b.js: ast(input) !== ast(prettier(input)) +Index: +=================================================================== +--- ++++ +@@ -17,6 +17,6 @@ + \\"method\\": false, + \\"key\\": { +- \\"type\\": \\"StringLiteral\\", +- \\"value\\": \\"b\\" ++ \\"type\\": \\"Identifier\\", ++ \\"name\\": \\"b\\" + }, + \\"computed\\": false, + +Index: +=================================================================== +--- ++++ +@@ -1,3 +1,3 @@ + const b = { +- 'b': 2 ++ b: 2 + }; + +" +`; + +exports[`show diff for 2+ error files with --debug-check (stdout) 1`] = ` +" + +" +`; + +exports[`show diff for 2+ error files with --debug-check (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/debug-check.js b/tests_integration/__tests__/debug-check.js index 40b3120e4..46394fbcd 100644 --- a/tests_integration/__tests__/debug-check.js +++ b/tests_integration/__tests__/debug-check.js @@ -19,3 +19,9 @@ describe("checks stdin with --debug-check", () => { status: 0 }); }); + +describe("show diff for 2+ error files with --debug-check", () => { + runPrettier("cli/debug-check", ["*.js", "--debug-check"]).test({ + status: "non-zero" + }); +}); diff --git a/tests_integration/cli/debug-check/a.js b/tests_integration/cli/debug-check/a.js new file mode 100644 index 000000000..7ce7d237c --- /dev/null +++ b/tests_integration/cli/debug-check/a.js @@ -0,0 +1,3 @@ +const a = { + 'a': 1 +}; diff --git a/tests_integration/cli/debug-check/b.js b/tests_integration/cli/debug-check/b.js new file mode 100644 index 000000000..c43c70bee --- /dev/null +++ b/tests_integration/cli/debug-check/b.js @@ -0,0 +1,3 @@ +const b = { + 'b': 2 +};