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

treat multi-line definitions as a single line

vikstrous2 opened this issue · comments

$ cat main.go
package main

type A struct {
        a1 int
        a2 int
        a3 int
        a4 int
        a5 int
        a6 int
        a7 int
        a8 int
        a9 int
        a0 int
}

func main() {
        i := A{
                a1: 0,
                a2: 0,
                a3: 0,
                a4: 0,
                a5: 0,
                a6: 0,
                a7: 0,
                a8: 0,
                a9: 0,
                a0: 0,
        }
        _ = i
}

expected: no error
actual:

$ golangci-lint run . --enable varnamelen
main.go:17:2: variable name 'i' is too short for the scope of its usage (varnamelen)
        i := A{
        ^

also confirmed with version 0.5.0

This is working as intended: It reports the usage of a short variable name over a longer span of source lines. The contents of the lines does not matter.

Ok. Your call. This linter won't be useful for us in its current form if your definition of "number of lines" is so literal.