I don't know of anything that does those rewrites (and haven't looked), but it looks like gofmt -s could support it by extending this type-switch: https://cs.opensource.google/go/go/+/master:src/cmd/gofmt/simplify.go;l=16-103;drc=9b89c380208ea2e85985ee6bf2b1d684274dfa1d
I like the idea of an automatic rewrite of those loop primitives, though. (it's possible that the x := x case may need type/declaration-location information that gofmt doesn't have to do robustly, though) Note: the go fix directory hasn't had any commits since August, so it doesn't appear to have it either. (that might be the right place for that rewrite -- although, I think vet also has a suggested fix capacity that would make sense for any module with the go line set to 1.22+) On Tue, Jan 16, 2024 at 1:33 AM Amnon <amno...@gmail.com> wrote: > Go 1.22 contains some cool features which will allow us to write simpler > code. > > Would it be possible for gofmt -s to help us do transformations which > clean up old code such as > for i := 0; i < n; i++ -> for i := range n > removing x := x assignments inside range loops > or updating code to use the new math/rand/v2 API? > > If not, has anyone written any refactoring tools to do this? > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/91a531a9-5043-4357-b643-d1600dcae119n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/91a531a9-5043-4357-b643-d1600dcae119n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CANrC0BjVSPpqKF%3DUWppq3zS_NNjKvjsjKj6UmaaMy%2BCnrR7q4A%40mail.gmail.com.