From 4a3e3990d3bf954da1a319cb7affa6f5280de769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D1=82=D0=B8=D0=BD?= Date: Sat, 3 Jul 2021 16:07:59 +0300 Subject: [PATCH] Do not filter out files without net/http --- passes/bodyclose/bodyclose.go | 5 ----- passes/bodyclose/testdata/src/a/helper.go | 7 +++++++ passes/bodyclose/testdata/src/a/no_import.go | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 passes/bodyclose/testdata/src/a/helper.go create mode 100644 passes/bodyclose/testdata/src/a/no_import.go diff --git a/passes/bodyclose/bodyclose.go b/passes/bodyclose/bodyclose.go index 145d540..a7ff30b 100644 --- a/passes/bodyclose/bodyclose.go +++ b/passes/bodyclose/bodyclose.go @@ -80,11 +80,6 @@ func (r runner) run(pass *analysis.Pass) (interface{}, error) { r.skipFile = map[*ast.File]bool{} for _, f := range funcs { - if r.noImportedNetHTTP(f) { - // skip this - continue - } - // skip if the function is just referenced var isreffunc bool for i := 0; i < f.Signature.Results().Len(); i++ { diff --git a/passes/bodyclose/testdata/src/a/helper.go b/passes/bodyclose/testdata/src/a/helper.go new file mode 100644 index 0000000..18b3185 --- /dev/null +++ b/passes/bodyclose/testdata/src/a/helper.go @@ -0,0 +1,7 @@ +package a + +import "net/http" + +func doRequestWithoutClose() (*http.Response, error) { + return http.Get("https://example.com") +} diff --git a/passes/bodyclose/testdata/src/a/no_import.go b/passes/bodyclose/testdata/src/a/no_import.go new file mode 100644 index 0000000..3bc5034 --- /dev/null +++ b/passes/bodyclose/testdata/src/a/no_import.go @@ -0,0 +1,5 @@ +package a + +func doRequestInHelperFunc() { + _, _ = doRequestWithoutClose() // want "response body must be closed" +}