Skip to content

"gofmt -d" should have non-zero exit if there is a diff #38551

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

Closed
belm0 opened this issue Apr 21, 2020 · 1 comment
Closed

"gofmt -d" should have non-zero exit if there is a diff #38551

belm0 opened this issue Apr 21, 2020 · 1 comment

Comments

@belm0
Copy link

belm0 commented Apr 21, 2020

What version of Go are you using (go version)?

$ go version
go version go1.13.4 darwin/amd64

What did you do?

$ gofmt -d .
(... diff ...)
$ echo $?
0

What did you expect to see?

Exit value of 1, since there is a diff.

Presence of a diff is the error case, meaning that the code requires formatting. Then for example, makefile targets to check formatting can simply be "gofmt -d ." and do the right thing.

What did you see instead?

exit value of 0

@ALTree
Copy link
Member

ALTree commented Apr 21, 2020

Hi,

this was requested in #24230 and #24427, and rejected. As noted in #24230, you can already check if gofmt -l is empty. Closing here as a dup of #24230.

@ALTree ALTree closed this as completed Apr 21, 2020
@golang golang locked and limited conversation to collaborators Apr 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants