uartois / sonar-golang

Sonarqube plugin for the golang language.
GNU Lesser General Public License v3.0
245 stars 32 forks source link

Improve regexes for gocyclo and vet/shadow #48

Closed maclav3 closed 6 years ago

maclav3 commented 6 years ago

This is a reincarnation of https://github.com/uartois/sonar-golang/pull/47 - after I realized that maintenance is the development branch and a better place to propose these changes. Sorry for the mess.

  1. The current regex for gocyclo does not match methods, only functions. Here I propose a regex that matches the following:

Foo() (currently supported) (Foo).Bar() (*Foo).Bar() (foo *Foo).Bar()

AFAIK, gocyclo doesn't generate the last example, but I included it just to be safe.

  1. Replaced the hardcoded 10 in gocyclo regex, in case someone configures gocyclo with a different threshold.

  2. Improved the regex for vet/shadow, to allow for file paths, for example: declaration of "err" shadows declaration at foo/bar/baz.go:123

danielleberre commented 6 years ago

Thanks @maclav3 for your contribution!