Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure --list-different + --write reports status code 0 #5512

Merged
merged 2 commits into from Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/cli/util.js
Expand Up @@ -146,8 +146,8 @@ function listDifferent(context, input, options, filename) {
if (!prettier.check(input, options)) {
if (!context.argv["write"]) {
context.logger.log(filename);
process.exitCode = 1;
}
process.exitCode = 1;
}
} catch (error) {
context.logger.error(error.message);
Expand Down Expand Up @@ -498,7 +498,9 @@ function formatFiles(context) {

if (context.argv["list-different"] && isDifferent) {
context.logger.log(filename);
process.exitCode = 1;
if (!context.argv["write"]) {
process.exitCode = 1;
}
}

if (context.argv["write"]) {
Expand Down
2 changes: 1 addition & 1 deletion tests_integration/__tests__/infer-parser.js
Expand Up @@ -113,7 +113,7 @@ describe("--write and --list-different with unknown path and no parser", () => {

describe("multiple files", () => {
runPrettier("cli/infer-parser/", ["--list-different", "--write", "*"]).test(
{ status: 1 }
{ status: 0 }
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests_integration/__tests__/piped-output.js
Expand Up @@ -8,15 +8,15 @@ describe("output with --list-different + unformatted differs when piped", () =>
["--write", "--list-different", "--no-color", "unformatted.js"],
{ stdoutIsTTY: true }
).test({
status: 1
status: 0
});

const result1 = runPrettier(
"cli/write",
["--write", "--list-different", "--no-color", "unformatted.js"],
{ stdoutIsTTY: false }
).test({
status: 1
status: 0
});

expect(result0.stdout.length).toBeGreaterThan(result1.stdout.length);
Expand Down