logginghandler/vendor/github.com/nishanths/exhaustive
Marvin Preuss d095180eb4
All checks were successful
continuous-integration/drone/push Build is passing
build: uses go modules for tool handling
2022-01-14 13:51:56 +01:00
..
.gitignore build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
.travis.yml build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
enum.go build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
exhaustive.go build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
generated.go build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
go.mod build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
go.sum build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
LICENSE build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
README.md build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
regexp_flag.go build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
switch.go build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00

exhaustive

Godoc

Build Status

The exhaustive package and command line program can be used to detect enum switch statements that are not exhaustive.

An enum switch statement is exhaustive if it has cases for each of the enum's members. See godoc for the definition of enum used by the program.

The exhaustive package provides an Analyzer that follows the guidelines described in the go/analysis package; this makes it possible to integrate into existing analysis driver programs.

Install

go get github.com/nishanths/exhaustive/...

Docs

https://godoc.org/github.com/nishanths/exhaustive

Example

Given the code:

package token

type Token int

const (
	Add Token = iota
	Subtract
	Multiply
+	Quotient
+	Remainder
)
package calc

import "token"

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

Running the exhaustive command will print:

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

Enums can also be defined using explicit constant values instead of iota.

License

BSD 2-Clause