blizzy78 / varnamelen

Go analyzer checking that the length of a variable's name matches its usage scope

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ignore i (index) in for loop

palsivertsen opened this issue · comments

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{}{} {
	   ^

This is probably related to #10 (comment), in that range returns multiple-values.

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

varnamelen v0.7.0 contains improvements to the way the types of idents are inferred, so this should work now.

Confirmed. Thank you!