exhaustive

package module
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: BSD-2-Clause, BSD-3-Clause Imports: 1 Imported by: 21

README

The exhaustive static analysis checks that expression switch statements, in which the type of the switch expression is an enumerated type, are exhaustive.

The analysis is implemented in multiple passes; see the packages in the 'passes/*' directories. Package enumerated find declarations of enumerated types and enumerated constants. Package exhaustive scans a syntax tree for eligible expression switch statements and checks that the switch statements are exhaustive.

Documentation:

https://pkg.go.dev/github.com/nishanths/exhaustive/passes/enumerated

https://pkg.go.dev/github.com/nishanths/exhaustive/passes/exhaustive

Usage

The exhaustive command can be installed with 'go install'.

go install github.com/nishanths/exhaustive/cmd/exhaustive@latest

The synopsis of the command is:

exhaustive [-B] [-d] [-defrequire] [-e] [-g] [-i] [-p] [-check string]
           [-constignore regexp] [-typeignore regexp] [-typeonly regexp] [packages]

The flags are documented in the package comments. See links to documentation above.

The packages in this module can be imported and used from external analysis driver programs. See https://golang.org/x/tools/go/analysis for details. The analysis driver program may want to make available to users the flag sets defined by both the enumerated analyzer and the exhaustive analyzer.

Examples

Given the following Go source code:

package example

type vcs int

const (
	bzr vcs = iota
	fossil
	git
	hg
	svn
	darcs
)

func f(v vcs) {
	switch v {
	case bzr:
	case fossil:
	case git:
	case svn:
	}
}

the exhaustive command produces the following diagnostic:

example.go:15:2: switch not exhaustive: missing cases: hg, darcs

Though it is not so in the example, in general the enumerated type declarations and the switch statements can be in different packages.

Documentation

Overview

Deprecated: This package moved to 'github.com/nishanths/exhaustive/passes/exhaustive'. New code should use the package at that import path.

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
exhaustive command
internal
passes
enumerated
Package enumerated finds declarations of enumerated types and enumerated constants.
Package enumerated finds declarations of enumerated types and enumerated constants.
exhaustive
Package exhaustive checks that expression switch statements, in which the type of the switch expression is an enumerated type, are exhaustive.
Package exhaustive checks that expression switch statements, in which the type of the switch expression is an enumerated type, are exhaustive.

Jump to

Keyboard shortcuts

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