Skip to content

Commit abda6c9

Browse files
committed
doc: mention oneoflint in a README
1 parent f75d0fa commit abda6c9

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33
`sumlint` adds exhaustiveness checks for your interface "sum types" using a lightweight
44
naming convention + `go vet`.
55

6+
`oneoflint` provides the same check for [gRPC oneof](https://protobuf.dev/programming-guides/proto3/#oneof).
7+
8+
## Example
9+
10+
```go
11+
// Non‑exhaustive: missing nonexhaustive.B, nonexhaustive.C.
12+
func bad(x SumFoo) {
13+
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+
func process(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+
628
Install:
729

830
```sh
@@ -75,6 +97,27 @@ type A struct{}
7597
func (A) sumFoo() {}
7698
```
7799

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+
78121
## 2. Exhaustive Type Switch Checking
79122

80123
`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 .
120163
121164
## Conclusion
122165
123-
`sumlint` lets you use exhaustively checked sum types in plain Go using a
124-
lightweight naming convention and `go vet`.
166+
`sumlint` and `oneoflint` lets you use exhaustively checked type switches in 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).
125168
126169
Happy vetting!
127170

0 commit comments

Comments
 (0)