Skip to content

Commit

Permalink
Do not flag the unhandled errors which are explicitly ignored
Browse files Browse the repository at this point in the history
fixes #270
  • Loading branch information
ccojocar authored and Cosmin Cojocar committed Jan 14, 2019
1 parent 12400f9 commit 14ed63d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
12 changes: 0 additions & 12 deletions rules/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions testutils/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func test() (int,error) {
func main() {
v, _ := test()
fmt.Println(v)
}`}, 1}, {[]string{`
}`}, 0}, {[]string{`
package main
import (
"io/ioutil"
Expand All @@ -206,7 +206,7 @@ func main() {
a()
b()
c()
}`}, 3}, {[]string{`
}`}, 2}, {[]string{`
package main
import "fmt"
func test() error {
Expand Down

0 comments on commit 14ed63d

Please sign in to comment.