Lint your #golang code like a mad man!
I use the following linters to lint my codes while excluding the vendor directory. I’m using GNU/Linux but with a little tweak you should be able to use the following scripts in your OS of choice. I use glide for vendoring, but you can easily replace the “glide nv” part with your vendoring tool. It lists all folders except the vendor folder, which is handy. In some cases “glide nv” didn’t do the job, so I had to do it in the old fashion way.
Note: I use the $ sign to indicate it’s a shell prompt.
Gofmt should be already installed with your go binary. To fmt your code run:
$ find . -name "*.go" -not -path "./vendor/*" -not -path ".git/*" | xargs gofmt -s -d
Gocyclo calculate cyclomatic complexities of functions in Go source code.
$ go get -u github.com/fzipp/gocyclo
$ gocyclo -over 12 $(ls -d */ | grep -v vendor)
It lists all the codes with complexity of over 12. You also can list the top 10 (or any other numbers) by doing:
$ gocyclo -top 10 $(ls -d */ | grep -v vendor)
Interfacer is an interesting one. From author:
A linter that suggests interface types. In other words, it warns about the usage of types that are more specific than necessary.
$ go get -u github.com/mvdan/interfacer/cmd/interfacer
$ interfacer $(glide nv)
Deadcode will tell you any unused code snippets. To install:
$ go get -u github.com/tsenart/deadcode
$ find . -type d -not -path "./vendor/*" | xargs deadcode
The gotype command does syntactic and semantic analysis of Go files and packages like the front-end of a Go compiler.
$ go get -u golang.org/x/tools/cmd/gotype
$ find . -name "*.go" -not -path "./vendor/*" -not -path ".git/*" -print0 | xargs -0 gotype -a
$ go get -u github.com/client9/misspell
$ find . -type f -not -path "./vendor/*" -print0 | xargs -0 misspell
Staticcheck is go vet on steroids, applying a ton of static analysis checks you might be used to from tools like ReSharper for C#.
$ go get -u honnef.co/go/staticcheck/cmd/staticcheck
$ staticcheck $(glide nv)
Gosimple is a linter for Go source code that specialises on simplifying code.
$ go get -u honnef.co/go/simple/cmd/gosimple
$ gosimple $(glide nv)
goconst From author:
Find in Go repeated strings that could be replaced by a constant
$ go get -u github.com/jgautheron/goconst/cmd/goconst
$ goconst ./… | grep -v vendor