Skip to content

Commit

Permalink
readme: link directly to package doc section
Browse files Browse the repository at this point in the history
  • Loading branch information
nishanths committed Nov 24, 2022
1 parent 2b2e029 commit ff12d63
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -63,41 +59,39 @@ 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
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

0 comments on commit ff12d63

Please sign in to comment.