govet-noglobals

command module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

README

gochecknoglobals

builds.sr.ht status Coverage badge Version badge

Check that no global variables are present in Go code.

Global variables are often a source of bugs, because it is impossible to know all of the functions that can access them. In effect, they have unlimited coupling. Usinig global variables has long been considered bad design. This linter will raise an issue when global variables are found in Go code.

Install

Assuming that the Go toolchain has already been installed, then installation can be done as follows:

go install git.sr.ht/~rj/govet-noglobals@latest

Usage

The linter is supports the standard features provided by Go's analysis package. The linter can be run with standard options by specifying the package or packages.

gochecknoglobals [flags] <package>

There are two options specific to this linter. First, the flag -t can be used to specify whether or not test files are included in the analysis. Second, the flag -err can be used to exclude global variables that have the prefix Err, since this is such a common idiom in Go code.

Examples
gochecknoglobals .             # Check current directory
gochecknoglobals ./...         # Check current directory and all sub directories
gochecknoglobals -t=false .    # Exclude tests (files ending with _test.go)
gochecknoglobals -err=false .  # Raise an issue for global variables with Err prefix.

Scope

Currently, govet-noglobals is considered complete. Additional, or separate, checks are probably better handled in a separate repository. Espcially with the increasing use of linter aggregators in the community.

Exceptions for certain classes of global variables will be considered, but will be gated behind command-line options.

License

BSD (c) Robert Johnstone

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