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

Add --exit-code to buf format #1033

Merged
merged 1 commit into from
Mar 25, 2022
Merged

Add --exit-code to buf format #1033

merged 1 commit into from
Mar 25, 2022

Conversation

bufdev
Copy link
Member

@bufdev bufdev commented Mar 25, 2022

Fixes #1030.

This makes it so that buf format exits with a non-zero exit code if files were not already formatted. Common invocations:

# Print the diff and exit with non-zero exit code if there is a diff
$ buf format -d --exit-code
# Print nothing and exit with non-zero exit code if there is a diff
$ buf format --exit-code >/dev/null

@bufdev bufdev requested a review from doriable March 25, 2022 17:06
@@ -1944,19 +1944,6 @@ func TestFormatDiff(t *testing.T) {
@@ -1,13 +1,7 @@
-
syntax = "proto3";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is affected if there is whitespace or not in the diff - this is kind of a mess across IDEs, just simplifying it to test what we need to

stdoutCopy := bytes.NewBuffer(nil)
if stdout == nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This came up as a panic in the tests when I had stdout as nil - this makes it so that stdout/stderr can be nil

@bufdev bufdev merged commit 05a7f39 into main Mar 25, 2022
@bufdev bufdev deleted the format-exit-code branch March 25, 2022 17:16
christophermaier added a commit to grapl-security/grapl that referenced this pull request Mar 25, 2022
Now we don't need to go through a helper script, because an
`--exit-code` was added with bufbuild/buf#1033.

Signed-off-by: Christopher Maier <[email protected]>
Comment on lines +5 to +6
- Add `--exit code` flag to `buf format` to exit with a non-zero exit code if
the files were not already formatted.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(you may mean --exit-code not --exit code)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, yes -- we were a bit excited about this. Thanks for catching this and we'll update the changelog :)

Monirul1 pushed a commit to Monirul1/buf that referenced this pull request Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make buf format --diff exit with non-zero code if a difference is found
3 participants