Skip to content

Commit

Permalink
Merge pull request #101 from k1LoW/exclude-dirs
Browse files Browse the repository at this point in the history
Add `exclude-files:` section for excluding files from analysis
  • Loading branch information
k1LoW committed Apr 22, 2024
2 parents 8638ff5 + 46bd94f commit ba84fef
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gostyle.yml.init
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ analyzers:
# medium-varname-max: 8 # max length of variable name for medium scope (default: -1)
# large-varname-max: 16 # max length of variable name for large scope (default: -1)
# very-large-varname-max: 32 # max length of variable name for very large scope (default: -1)
# exclude-files: # exclude files from analysis
# - path/to/**/*.go
3 changes: 2 additions & 1 deletion analyzer/code_review_comments/contexts/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Contexts.IncludeGenerated
excludeTest = c.AnalyzersSettings.Contexts.ExcludeTest
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -73,7 +75,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.StructType)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
4 changes: 3 additions & 1 deletion analyzer/code_review_comments/dontpanic/dontpanic.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}

var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Dontpanic.IncludeGenerated
excludeTest = c.AnalyzersSettings.Dontpanic.ExcludeTest
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -70,7 +73,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.CallExpr)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/code_review_comments/errorstrings/errorstrings.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Errorstrings.IncludeGenerated
excludeTest = c.AnalyzersSettings.Errorstrings.ExcludeTest
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -71,7 +73,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.CallExpr)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/code_review_comments/handlerrors/handlerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Handlerrors.IncludeGenerated
excludeTest = c.AnalyzersSettings.Handlerrors.ExcludeTest
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -75,7 +77,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.AssignStmt)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
4 changes: 3 additions & 1 deletion analyzer/decisions/funcfmt/funcfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ var AnalyzerWithConfig = &analysis.Analyzer{
func run(pass *analysis.Pass) (any, error) {
c, err := config.Load(pass)
if err != nil {

return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Funcfmt.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}

if disable {
Expand All @@ -70,7 +73,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.CallExpr)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/getters/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ func run(pass *analysis.Pass) (any, error) {
return nil, err
}
words := strings.Split(exclude, ",")
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
words = c.AnalyzersSettings.Getters.Exclude
includeGenerated = c.AnalyzersSettings.Getters.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -77,7 +79,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.AssignStmt)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/nilslices/nilslices.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Nilslices.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -72,7 +74,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.BinaryExpr)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/pkgnames/pkgnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Pkgnames.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -77,7 +79,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.ImportSpec)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/recvnames/recvnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Recvnames.IncludeGenerated
max = c.AnalyzersSettings.Recvnames.Max
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}

if disable {
Expand All @@ -73,7 +75,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.FuncDecl)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/recvtype/recvtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Recvtype.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}

if disable {
Expand All @@ -70,7 +72,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.FuncDecl)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/repetition/repetition.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ func run(pass *analysis.Pass) (any, error) {
return nil, err
}
words := strings.Split(exclude, ",")
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Recvnames.IncludeGenerated
words = c.AnalyzersSettings.Repetition.Exclude
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}

if disable {
Expand All @@ -80,7 +82,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.FuncDecl)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/typealiases/typealiases.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ func run(pass *analysis.Pass) (any, error) {
return nil, err
}
words := strings.Split(exclude, ",")
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
words = c.AnalyzersSettings.Typealiases.Exclude
includeGenerated = c.AnalyzersSettings.Typealiases.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -72,7 +74,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.TypeSpec)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/underscores/underscores.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ func run(pass *analysis.Pass) (any, error) {
return nil, err
}
words := strings.Split(exclude, ",")
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
words = c.AnalyzersSettings.Underscores.Exclude
includeGenerated = c.AnalyzersSettings.Underscores.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -81,7 +83,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.RangeStmt)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/useany/useany.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Useany.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -70,7 +72,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.CompositeLit)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/useq/useq.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Useq.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -73,7 +75,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.CallExpr)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/decisions/varnames/varnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func run(pass *analysis.Pass) (any, error) {
return nil, err
}
words := strings.Split(exclude, ",")
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
words = c.AnalyzersSettings.Varnames.Exclude
Expand All @@ -81,6 +82,7 @@ func run(pass *analysis.Pass) (any, error) {
largeScopeMax = c.AnalyzersSettings.Varnames.LargeScopeMax
largeVarnameMax = c.AnalyzersSettings.Varnames.LargeVarnameMax
veryLargeVarnameMax = c.AnalyzersSettings.Varnames.VeryLargeVarnameMax
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -101,7 +103,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.RangeStmt)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/effective/ifacenames/ifacenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ func run(pass *analysis.Pass) (any, error) {
if err != nil {
return nil, err
}
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
includeGenerated = c.AnalyzersSettings.Ifacenames.IncludeGenerated
all = c.AnalyzersSettings.Ifacenames.All
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -75,7 +77,6 @@ func run(pass *analysis.Pass) (any, error) {
}

var ii *ast.Ident
var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
3 changes: 2 additions & 1 deletion analyzer/guide/mixedcaps/mixedcaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ func run(pass *analysis.Pass) (any, error) {
return nil, err
}
words := strings.Split(exclude, ",")
var opts []reporter.Option
if c != nil {
disable = c.IsDisabled(name)
words = c.AnalyzersSettings.Mixedcaps.Exclude
includeGenerated = c.AnalyzersSettings.Mixedcaps.IncludeGenerated
opts = append(opts, reporter.ExcludeFiles(c.ConfigDir, c.ExcludeFiles))
}
if disable {
return nil, nil
Expand All @@ -81,7 +83,6 @@ func run(pass *analysis.Pass) (any, error) {
(*ast.RangeStmt)(nil),
}

var opts []reporter.Option
if includeGenerated {
opts = append(opts, reporter.IncludeGenerated())
}
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
type Config struct {
Analyzers Analyzers `yaml:"analyzers"`
AnalyzersSettings AnalyzersSettings `yaml:"analyzers-settings"`
ExcludeFiles []string `yaml:"exclude-files"`
ConfigDir string `yaml:"-"`
loaded bool
err error
}
Expand Down
Loading

0 comments on commit ba84fef

Please sign in to comment.