loopvar

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 6 Imported by: 0

README

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` ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "loopvar",
	Doc:  "loopvar is a linter that detects places where loop variables are copied.",
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL