Skip to content

Commit

Permalink
ensure --list-different + --write reports status code 0 (#5512)
Browse files Browse the repository at this point in the history
* change exit code for list different and write

* update existing tests
  • Loading branch information
outofambit authored and j-f1 committed Nov 23, 2018
1 parent 7da4ed7 commit e12cd17
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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

0 comments on commit e12cd17

Please sign in to comment.