Check that no globals are present in Go code.
Global variables are an input to functions that is not visible in the functions signature, complicate testing, reduces readability and increase the complexity of code.
https://peter.bourgon.org/blog/2017/06/09/theory-of-modern-go.html https://twitter.com/davecheney/status/871939730761547776
There are very few exceptions to the global variable rule. This tool will ignore the following patterns:
err
or Err
prefix that implement the error
interface_
version
regexp.MustCompile()
//go:embed
commentgo install 4d63.com/gochecknoglobals@latest
The linter is built on Go's analysis package and does thus support all the built in flags and features from this type. The analyzer is executed by specifying packages.
gochecknoglobals [package]
gochecknoglobals ./...
By default, test files are checked but can be excluded by adding the
-test=false
flag.
gochecknoglobals -test=false [package]