diff --git a/README.md b/README.md index 589616c..c7f2799 100644 --- a/README.md +++ b/README.md @@ -2,35 +2,31 @@ Checks exhaustiveness of enum switch statements in Go source code. +``` +go install github.com/nishanths/exhaustive/cmd/exhaustive@latest +``` + The repository consists of an importable Go package and a command line program. The package provides an `analysis.Analyzer` value that follows the guidelines in the [`golang.org/x/tools/go/analysis`][xanalysis] -package. This should make it possible to integrate exhaustive with your +package. This should make it possible to integrate `exhaustive` with your own analysis driver programs. -To install the command line program, run: - -``` -go install github.com/nishanths/exhaustive/cmd/exhaustive@latest -``` - -For documentation on the command's flags, definition of enums, and -definition of exhaustiveness, see [pkg.go.dev][godoc]. For a changelog, -see [CHANGELOG][changelog] in the wiki. +For documentation on flags, the definition of enum, and the definition +of exhaustiveness, see [pkg.go.dev][godoc-doc]. For a changelog, see +[CHANGELOG][changelog] in the wiki. The program may additionally be configured to check for exhaustiveness of map literals with enum key types. See examples below. ## Bugs -`exhaustive` does not report missing cases for a switch statement that -switch on a type-parameterized type. For details see [this -issue][issue-typeparam]. +`exhaustive` does not report missing cases in a switch statement that +switches on a type-parameterized type. See [this issue][issue-typeparam] +for details. ## Examples -### Switch statement - Given the enum ```go @@ -54,7 +50,7 @@ package calc import "token" -func doSomething(t token.Token) { +func f(t token.Token) { switch t { case token.Add: case token.Subtract: @@ -63,14 +59,14 @@ func doSomething(t token.Token) { } } -var tokenNames = map[token.Token]string{ +var m = map[token.Token]string{ token.Add: "add", token.Subtract: "subtract", token.Multiply: "multiply", } ``` -running exhaustive with default options will print: +running `exhaustive` with default options will print ``` % exhaustive path/to/pkg/calc @@ -78,26 +74,24 @@ calc.go:6:2: missing cases in switch of type token.Token: Quotient, Remainder % ``` -### Map literal - -To additionally check exhaustiveness of map literals, use the `-check` -flag. +To additionally check exhaustiveness of map literals, use +`-check=switch,map`. ``` % exhaustive -check=switch,map path/to/pkg/calc calc.go:6:2: missing cases in switch of type token.Token: Quotient, Remainder -calc.go:14:18: missing keys in map of key type token.Token: Quotient, Remainder +calc.go:14:9: missing keys in map of key type token.Token: Quotient, Remainder % ``` ## Contributing Issues and pull requests are welcome. Before making a substantial -change, please discuss it in an issue. +change please discuss it in an issue. [repo]: https://pkg.go.dev/github.com/nishanths/exhaustive [godoc-svg]: https://pkg.go.dev/badge/github.com/nishanths/exhaustive.svg -[godoc]: https://pkg.go.dev/github.com/nishanths/exhaustive +[godoc-doc]: https://pkg.go.dev/github.com/nishanths/exhaustive#section-documentation [xanalysis]: https://pkg.go.dev/golang.org/x/tools/go/analysis [changelog]: https://github.com/nishanths/exhaustive/wiki/CHANGELOG [issue-typeparam]: https://github.com/nishanths/exhaustive/issues/31