Skip to content

nishanths/exhaustive

master
Switch branches/tags
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

exhaustive Godoc

Check exhaustiveness of enum switch statements in Go source code.

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

For docs on the flags, the definition of enum, and the definition of exhaustiveness, see godocs.io.

For the changelog, see CHANGELOG in the wiki.

The package provides an Analyzer that follows the guidelines in the go/analysis package; this should make it possible to integrate exhaustive with your own analysis driver program.

Bugs

exhaustive does not report missing cases if the switch statement switches on a type parameterized type. See this issue for details.

Example

Given the enum

package token

type Token int

const (
	Add Token = iota
	Subtract
	Multiply
	Quotient
	Remainder
)

and the switch statement

package calc

import "token"

func f(t token.Token) {
	switch t {
	case token.Add:
	case token.Subtract:
	case token.Multiply:
	default:
	}
}

running exhaustive will print

calc.go:6:2: missing cases in switch of type token.Token: Quotient, Remainder

Contributing

Issues and pull requests are welcome. Before making a substantial change, please discuss it in an issue.