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

Return another exit code when files need to be updated #114

Open
myshkin5 opened this issue Feb 3, 2021 · 8 comments
Open

Return another exit code when files need to be updated #114

myshkin5 opened this issue Feb 3, 2021 · 8 comments

Comments

@myshkin5
Copy link

myshkin5 commented Feb 3, 2021

Great tool! Thanks for creating it!

I would like to integrate gofumpt into my CI/CD pipeline so I want to know if there are changes to make. Maybe a command line option could tell gofumpt to return an error exit code if files need to be rewritten. Or this could be the default behavior with the -d option.

@mvdan
Copy link
Owner

mvdan commented Feb 5, 2021

I actually agree that using gofmt/gofumpt in CI/CD is a bit cumbersome, and there have been proposals to make gofmt -d return a non-zero exit status if there are differences. See golang/go#24230.

We'll already be breaking command-line-usage compatibility with gofmt with #105, so I think we can consider this feature then.

@mvdan mvdan added this to the v0.2.0 milestone Mar 11, 2021
@mvdan mvdan removed this from the v0.2.0 milestone May 20, 2021
@mvdan
Copy link
Owner

mvdan commented May 20, 2021

I actually agree that using gofmt/gofumpt in CI/CD is a bit cumbersome, and there have been proposals to make gofmt -d return a non-zero exit status if there are differences. See golang/go#24230.

I ended up opening another upstream issue to make my case for it.

@mvdan
Copy link
Owner

mvdan commented Sep 20, 2021

Err, why did I not link it here? It's golang/go#46289 :)

@Jacalz
Copy link

Jacalz commented Mar 20, 2022

I think this would be a very good change. For anyone else that want to use it in their CI, I’m currently working around it using this instead:
test -z $(gofumpt -d -e . | tee /dev/stderr)
I hope it can help someone until this has been fixed :)

@NoahHakansson
Copy link

I think this would be a very good change. For anyone else that want to use it in their CI, I’m currently working around it using this instead: test -z $(gofumpt -d -e . | tee /dev/stderr) I hope it can help someone until this has been fixed :)

To get rid of the test: too many arguments add "" around it like: test -z "$(gofumpt -d -e . | tee /dev/stderr)" instead

@prologic
Copy link

prologic commented Jan 4, 2023

Any chance we'll see a flag for enabling "exit status on differences"? 🤔

@myshkin5
Copy link
Author

myshkin5 commented Jan 5, 2023

For what it's worth, we now just use golangci-lint. It runs gofumpt in a "linter" mode (and tons of other linters too): https://golangci-lint.run/usage/linters/#gofumpt

@mvdan
Copy link
Owner

mvdan commented Jan 7, 2023

The chances of this feature being done in gofumpt are pretty much 100%. I just want to be careful about adding features before gofmt does, because if gofmt later adds it and in a different way (e.g. different flag name), then the result will be confusing for everyone.

I've left a comment in golang/go#46289 (comment) trying to nudge things along.

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

No branches or pull requests

5 participants