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

Using rewrite rules with gofumpt #275

Closed
silverwind opened this issue Jul 4, 2023 · 3 comments
Closed

Using rewrite rules with gofumpt #275

silverwind opened this issue Jul 4, 2023 · 3 comments

Comments

@silverwind
Copy link

silverwind commented Jul 4, 2023

I would like to rewrite interface{} to any, but the docs seem unclear about rewrite rules:

Finally, note that the -r rewrite flag is removed in favor of gofmt -r, and the -s flag is hidden as it is always enabled.

What does this statement mean? Does one need to run gofmt before gofumpt to be able to use rewrite rules? A docs clarification would be nice.

Also, I wonder how a tool that is advertized as a "drop-in replacement" does not support all features of the tool it's meant to replace.

@mvdan
Copy link
Owner

mvdan commented Jul 8, 2023

Correct, there isn't a gofumpt -r because you should use gofmt -r. There are three reasons for this:

  1. gofmt -r works, and gofumpt is not in the business of pattern rewrites.
  2. gofmt -r has always been quite limited by design; https://github.com/rsc/rf is their new attempt and it's far more powerful. I don't see a point in investing more time into gofmt -r, particularly since neither approach has anything to do with canonical formatting.
  3. It is a surprisingly complex chunk of code that we don't need to maintain on our end.

Also note that our README says:

It can be used as a drop-in replacement to format your Go code

I think that still holds true; at least in my head, rewrite rules have little to do with canonical formatting like gofmt or gofumpt.

In any case, I'm happy to get input on better ways to document both of these aspects :)

@silverwind
Copy link
Author

silverwind commented Jul 8, 2023

I guess in the end such "rewrites" are the job of a linter's autofix, e.g. ruff --fix or eslint --fix serve the purpose very will in those respective languages, but golang's linter's are rudimentary compared to those two, golangci's --fix is borderline useless.

I still hope a better go linter arises, golangci really pales in comparision to what other linters can do.

@mvdan
Copy link
Owner

mvdan commented Jul 13, 2023

I'm going to close this then, as it seems like the misunderstanding is solved. Still happy to receive suggestions in terms of better wording - in that case please send a PR.

@mvdan mvdan closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 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

No branches or pull requests

2 participants