Goでenumの記述漏れを検出する
This content is a draft and will not be included in production builds.
golangci-lint に exhaustive があるので、これを有効にするといい。exhaustructは型リテラルごとにデフォルトの挙動と個別の挙動を変えられるでもメモを書いていた。Goで構造体フィールド初期化漏れを検出するもあった。Goでinterfaceのtype switchに記述漏れがあったら検出するもある。いくつ書いているんだ。
linters: enable: - exhaustive - exhaustruct settings: exhaustive: check: - switch - map explicit-exhaustive-switch: true explicit-exhaustive-map: trueデフォルトは exhaustive:enforce コメントを付けても map を対象としないので、enable は必ず書いておく必要がある。
オプションの他に、exhaustive:enforce と exhaustive:ignore コメントが用意されている。これも exhaustruct と同様にデフォルト無効にしておいて、必要な場面で exhaustive:enforce するのがいいと思う。
//exhaustive:enforcevar attributeOperators = map[attributeOperator]struct{}{ attributeEqualOperator: struct{}{},}
//exhaustive:enforceswitch op {case attributeEqualOperator: return "="}おそらく実態はnishanths/exhaustiveだと思う。