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

golangci-lint ignore-decls config not working for parameters #5

Closed OscarVanL closed 2 years ago

OscarVanL commented 2 years ago

My linter is giving me varnamelen warnings for my REST endpoint handler functions which I want to ignore.

internal/handler.go:83:35: parameter name 'w' is too short for the scope of its usage (varnamelen)
func GetSignin(w http.ResponseWriter, r *http.Request) {
                                  ^
internal/handler.go:171:33: parameter name 'w' is too short for the scope of its usage (varnamelen)
func Signout(w http.ResponseWriter, r *http.Request) {
                                ^
internal/handler.go:287:58: parameter name 'r' is too short for the scope of its usage (varnamelen)
func Sync(w http.ResponseWriter, r *http.Request) {
                                                         ^

My varnamelen config looks like this:

 varnamelen:
  # The longest distance, in source lines, that is being considered a "small scope." (defaults to 5)
  # Variables used in at most this many lines will be ignored.
  # max-distance: 5
  # The minimum length of a variable's name that is considered "long." (defaults to 3)
  # Variable names that are at least this long will be ignored.
  # min-name-length: 3
  # Check method receiver names. (defaults to false)
  # check-receiver: false
  # Check named return values. (defaults to false)
  # check-return: false
  # Ignore "ok" variables that hold the bool return value of a type assertion. (defaults to false)
  # ignore-type-assert-ok: false
  # Ignore "ok" variables that hold the bool return value of a map index. (defaults to false)
  # ignore-map-index-ok: false
  # Ignore "ok" variables that hold the bool return value of a channel receive. (defaults to false)
  # ignore-chan-recv-ok: false
  # Optional list of variable names that should be ignored completely. (defaults to empty list)
  ignore-names:
   - err
   - c
   - ctx
   - i
  # Optional list of variable declarations that should be ignored completely. (defaults to empty list)
  # Entries must be in the form of "<variable name> <type>" or "<variable name> *<type>" for
  # variables, or "const <name>" for constants.
  ignore-decls:
   - w http.ResponseWriter
   - r *http.Request
   - r http.Request
   - r *net/http/Request
   - r *mux.Router
  #  - t testing.T
  #  - f *foo.Bar
  #  - e error
  #  - i int
  #  - const C

I've had the same problem for other packages too. It seems none of my ignore-decls rules get used. My workaround so far has just been to add the letter to ignore-names, but this is far from ideal.

Here's my golangci-lint version:

golangci-lint --version
golangci-lint has version v1.43.0 built from (unknown, mod sum: "h1:SLwZFEmDgopqZpfP495zCtV9REUf551JJlJ51Ql7NZA=") on (unknown)

I've tried each ignore-decls rule individually just incase one broken rule caused them to all fail.

Any ideas why these rules aren't working?

blizzy78 commented 2 years ago

golangci-lint 1.43.0 contains varnamelen 0.3.0, which does not support the -ignoreDecls flag yet.

OscarVanL commented 2 years ago

Thanks! I hope golangci-lint updates soon :)

blizzy78 commented 2 years ago

varnamelen 0.5.0 should be in the next update, but I can't say when that will be released.