Ignore i (index) in for loop
palsivertsen opened this issue · comments
Pål Sivertsen commented
Given this main.go file:
package main
func main() {
for i := range []struct{}{} {
/*
Lorem
ipsum
dolor
sit
amet.
*/
_ = i
}
}
And this config (golangci.yaml):
linters:
disable-all: true
enable:
- varnamelen
linters-settings:
varnamelen:
ignore-decls:
- i int
I should not get an error for main.go:4:6, but I get the following error when running golangci-lint run
:
main.go:4:6: variable name 'i' is too short for the scope of its usage (varnamelen)
for i := range []struct{}{} {
^
Maik Schreiber commented
This is probably related to #10 (comment), in that range returns multiple-values.
Pål Sivertsen commented
Yes, probably.
I did a test using v0.6.1
and it's still a problem:
$ varnamelen -ignoreDecls "i int" ./...
/tmp/tmp.2OkqA0HPDD/main.go:4:6: variable name 'i' is too short for the scope of its usage
Maik Schreiber commented
varnamelen v0.7.0 contains improvements to the way the types of idents are inferred, so this should work now.
Pål Sivertsen commented
Confirmed. Thank you!