enumcase

package module
v0.0.0-...-574e2b6 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: MIT Imports: 7 Imported by: 3

README

enumcase

enumcase checks every switch statement handles all const values of the type

Install

$ go get -u github.com/MakeNowJust/enumcase/cmd/enumcase

Usage

$ go vet -vettool=$(which enumcase) pkgname

Or

$ enumcase pkgname

Example

For example you have this type and consts:

type FileMode int

const (
    Read FileMode = iota
    Write
    Append
)

Then, enumcase reports a warning for such a switch because the case to Append is missing.

switch mode {
case Read:
    // ...
case Write:
    // ...
}
$ go vet -vettool=$(which enumcase) .
/.../main.go:10:9: missing case(s) to FileMode value(s): Append

Notice

enumcase reports many false-positives because this tool checks all switch statement whose tag type has const value. It is hard to distinguish whether the type is enum-like or not.

I don't recommend to use enumcase on CI or everyday code check. However, I recommend to use enumcase when a new const value is added. It may help you.

Documentation

Index

Constants

View Source
const Doc = "enumcase ..."

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "enumcase",
	Doc:  Doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Functions

func GetRelatedConsts

func GetRelatedConsts(pass *analysis.Pass, t types.Type) []*types.Const

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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