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

Allow `--write` to be used with `--list-different` #1633

Merged
merged 2 commits into from May 21, 2017

Conversation

Projects
None yet
3 participants
@josephfrazier
Copy link
Collaborator

josephfrazier commented May 19, 2017

This makes it possible to simultaneously check for formatting errors and
fix them, which can be useful for CI services. For example, a CI service
could run:

prettier --list-different --write $FILES || git diff --exit-code

to show the formatting errors. Before this change, it would be necessary
to do:

prettier --list-different $FILES || (prettier --write $FILES; git diff --exit-code)

Here are some commands which are useful to verify that the outputs and
exit codes of prettier --list-different and prettier --write have
not changed:

./bin/prettier.js --list-different index.js src/*.js bin/*.js; echo $?
./bin/prettier.js --write index.js src/*.js bin/*.js; echo $?

josephfrazier added some commits May 19, 2017

Allow `--write` to be used with `--list-different`
This makes it possible to simultaneously check for formatting errors and
fix them, which can be useful for CI services. For example, a CI service
could run:

    prettier --list-different --write $FILES || git diff --exit-code

to show the formatting errors. Before this change, it would be necessary
to do:

    prettier --list-different $FILES || (prettier --write $FILES; git diff --exit-code)

Here are some commands which are useful to verify that the outputs and
exit codes of `prettier --list-different` and `prettier --write` have
not changed:

    ./bin/prettier.js --list-different index.js src/*.js bin/*.js; echo $?
    ./bin/prettier.js --write index.js src/*.js bin/*.js; echo $?

@vjeux vjeux merged commit 226adb2 into prettier:master May 21, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@vjeux

This comment has been minimized.

Copy link
Collaborator

vjeux commented May 21, 2017

Thanks!

@lydell

This comment has been minimized.

Copy link
Collaborator

lydell commented May 1, 2018

Hi! I’m thinking about CLI improvements for 2.0 in #3503. I’m having trouble understanding what this PR does.

How is

prettier --list-different --write $FILES || git diff --exit-code

different from

prettier --write $FILES
git diff --exit-code

?

@lydell

This comment has been minimized.

Copy link
Collaborator

lydell commented May 2, 2018

@josephfrazier The reason I’m asking is because I’m toying with the idea of making the CLI work like this:

# like today’s `--list-different`
prettier .

# like today’s `prettier "**/*.{js,css,md,etc}" --write`
prettier . --write

So then there won’t be a way to combine --write and --list-different. Which is why I need to understand what this PR does and why.

@josephfrazier

This comment has been minimized.

Copy link
Collaborator Author

josephfrazier commented May 5, 2018

To be honest, I don't remember what the original motivation for this fix was, other than just making this combination of flags do something relatively intuitive. I don't have any personal reasons against CLI changes, and what you're proposing sounds like it'll be easier to use and more consistent with other tools 👍

@lock lock bot locked as resolved and limited conversation to collaborators Aug 3, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.