aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/tomarrell
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tomarrell')
-rw-r--r--vendor/github.com/tomarrell/wrapcheck/v2/wrapcheck/wrapcheck.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/github.com/tomarrell/wrapcheck/v2/wrapcheck/wrapcheck.go b/vendor/github.com/tomarrell/wrapcheck/v2/wrapcheck/wrapcheck.go
index 6da17bd86..79e7bba86 100644
--- a/vendor/github.com/tomarrell/wrapcheck/v2/wrapcheck/wrapcheck.go
+++ b/vendor/github.com/tomarrell/wrapcheck/v2/wrapcheck/wrapcheck.go
@@ -121,7 +121,20 @@ func run(cfg WrapcheckConfig) func(*analysis.Pass) (interface{}, error) {
}
for _, file := range pass.Files {
+ // Keep track of parents so that can can traverse upwards to check for
+ // FuncDecls and FuncLits.
+ var parents []ast.Node
+
ast.Inspect(file, func(n ast.Node) bool {
+ if n == nil {
+ // Pop, since we're done with this node and its children.
+ parents = parents[:len(parents)-1]
+ } else {
+ // Push this node on the stack, since its children will be visited
+ // next.
+ parents = append(parents, n)
+ }
+
ret, ok := n.(*ast.ReturnStmt)
if !ok {
return true
@@ -137,6 +150,17 @@ func run(cfg WrapcheckConfig) func(*analysis.Pass) (interface{}, error) {
// to handle it by checking the return params of the function.
retFn, ok := expr.(*ast.CallExpr)
if ok {
+ // If you go up, and the parent is a FuncLit, then don't report an
+ // error as you are in an anonymous function. If you are inside a
+ // FuncDecl, then continue as normal.
+ for i := len(parents) - 1; i > 0; i-- {
+ if _, ok := parents[i].(*ast.FuncLit); ok {
+ return true
+ } else if _, ok := parents[i].(*ast.FuncDecl); ok {
+ break
+ }
+ }
+
// If the return type of the function is a single error. This will not
// match an error within multiple return values, for that, the below
// tuple check is required.