百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
E

exhaustive

> 编程语言
开源

检查 Go 源代码中枚举类型常量的 switch 语句是否完整。

344 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

检查 Go 源代码中枚举类型常量的 switch 语句是否完整。

exhaustive

exhaustive checks exhaustiveness of enum switch statements in Go source code.

For the definition of enum and the definition of exhaustiveness used by this program, see godoc. For the changelog, see CHANGELOG in the GitHub wiki. The program can be configured to additionally check exhaustiveness of keys in map literals whose key type is an enum.

Usage

Command:

go install github.com/nishanths/exhaustive/cmd/exhaustive@latest

exhaustive [flags] [packages]

For available flags, refer to the Flags section in godoc or run exhaustive -h.

Package:

go get github.com/nishanths/exhaustive

import "github.com/nishanths/exhaustive"

The exhaustive.Analyzer variable follows guidelines in the golang.org/x/tools/go/analysis package. This should make it possible to integrate exhaustive with your own analysis driver program.

Example

Given an enum:

package token // import "example.org/token"

type Token int

const (
	Add Token = iota
	Subtract
	Multiply
	Quotient
	Remainder
)

and code that switches on the enum:

package calc

import "example.org/token"

func x(t token.Token) {
	switch t {
	case token.Add:
	case token.Subtract:
	case token.Remainder:
	default:
	}
}

running exhaustive with default flags will produce:

calc.go:6:2: missing cases in switch of type token.Token: token.Multiply, token.Quotient

Specify flag -check=switch,map to additionally check exhaustiveness of keys in map literals. For example:

var m = map[token.Token]rune{
	token.Add:      '+',
	token.Subtract: '-',
	token.Multiply: '*',
	token.Quotient: '/',
}
calc.go:14:9: missing keys in map of key type token.Token: token.Remainder

Contributing

Issues and changes are welcome. Please discuss substantial changes in an issue first.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goastgotypesvet

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言