Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MakeNowJust/enumcase
enumcase checks every switch statement handles all const values of the type
https://github.com/MakeNowJust/enumcase
enum go golang lint static-analysis
Last synced: 2 months ago
JSON representation
enumcase checks every switch statement handles all const values of the type
- Host: GitHub
- URL: https://github.com/MakeNowJust/enumcase
- Owner: makenowjust
- License: mit
- Created: 2019-08-20T09:11:55.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-23T02:56:09.000Z (over 5 years ago)
- Last Synced: 2024-11-12T12:05:26.303Z (3 months ago)
- Topics: enum, go, golang, lint, static-analysis
- Language: Go
- Homepage:
- Size: 4.07 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# enumcase
> `enumcase` checks every `switch` statement handles all const values of the type
## Install
```console
$ go get -u github.com/MakeNowJust/enumcase/cmd/enumcase
```## Usage
```console
$ go vet -vettool=$(which enumcase) pkgname
```Or
```console
$ enumcase pkgname
```## Example
For example you have this type and consts:
```go
type FileMode intconst (
Read FileMode = iota
Write
Append
)
```Then, `enumcase` reports a warning for such a switch because the case to `Append` is missing.
```go
switch mode {
case Read:
// ...
case Write:
// ...
}
``````console
$ 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.