From a7b3ee43e4f70835b4cdbdc987ebdaf4899ab493 Mon Sep 17 00:00:00 2001 From: Sasha Melentyev Date: Wed, 12 Jun 2024 07:42:35 +0300 Subject: [PATCH] fix: fix false-positive (#97) Signed-off-by: Sasha Melentyev --- pkg/analyzer/analyzer.go | 4 +-- pkg/analyzer/testdata/src/a/http/issue96.go | 28 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 pkg/analyzer/testdata/src/a/http/issue96.go diff --git a/pkg/analyzer/analyzer.go b/pkg/analyzer/analyzer.go index 581bed2..09f7c82 100644 --- a/pkg/analyzer/analyzer.go +++ b/pkg/analyzer/analyzer.go @@ -117,8 +117,9 @@ func run(pass *analysis.Pass) (interface{}, error) { case *ast.BinaryExpr: switch n.Op { - case token.LSS, token.GTR, token.LEQ, token.GEQ: + case token.LSS, token.GTR, token.LEQ, token.GEQ, token.QUO, token.ADD, token.SUB, token.MUL: return + default: } x, ok := n.X.(*ast.SelectorExpr) @@ -138,7 +139,6 @@ func run(pass *analysis.Pass) (interface{}, error) { if ok { switchStmt(pass, x, n.Body.List) } - } }) diff --git a/pkg/analyzer/testdata/src/a/http/issue96.go b/pkg/analyzer/testdata/src/a/http/issue96.go new file mode 100644 index 0000000..4c0473b --- /dev/null +++ b/pkg/analyzer/testdata/src/a/http/issue96.go @@ -0,0 +1,28 @@ +package http_test + +import ( + "net/http" +) + +func _() error { + resp, err := http.DefaultClient.Do(&http.Request{}) + if err != nil { + return err + } + defer func() { _ = resp.Body.Close() }() + + if resp.StatusCode/100 != 2 { + return nil + } + if resp.StatusCode+100 != 2 { + return nil + } + if resp.StatusCode-100 != 2 { + return nil + } + if resp.StatusCode*100 != 2 { + return nil + } + + return nil +}