Skip to content

Commit

Permalink
add pkgprefix flag for cmd filter pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kkHAIKE committed Sep 10, 2022
1 parent a9c2e8b commit 6ca9469
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contextcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Configuration struct {
DisableFact bool
}

var pkgprefix string

func NewAnalyzer(cfg Configuration) *analysis.Analyzer {
analyzer := &analysis.Analyzer{
Name: "contextcheck",
Expand All @@ -28,6 +30,7 @@ func NewAnalyzer(cfg Configuration) *analysis.Analyzer {
buildssa.Analyzer,
},
}
analyzer.Flags.StringVar(&pkgprefix, "pkgprefix", "", "filter init pkgs (only for cmd)")

if !cfg.DisableFact {
analyzer.FactTypes = append(analyzer.FactTypes, (*ctxFact)(nil))
Expand Down Expand Up @@ -102,6 +105,9 @@ func NewRun(pkgs []*packages.Package, disableFact bool) func(pass *analysis.Pass
if len(m) > 0 && !m[strings.Split(pass.Pkg.Path(), "/")[0]] {
return nil, nil
}
if len(m) == 0 && pkgprefix != "" && !strings.HasPrefix(pass.Pkg.Path(), pkgprefix) {
return nil, nil
}

r := &runner{disableFact: disableFact}
r.run(pass)
Expand Down

0 comments on commit 6ca9469

Please sign in to comment.