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

treat multi-line definitions as a single line #8

Closed vikstrous2 closed 2 years ago

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

blizzy78 commented 2 years ago

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.

vikstrous2 commented 2 years ago

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.