Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import (

// NewAnalyzer returns a non-configurable analyzer that defaults to the defer-only mode.
// Deprecated, this will be removed in v1.0.0.
func NewAnalyzer() *analysis.Analyzer {
func NewAnalyzer(extraPackages []string) *analysis.Analyzer {
flags := flag.NewFlagSet("analyzer", flag.ExitOnError)
return newAnalyzer(run, flags)
return newAnalyzer(func(pass *analysis.Pass) (interface{}, error) {
return run(pass, extraPackages)
}, flags)
}

func run(pass *analysis.Pass) (interface{}, error) {
opinionatedAnalyzer := &deferOnlyAnalyzer{}
func run(pass *analysis.Pass, extraPackages []string) (interface{}, error) {
opinionatedAnalyzer := &deferOnlyAnalyzer{
extraPackages: extraPackages,
}
return opinionatedAnalyzer.Run(pass)
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/analyzer/defer_only.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ var (
}
)

type deferOnlyAnalyzer struct{}
type deferOnlyAnalyzer struct {
extraPackages []string
}

func NewDeferOnlyAnalyzer() *analysis.Analyzer {
analyzer := &deferOnlyAnalyzer{}
Expand All @@ -53,8 +55,12 @@ func (a *deferOnlyAnalyzer) Run(pass *analysis.Pass) (interface{}, error) {
return nil, nil
}

pkgs := make([]string, len(sqlPackages)+len(a.extraPackages))
copy(pkgs, sqlPackages)
copy(pkgs[len(sqlPackages):], a.extraPackages)

// Build list of types we are looking for
targetTypes := getTargetTypes(pssa, sqlPackages)
targetTypes := getTargetTypes(pssa, pkgs)

// If non of the types are found, skip
if len(targetTypes) == 0 {
Expand Down