You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
switch x.(type) { // want `non-exhaustive type switch on SumFoo: missing cases for: nonexhaustive.B, nonexhaustive.C`
14
+
case A:
15
+
default:
16
+
}
17
+
}
18
+
19
+
// Non‑exhaustive: missing one_of.Msg_B
20
+
funcprocess(msg *Msg) {
21
+
switch msg.GetPayload().(type) { // want `non-exhaustive type switch on isMsg_Payload: missing cases for: one_of.Msg_B`
22
+
case *Msg_A:
23
+
default:
24
+
}
25
+
}
26
+
```
27
+
6
28
Install:
7
29
8
30
```sh
@@ -75,6 +97,27 @@ type A struct{}
75
97
func(A) sumFoo() {}
76
98
```
77
99
100
+
## gRPC files
101
+
102
+
It turned out code generated by `protoc` for Go uses almost same convention.
103
+
104
+
```proto
105
+
message Msg {
106
+
oneof payload {
107
+
A a = 1;
108
+
B b = 2;
109
+
}
110
+
}
111
+
```
112
+
113
+
```go
114
+
type isMsg_Payload interface {
115
+
isMsg_Payload()
116
+
}
117
+
```
118
+
119
+
The `oneoflint` is the linter configured to check and report exactly this.
120
+
78
121
## 2. Exhaustive Type Switch Checking
79
122
80
123
`sumlint` inspects type switches of all detected Sum* interfaces and reports two distinct problems.
@@ -120,8 +163,8 @@ $ cd tests; go vet -vettool=${HOME}/go/bin/sumlint .
120
163
121
164
## Conclusion
122
165
123
-
`sumlint` lets you use exhaustively checked sum typesin plain Go using a
124
-
lightweight naming convention and `go vet`.
166
+
`sumlint`and `oneoflint`lets you use exhaustively checked type switchesin plain Go using a
167
+
lightweight naming convention and `go vet` or other tool compatible with [golang.org/x/tools/go/analysis](https://pkg.go.dev/golang.org/x/tools/go/analysis).
0 commit comments