blizzy78 / varnamelen

Go analyzer checking that the length of a variable's name matches its usage scope
MIT License
20 stars 2 forks source link

Ignore i (index) in for loop #12

Closed palsivertsen closed 2 years ago

palsivertsen commented 2 years ago

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{}{} {
       ^
blizzy78 commented 2 years ago

This is probably related to https://github.com/blizzy78/varnamelen/issues/10#issuecomment-1030751753, in that range returns multiple-values.

palsivertsen commented 2 years ago

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
blizzy78 commented 2 years ago

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

palsivertsen commented 2 years ago

Confirmed. Thank you!