
This commit adds full support for bodyclose linter (https://github.com/timakin/bodyclose), which checks if an `http.Body` element is correctly closed after usage. Since it can be used via `go/analysis', I followed the `govet' example as suggested by https://github.com/golangci/golangci-lint/wiki/How-to-add-a-custom-linter. This commit is fully tested, and contains a (flawed) test program which calls `http.Get()' on `https://google.com' and does not closes its corresponding `http.Body'.
19 lines
300 B
Go
19 lines
300 B
Go
package analysisutil
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/token"
|
|
|
|
"golang.org/x/tools/go/analysis"
|
|
)
|
|
|
|
// File finds *ast.File in pass.Files by pos.
|
|
func File(pass *analysis.Pass, pos token.Pos) *ast.File {
|
|
for _, f := range pass.Files {
|
|
if f.Pos() <= pos && pos <= f.End() {
|
|
return f
|
|
}
|
|
}
|
|
return nil
|
|
}
|