mirror of
https://github.com/anchore/syft.git
synced 2025-11-19 09:23:15 +01:00
make new linter pass linting
Signed-off-by: Will Murphy <will.murphy@anchore.com>
This commit is contained in:
parent
552cf45224
commit
34f9e6fec9
@ -1,15 +1,16 @@
|
|||||||
package ensuredefer
|
package ensuredefer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golangci/plugin-module-register/register"
|
|
||||||
"go/ast"
|
"go/ast"
|
||||||
|
|
||||||
|
"github.com/golangci/plugin-module-register/register"
|
||||||
"golang.org/x/tools/go/analysis"
|
"golang.org/x/tools/go/analysis"
|
||||||
"golang.org/x/tools/go/analysis/passes/inspect"
|
"golang.org/x/tools/go/analysis/passes/inspect"
|
||||||
"golang.org/x/tools/go/ast/inspector"
|
"golang.org/x/tools/go/ast/inspector"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
register.Plugin("ensuredefer", func(conf any) (register.LinterPlugin, error) {
|
register.Plugin("ensuredefer", func(_ any) (register.LinterPlugin, error) {
|
||||||
return &analyzerPlugin{}, nil
|
return &analyzerPlugin{}, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -18,13 +19,11 @@ func run(pass *analysis.Pass) (any, error) {
|
|||||||
insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||||
nodeFilter := []ast.Node{
|
nodeFilter := []ast.Node{
|
||||||
(*ast.ExprStmt)(nil),
|
(*ast.ExprStmt)(nil),
|
||||||
(*ast.DeferStmt)(nil),
|
|
||||||
}
|
}
|
||||||
insp.Preorder(nodeFilter, func(node ast.Node) {
|
insp.Preorder(nodeFilter, func(node ast.Node) {
|
||||||
// if we have a *ast.ExprStmt that calls internal.CloseAndLogError, report a problem.
|
// if we have a *ast.ExprStmt that calls internal.CloseAndLogError, report a problem.
|
||||||
// (if the function is correctly called in a defer statement, the block will have
|
// (if the function is correctly called in a defer statement, the block will have
|
||||||
switch t := node.(type) {
|
if t, ok := node.(*ast.ExprStmt); ok {
|
||||||
case *ast.ExprStmt:
|
|
||||||
if !isExprStmtAllowed(t, pass) {
|
if !isExprStmtAllowed(t, pass) {
|
||||||
pass.Reportf(t.Pos(), "internal.CloseAndLogError must be called in defer")
|
pass.Reportf(t.Pos(), "internal.CloseAndLogError must be called in defer")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
package ensuredefer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/x/tools/go/analysis/singlechecker"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
singlechecker.Main(NewAnalyzer())
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user