gochecknoglobals

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2021 License: MIT Imports: 3 Imported by: 0

README

gochecknoglobals

test Go Report Card

Check that no globals are present in Go code.

Why

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

Exceptions

There are very few exceptions to the global variable rule. This tool will ignore the following patterns:

  • Variables with an Err prefix
  • Variables named _
  • Variables named version
  • Variables assigned from regexp.MustCompile()
  • Variables with a //go:embed comment

Install

go get 4d63.com/gochecknoglobals

Usage

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 will not be checked but can be included by adding the -t flag.

gochecknoglobals -t [package]

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL