From 14ed63d55833ce11eb756de9fe91cd76a78e5ef0 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Mon, 14 Jan 2019 09:50:19 +0100 Subject: [PATCH] Do not flag the unhandled errors which are explicitly ignored fixes #270 --- rules/errors.go | 12 ------------ testutils/source.go | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/rules/errors.go b/rules/errors.go index 44da04a..fa640d0 100644 --- a/rules/errors.go +++ b/rules/errors.go @@ -51,18 +51,6 @@ func returnsError(callExpr *ast.CallExpr, ctx *gosec.Context) int { func (r *noErrorCheck) Match(n ast.Node, ctx *gosec.Context) (*gosec.Issue, error) { switch stmt := n.(type) { - case *ast.AssignStmt: - for _, expr := range stmt.Rhs { - if callExpr, ok := expr.(*ast.CallExpr); ok && r.whitelist.ContainsCallExpr(expr, ctx, false) == nil { - pos := returnsError(callExpr, ctx) - if pos < 0 || pos >= len(stmt.Lhs) { - return nil, nil - } - if id, ok := stmt.Lhs[pos].(*ast.Ident); ok && id.Name == "_" { - return gosec.NewIssue(ctx, n, r.ID(), r.What, r.Severity, r.Confidence), nil - } - } - } case *ast.ExprStmt: if callExpr, ok := stmt.X.(*ast.CallExpr); ok && r.whitelist.ContainsCallExpr(stmt.X, ctx, false) == nil { pos := returnsError(callExpr, ctx) diff --git a/testutils/source.go b/testutils/source.go index a0c3c0f..2653230 100644 --- a/testutils/source.go +++ b/testutils/source.go @@ -184,7 +184,7 @@ func test() (int,error) { func main() { v, _ := test() fmt.Println(v) -}`}, 1}, {[]string{` +}`}, 0}, {[]string{` package main import ( "io/ioutil" @@ -206,7 +206,7 @@ func main() { a() b() c() -}`}, 3}, {[]string{` +}`}, 2}, {[]string{` package main import "fmt" func test() error {