dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.07k stars 363 forks source link

quickfix: go1.22 suggest range over int #1514

Open tkw1536 opened 4 months ago

tkw1536 commented 4 months ago

With the release of go1.22, range over integers is now in the language. Code such as:

for i := 0; i < 10; i++ {
   doSomething(i)
}

can be replaced with the more idiomatic:

for i := range 10 {
   doSomething(i)
}

It would be great if staticcheck could add a check to suggest such changes automatically.

dominikh commented 4 months ago

At the moment this is out of scope for staticcheck. We don't want to start flagging over a decade of existing, valid code. We could implement it as a quickfix for gopls, if they don't already have such a check.

ccoVeille commented 4 months ago

If your are interested, there is this linter

https://github.com/ckaznocha/intrange

Available in golangci-lint since 1.57.0