exhaustive is a static analysis tool for Go source code that checks whether switch statements over enum-like constants handle every possible value.
It helps expose omissions that can otherwise remain hidden when a new constant is added or when a switch only covers part of a type’s defined values. Because Go has no dedicated enum declaration, the tool works with named types whose possible values are represented by constants. The analyzer follows Go’s analysis framework, so it can be used directly from the command line or integrated into another analysis driver.
This is free and open source software.
Key Features
- Checks switch statements over enum-like constant types for missing cases.
- Can also inspect map literals whose key type is an enum and report missing keys.
- Reports the names of unhandled constants together with the source position of the incomplete construct.
- Supports directives for enum definitions that should not participate in exhaustiveness checking.
- Provides controls that let projects tailor how switch statements are analysed.
- Can operate across individual packages or wider package patterns.
- Uses Go type information rather than relying on simple textual matching.
- Implements the
golang.org/x/tools/go/analysisAnalyzer interface. - Can therefore be incorporated into custom static-analysis driver programs.
- Is available both as a standalone command and as a reusable Go package.
- Identifies omitted values explicitly, making diagnostics immediately actionable.
- Works with enum-like types defined in other packages as well as the package being checked.
Website: github.com/nishanths/exhaustive
Support:
Developer: nishanths
License: BSD 2-Clause “Simplified” License
exhaustive is written in Go. Learn Go with our recommended free books and free tutorials.
Related Software
| Go Linters | |
|---|---|
| revive | Designed as a drop-in replacement for golint |
| golangci-lint | Fast Go linters runner |
| gosec | Security scanner for Go projects |
| Staticcheck | Advanced Go linter |
| go-critic | Opinionated Go source code linter |
| Vet | Examines Go source code and reports suspicious constructs |
| gofumpt | Stricter gofmt |
| gofmt | Formats Go programs |
| go-ruleguard | Analysis-based Go linter that runs dynamically loaded rules |
| forbidigo | Go linter for forbidding identifiers |
| godot | Keep source code comments consistent |
Read our verdict in the software roundup.
Explore our carefully curated directory of recommended free and open source software, covering every major software category.The directory forms part of our extensive collection of articles for Linux enthusiasts. It includes hundreds of detailed reviews, together with free and open source alternatives to proprietary software from companies such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk. LinuxLinks also covers interesting projects worth exploring, Linux-compatible hardware, free programming books and tutorials, and much more. Know a useful free and open source Linux application that we haven’t covered? Tell us about it using our submission form. |


Please read our Comment Policy before commenting.