Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

karamaru-alpha/loopvar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loopvar

loopvar is a linter that detects places where loop variables are copied.

cf. Fixing For Loops in Go 1.22

Example

for i, v := range []int{1, 2, 3} {
    i := i // The loop variable "i" should not be copied (Go 1.22~ or Go 1.21 GOEXPERIMENT=loopvar)
    v := v // The loop variable "v" should not be copied (Go 1.22~ or Go 1.21 GOEXPERIMENT=loopvar)
    _, _ = i, v
}

for i := 1; i <= 3; i++ {
    i := i // The loop variable "i" should not be copied (Go 1.22~ or Go 1.21 GOEXPERIMENT=loopvar)
    _ = i
}

Install

go install github.com/karamaru-alpha/loopvar/cmd/loopvar
go vet -vettool=`which loopvar` ./...

About

loopvar is a linter that detects places where loop variables are copied.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages