Check all levels of embedded interfaces against the exclude list.#137
Merged
kisielk merged 7 commits intoMay 22, 2018
Merged
Conversation
077a089 to
5584f04
Compare
kisielk
requested changes
Apr 9, 2018
Owner
kisielk
left a comment
There was a problem hiding this comment.
Looks good. A few additional comments would be helpful, especially 6 months down the road when everyone forgets what all this code does :)
| } | ||
|
|
||
| func (v *visitor) fullName(call *ast.CallExpr) (string, bool) { | ||
| func (v *visitor) selectorAndFunc(call *ast.CallExpr) (*ast.SelectorExpr, *types.Func, bool) { |
Owner
There was a problem hiding this comment.
While you're here, can you add a comment to this function, particularly the return values?
|
|
||
| } | ||
|
|
||
| func (v *visitor) fullName(call *ast.CallExpr) (string, bool) { |
| return fn.FullName(), true | ||
| } | ||
|
|
||
| func (v *visitor) namesForExcludeCheck(call *ast.CallExpr) []string { |
| return s.Field(fieldIndex).Type() | ||
| } | ||
|
|
||
| func getEmbeddedInterfaceDefiningMethod(interfaceT *types.Interface, fn *types.Func) (*types.Named, bool) { |
Owner
There was a problem hiding this comment.
Can you please document the return values of this one?
The rest of the function returns in this file are pretty self explanatory but this one may be confusing down the road.
Owner
|
Ping @louissobel I'm basically ready to merge this after the docs are added :) |
5584f04 to
cd18fe7
Compare
Contributor
Author
|
thanks for the nudge! docs added |
Owner
|
Great, thanks a lot ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This addresses #132 .
When generating names of a call to check against the exclusion list, errcheck currently just uses the name of the function itself. For example, for the Write call in
the checked name will be
(io.Writer).Write. This limits the usefulness of the exclusion list, because we'd really like to be able to exclude(hash.Hash).Write, which is documented to never return an error.So this PR adds code (
embedded_walker.go) to search through atypes.Selectionof atypes.Func, recording all the interfaces that are passed through while descending down to the actual declaration of that Func. In the example above, we'd observe that we pass through two interfaces getting toWrite:hash.Hashandio.Writer. It also deals the receiver being a struct with an embedded interface.Then we use this code in
errcheckto generate multiple names to check against the exclusion list:["(hash.Hash).Write", "(io.Writer).Write"]in this example.And finally, the PR adds
(hash.Hash).Writeto the default exclusion list as a use case for all this code.