-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add gochecksumtype
linter
#3671
Conversation
In order for a pull request adding a linter to be reviewed, the linter and the PR must follow some requirements. Pull Request Description
Linter
The Linter Tests Inside Golangci-lint
|
Hello, this linter seems really close to |
As I mentioned, this is just a fork of an existing linter that has been around for quite some time. There was only a minimal amount of work required to bring it up to date. FWIW I did look at |
I will wait for feedback from @nishanths before taking a decision. |
Ping! |
still waiting for @nishanths feedback |
I think we have waited enough time, so we will accept your linter. @alecthomas Can you take a look at the checklist? #3671 (comment) |
Since I added one sts import in the test case, the test fails: $ T=gochecksumtype.go make test_linters
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdata/gochecksumtype.go
=== RUN TestSourcesFromTestdata
linters_test.go:21: testdata/*.go
=== RUN TestSourcesFromTestdata/gochecksumtype.go
=== PAUSE TestSourcesFromTestdata/gochecksumtype.go
=== CONT TestSourcesFromTestdata/gochecksumtype.go
level=info msg="[test] ran [/home/ldez/sources/go/src/github.com/golangci/golangci-lint/golangci-lint run --internal-cmd-test --no-config --allow-parallel-runners --disable-all --out-format=json --max-same-issues=100 -Egochecksumtype gochecksumtype.go] in 213.428115ms"
analysis.go:66: gochecksumtype.go:26: no diagnostic was reported matching `exhaustiveness check failed for sum type.*SumType.*missing cases for Two`
level=info msg="[test] ran [/home/ldez/sources/go/src/github.com/golangci/golangci-lint/golangci-lint run --internal-cmd-test --no-config --allow-parallel-runners --disable-all --out-format=json --max-same-issues=100 -Etypecheck -Egochecksumtype gochecksumtype.go] in 240.006321ms"
analysis.go:66: gochecksumtype.go:26: no diagnostic was reported matching `exhaustiveness check failed for sum type.*SumType.*missing cases for Two`
--- FAIL: TestSourcesFromTestdata (2.04s)
--- FAIL: TestSourcesFromTestdata/gochecksumtype.go (0.45s)
=== RUN TestSourcesFromTestdataSubDir
--- PASS: TestSourcesFromTestdataSubDir (0.00s)
FAIL
FAIL github.com/golangci/golangci-lint/test 2.528s
FAIL
make: *** [Makefile:48: test_linters] Error 1 |
I move the logger and the test works, maybe there is something that I don't understand. |
Hi ! Thanks for this PR ! I was looking for a similar feature! Is there anything blocking here? |
If you can explain why this change produces a different behavior. |
@ldez thanks for the fast feedback! It seems that this behavior is intended by the linter's author. This behavior comes from upstream: NB: The comment is not exact because it seems that the linter only check if the default case is only containing a panic. |
`gochecksumtype` is a linter that checks that type switches on "sum types" in Go are exhaustive. https://github.com/alecthomas/go-check-sumtype This is based on BurntSushi/go-sumtype, but fixes, modernises and simplifies it.
} | ||
|
||
var unknownError error | ||
errors := gochecksumtype.Run([]*packages.Package{pkg}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation doesn't allow declaring a sum type in package A and checking a type switch in package B. That's because each package is checked separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe to open separate issue?
I feel like this comment will get lost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gochecksumtype
is a linter that checks that type switches on "sum types" in Go are exhaustive.https://github.com/alecthomas/go-check-sumtype
This is based on BurntSushi/go-sumtype, but fixes, modernises and simplifies it.
fixes #402