Closed amnonbc closed 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.
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?