prettier: CLI: --list-different + --write = Exit status 1 if something was modified
It doesn’t play very well with npm scripts:
d:\dev\foo>npm run format
> @ format d:\dev\foo
> prettier --write --list-different *.js
foo.js
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ format: `prettier --write --list-different *.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ format script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Without --list-different
though it doesn’t behave like this.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 17 (8 by maintainers)
@bennyn
--list-different
without--write
is a check. It checks that the files are formatted properly and lists the ones that aren’t. It’s totally expected that it fails with the exit code 1 when it finds something (package.json
in your case).With
--write
however, Prettier immediately reformats the files rectifying all the formatting problems, so this exit code 1 makes very little sense in that case. Meanwhile,--write
is too verbose without--list-different
. That’s why I’d like to use them together. And that’s what this issue is about.I’d like an exit code
1
when something is changed so I can use it in git hooks.@j-f1 I’m using
--write
and--list-different
to write & get an exit code of1
when something is written, which ensures my git hook is aborted. Can I rely on this, or will there be a different method to ensure an exit1
when using--write
?@aMoniker From my reading of this issue, the current behavior of exiting with
1
if--list-different
is passed, but--write
isn’t will remain.Sorry @thorn0 for this misunderstanding - everything works as expected in the documentation 😄
I also have issues with my CI when using
--list-different
:Without
--list-different
it works.EDIT: I found out that it crashed because it didn’t like the formatting of
package.json
. The output in the CLI was not very self explanatory. 🙈I use yarn/npm to run prettier and I am getting the error “Exit status 1” or “Exit code 1” for pretty much any command, except for “–help” and “-v”.
If I install and run prettier globally then there are no errors.