mvdan / gofumpt

A stricter gofmt
https://pkg.go.dev/mvdan.cc/gofumpt
BSD 3-Clause "New" or "Revised" License
3.15k stars 110 forks source link

add simplifications for Go 1.22 #291

Closed amnonbc closed 5 months ago

amnonbc commented 5 months ago

Enhancement request:

Can gofumpt do code simplifications enabled by go 1.22

e.g.

for i := 0; i < n; i++ -> for i := range n

or updating usages of math/rand to v2?

mvdan commented 5 months ago

For math/rand, definitely not. That is way too invasive for a formatter. Such non-trivial rewrites need type information and are more suited for e.g. go fix or staticcheck.

For integer loops, I guess we could try to do it without type information, but I think once again it's not really the right tool. You would ideally also want to rewrite the foo := foo pattern fixed by 1.22's new variable scoping in loops, per https://tip.golang.org/doc/go1.22#language. I think both of those should be done by a static analysis tool, which gofumpt is not, because computing type information would make it way too slow.