golangci-lint/test/ruleguard/rangeExprCopy.go
2023-10-05 14:21:43 +02:00

16 lines
338 B
Go

//go:build ruleguard
package ruleguard
import (
"github.com/quasilyte/go-ruleguard/dsl"
)
func RangeExprVal(m dsl.Matcher) {
m.Match(`for _, $_ := range $x { $*_ }`, `for _, $_ = range $x { $*_ }`).
Where(m["x"].Addressable && m["x"].Type.Size >= 512).
Report(`$x copy can be avoided with &$x`).
At(m["x"]).
Suggest(`&$x`)
}