diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 144550b4b25d..5870d1aef573 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -4022,6 +4022,9 @@ formatters: chain-split-dots: false exclusions: + # Log a warning if an exclusion path is unused. + # Default: false + warn-unused: true # Mode of the generated files analysis. # # - `strict`: sources are excluded by strictly following the Go generated file convention. diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index dedbf8676bb2..d561849627fd 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -4634,6 +4634,10 @@ "items": { "type": "string" } + }, + "warn-unused": { + "type": "boolean", + "default": false } } } diff --git a/pkg/config/formatters.go b/pkg/config/formatters.go index 145ea861ab42..e1723ac101fd 100644 --- a/pkg/config/formatters.go +++ b/pkg/config/formatters.go @@ -22,6 +22,7 @@ func (f *Formatters) Validate() error { } type FormatterExclusions struct { - Generated string `mapstructure:"generated"` - Paths []string `mapstructure:"paths"` + Generated string `mapstructure:"generated"` + Paths []string `mapstructure:"paths"` + WarnUnused bool `mapstructure:"warn-unused"` } diff --git a/pkg/goformat/runner.go b/pkg/goformat/runner.go index 5e1a2a6b1075..fa1d1acc3019 100644 --- a/pkg/goformat/runner.go +++ b/pkg/goformat/runner.go @@ -67,6 +67,14 @@ func (c *Runner) Run(paths []string) error { } } + for pattern, count := range c.opts.excludedPathCounter { + if c.opts.warnUnused && count == 0 { + c.log.Warnf("The pattern %q match no issues", pattern) + } else { + c.log.Infof("Skipped %d issues by pattern %q", count, pattern) + } + } + return nil } @@ -181,6 +189,9 @@ type RunnerOptions struct { diff bool colors bool stdin bool + + warnUnused bool + excludedPathCounter map[*regexp.Regexp]int } func NewRunnerOptions(cfg *config.Config, diff, diffColored, stdin bool) (RunnerOptions, error) { @@ -190,11 +201,13 @@ func NewRunnerOptions(cfg *config.Config, diff, diffColored, stdin bool) (Runner } opts := RunnerOptions{ - basePath: basePath, - generated: cfg.Formatters.Exclusions.Generated, - diff: diff || diffColored, - colors: diffColored, - stdin: stdin, + basePath: basePath, + generated: cfg.Formatters.Exclusions.Generated, + diff: diff || diffColored, + colors: diffColored, + stdin: stdin, + excludedPathCounter: make(map[*regexp.Regexp]int), + warnUnused: cfg.Formatters.Exclusions.WarnUnused, } for _, pattern := range cfg.Formatters.Exclusions.Paths { @@ -204,6 +217,7 @@ func NewRunnerOptions(cfg *config.Config, diff, diffColored, stdin bool) (Runner } opts.patterns = append(opts.patterns, exp) + opts.excludedPathCounter[exp] = 0 } return opts, nil @@ -221,6 +235,7 @@ func (o RunnerOptions) MatchAnyPattern(path string) (bool, error) { for _, pattern := range o.patterns { if pattern.MatchString(rel) { + o.excludedPathCounter[pattern]++ return true, nil } } diff --git a/pkg/result/processors/exclusion_paths.go b/pkg/result/processors/exclusion_paths.go index dafad44d1d3b..104c33eefa5b 100644 --- a/pkg/result/processors/exclusion_paths.go +++ b/pkg/result/processors/exclusion_paths.go @@ -79,7 +79,7 @@ func (p *ExclusionPaths) Process(issues []result.Issue) ([]result.Issue, error) func (p *ExclusionPaths) Finish() { for pattern, count := range p.excludedPathCounter { if p.warnUnused && count == 0 { - p.log.Warnf("The pattern %q match %d issues", pattern, count) + p.log.Warnf("The pattern %q match no issues", pattern) } else { p.log.Infof("Skipped %d issues by pattern %q", count, pattern) } @@ -87,7 +87,7 @@ func (p *ExclusionPaths) Finish() { for pattern, count := range p.excludedPathExceptCounter { if p.warnUnused && count == 0 { - p.log.Warnf("The pattern %q match %d issues", pattern, count) + p.log.Warnf("The pattern %q match no issues", pattern) } } }