Skip to content

Commit

Permalink
feat: support skipping test files
Browse files Browse the repository at this point in the history
  • Loading branch information
aereal committed May 18, 2022
1 parent cf340d0 commit 108e88d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ var Analyzer = &analysis.Analyzer{
Run: run,
}

var configPath string
var (
configPath string
skipTestPackages bool
)

func init() {
Analyzer.Flags.StringVar(&configPath, "config", "pkgboundaries.json", "config file path")
Analyzer.Flags.BoolVar(&skipTestPackages, "skip-test", false, "skip validating for test pacakges")
}

func SetConfigPathForTesting(path string) func() {
Expand All @@ -33,7 +37,7 @@ func SetConfigPathForTesting(path string) func() {

func run(pass *analysis.Pass) (interface{}, error) {
currentPkg := pass.Pkg.Path()
if strings.HasSuffix(currentPkg, ".test") {
if strings.HasSuffix(currentPkg, ".test") && skipTestPackages {
return nil, nil
}
var cfg *pkgboundaries.Config
Expand Down Expand Up @@ -66,6 +70,11 @@ func run(pass *analysis.Pass) (interface{}, error) {
}
}
for _, file := range pass.Files {
if tf := pass.Fset.File(file.Pos()); tf != nil {
if skipTestPackages && strings.HasSuffix(tf.Name(), "_test.go") {
continue
}
}
processFile(file)
}
return nil, nil
Expand Down

0 comments on commit 108e88d

Please sign in to comment.