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

quickfix: go1.22 suggest range over int #1514

Open
tkw1536 opened this issue Apr 7, 2024 · 2 comments
Open

quickfix: go1.22 suggest range over int #1514

tkw1536 opened this issue Apr 7, 2024 · 2 comments

Comments

@tkw1536
Copy link

tkw1536 commented Apr 7, 2024

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.

@tkw1536 tkw1536 added the needs-triage Newly filed issue that needs triage label Apr 7, 2024
@dominikh
Copy link
Owner

dominikh commented Apr 7, 2024

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.

@dominikh dominikh added new-check and removed needs-triage Newly filed issue that needs triage labels Apr 7, 2024
@dominikh dominikh changed the title staticcheck: go1.22 suggest range over int quickfix: go1.22 suggest range over int Apr 7, 2024
@ccoVeille
Copy link

If your are interested, there is this linter

https://github.com/ckaznocha/intrange

Available in golangci-lint since 1.57.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants