You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when gofmt is executed, it will identify and correct formatting issues, but will exit with an exit code of 0. This is ordinarily acceptable, but can be annoying in particular instances.
I always use gofmt ./... in my Continuous Integration pipelines, and fail the pipeline if any formatting errors were present. At the moment, I use some bash magic like this:
echo'running go fmt on all packages...'
invalidFiles=$(gofmt -l ./... 2>&1)if [ "$invalidFiles" ];thenecho"These files did not pass the 'go fmt' check, please run 'go fmt' on them:"echo$invalidFilesexit 1
fi
(I realize this could be shortened, but it's easiest to understand in this form)
Obviously, this works fine. But It's slightly annoying repeating this when it seems logical that the gofmt command could simply exit with a non-zero exit code.
The Proposal
Add a flag to the gofmt tool that will set the exit code to 1 when any formatting issues are detected. I was originally thinking -e, but this is already taken. Perhaps -x is acceptable?
This is the behavior I would like to see with this flag:
> gofmt -l -x ./...
src/some/file.go
>echo$?
1
Thoughts? Is the simplification of the testing pipeline worth the (minor) complexity added to the gofmt tool? If it sounds good, I can probably have a PR up for it pretty quickly.
The text was updated successfully, but these errors were encountered:
The 'Problem'
Currently, when
gofmt
is executed, it will identify and correct formatting issues, but will exit with an exit code of0
. This is ordinarily acceptable, but can be annoying in particular instances.I always use
gofmt ./...
in my Continuous Integration pipelines, and fail the pipeline if any formatting errors were present. At the moment, I use some bash magic like this:(I realize this could be shortened, but it's easiest to understand in this form)
Obviously, this works fine. But It's slightly annoying repeating this when it seems logical that the
gofmt
command could simply exit with a non-zero exit code.The Proposal
Add a flag to the
gofmt
tool that will set the exit code to1
when any formatting issues are detected. I was originally thinking-e
, but this is already taken. Perhaps-x
is acceptable?This is the behavior I would like to see with this flag:
Thoughts? Is the simplification of the testing pipeline worth the (minor) complexity added to the
gofmt
tool? If it sounds good, I can probably have a PR up for it pretty quickly.The text was updated successfully, but these errors were encountered: