-
Notifications
You must be signed in to change notification settings - Fork 18k
Proposal: Allow go fmt to return non-zero if code violations are found #41189
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
Comments
I personally agree. The |
Apologies for the extra output. I don't believe the exit code should change based on whether files were reformatted. |
Hi @rsc, there is no doubt that reformatting files is expected behavior and it should return success. I don't think that should be changed. However, from my experience and from what I read, it's a common practice to use I understand that maybe more proper behavior would be to add I just tried below but on CI there is no /dev/tty, I'm out of ideas.
Feel free to close the issue, just wanted to share the pain and point out to new issue with printing output. |
A few comments related to CI systems.
I am not sure what you were trying to do with the |
In other language ecosystems, one common solution to (1)/(3) is to pin a
Thus, you have (Personally, I’ve worked with all these ecosystems, and (1) and (3) have Is there a reason that a solution like this is less attractive for Go? |
@wchargin What you described seems to be a popular solution used by many Go projects (aside from the |
@dmitshur: Good to know; thanks. I’ll go with that for my project, then, |
Allow gofmt to return non-zero if code violations are found.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
I know this topic was rejected several times (#24427, #24230) but things changed since last time and
go fmt
downloads now dependencies (#31976, #30577) and prints them to stderr breaking above hack ifgo fmt ./...
is wrapped in another script e.g.test -z $(make -s fmt)
. This is really annoying. Also the trick hides the output. I understand sometimes it's trivial to use other tools to bypass the issue but this gets more and more complicated and we have no guarantee it won't change in the future.I'm trying right now to have, both, status code = 1 and output and I'm running out of ideas. I also don't like the idea of filtering stderr from
go fmt
output to get rid of those "go: downloading". Not to mention that most of the people not familiar with shell cringe when they seetest -z
.There is clearly need for fmt to exit with status code=1 (an option) and return info which files got changed to verify if project is correctly formatted.
Is there any chance to have another look at this and simplify our lives?
The text was updated successfully, but these errors were encountered: