exhaustive – check exhaustiveness of Go switch statements

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/analysis Analyzer 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
reviveDesigned as a drop-in replacement for golint
golangci-lintFast Go linters runner
gosecSecurity scanner for Go projects
StaticcheckAdvanced Go linter
go-criticOpinionated Go source code linter
VetExamines Go source code and reports suspicious constructs
gofumptStricter gofmt
gofmtFormats Go programs
go-ruleguardAnalysis-based Go linter that runs dynamically loaded rules
forbidigoGo linter for forbidding identifiers
godotKeep source code comments consistent

Read our verdict in the software roundup.


Best Free and Open Source Software 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.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted