-
Notifications
You must be signed in to change notification settings - Fork 19
Add checksumtype to the golangci-lint file. #111
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
base: main
Are you sure you want to change the base?
Add checksumtype to the golangci-lint file. #111
Conversation
bcc14bb to
e0d4781
Compare
philhassey
left a comment
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.
I think there's a typo to fix.
Sorry for the delay on reviewing this, there was some trouble with notifications.
4de67ff to
e8315d1
Compare
philhassey
left a comment
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.
Just a minor nit.
e8315d1 to
11d1e87
Compare
Some of the types within cedar-go match the sum type idiom (an interface with an unexported method) described in the linter below. Let's add an explicit check for exhaustiveness for this specific linter. https://github.com/alecthomas/go-check-sumtype *Issue #, if available:* IDK what issue tracker you use. *Description of changes:* Add a sum type annotation, add two branches to convertNamespace, both of which are just comments. Let me know if the behavior in those branches should be a little smarter. Signed-off-by: Greg NISBET <[email protected]>
Some nonce types have an embedded Node member and are in the same package, so they appear to the sum type checker to be real variants based on the heuristics that that package uses. There are a few ways to handle this: 1) make the unknownNode and unknownType cases real variants 2) remove the tests that use unknownNode and unknownType 3) rewrite the tests that use unknownNode and unknownType to use a different strategy to detect the same defects. Signed-off-by: Greg NISBET <[email protected]>
Remove unknownType and unknownNode and the two tests that depend on them. Signed-off-by: Greg NISBET <[email protected]>
Signed-off-by: Greg NISBET <[email protected]>
ffdcd12 to
685b2da
Compare
|
Rev'd PR. I think this will be the most controversial change (in |
| at.ContextRecord = t | ||
| case *Path: | ||
| at.ContextPath = t | ||
| case *SetType: |
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.
Can you explain why this needed to be added, etc? I see there is another case of panic in this file, which I'm not really excited about either ... Is there a way we can rephrase both to avoid those panics? I'd rather we use error handling in bad cases.
Either way, the PR can't be merged without 100% coverage, so this does need to be covered with a test to show when it happens.
gochecksumtype is a linter in golangci-lint that checks for switch statement exhaustiveness for types that look like sum types in other languages. More precisely, interface types with a //sumtype:decl annotation and an unexported nullary marker method are statically guaranteed to be closed (since new types that implement the interface can't be created). This means that we can check for exhaustiveness on type switches for values implementing the sumdecl-compatible interface, which is what the linter does. The initial attempt to add this to every type with a marker interface cedar-policy#111 has grown in complexity since a few of the tests use unknownNode and unknownType types for checking the error paths. gochecksumtype has no way of indicating test-only variants of a sum type. So, to keep the diff size small and the code coverage at 100% (except for the generated parser) at each step, I'm going to break PR cedar-policy#111 into pieces and land them separately. Signed-off-by: Greg NISBET <[email protected]>
|
I want to split this PR. Here's the first piece: #121 |
Some of the types within cedar-go match the sum type idiom (an interface with an unexported method) described in the linter below.
Let's add an explicit check for exhaustiveness for this specific linter.
https://github.com/alecthomas/go-check-sumtype
Issue #, if available:
n/a
Description of changes:
Add a sum type annotation, add two branches to convertNamespace, both of which are just comments. Let me know if the behavior in those branches should be a little smarter.