File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 11package config
22
33import (
4+ "errors"
5+ "fmt"
6+ "regexp"
47 "time"
58)
69
@@ -233,6 +236,37 @@ type ExcludeRule struct {
233236 Text string
234237}
235238
239+ func validateOptionalRegex (value string ) error {
240+ if value == "" {
241+ return nil
242+ }
243+ _ , err := regexp .Compile (value )
244+ return err
245+ }
246+
247+ func (e ExcludeRule ) Validate () error {
248+ if err := validateOptionalRegex (e .Path ); err != nil {
249+ return fmt .Errorf ("invalid path regex: %v" , err )
250+ }
251+ if err := validateOptionalRegex (e .Text ); err != nil {
252+ return fmt .Errorf ("invalid text regex: %v" , err )
253+ }
254+ nonBlank := 0
255+ if len (e .Linters ) > 0 {
256+ nonBlank ++
257+ }
258+ if e .Path != "" {
259+ nonBlank ++
260+ }
261+ if e .Text != "" {
262+ nonBlank ++
263+ }
264+ if nonBlank < 2 {
265+ return errors .New ("at least 2 of (text, path, linters) should be set" )
266+ }
267+ return nil
268+ }
269+
236270type Issues struct {
237271 ExcludePatterns []string `mapstructure:"exclude"`
238272 ExcludeRules []ExcludeRule `mapstructure:"exclude-rules"`
Original file line number Diff line number Diff line change @@ -105,6 +105,11 @@ func (r *FileReader) validateConfig() error {
105105 if c .Run .IsVerbose {
106106 return errors .New ("can't set run.verbose option with config: only on command-line" )
107107 }
108+ for i , rule := range c .Issues .ExcludeRules {
109+ if err := rule .Validate (); err != nil {
110+ return fmt .Errorf ("error in exclude rule #%d: %v" , i , err )
111+ }
112+ }
108113
109114 return nil
110115}
Original file line number Diff line number Diff line change @@ -55,7 +55,6 @@ func NewExcludeRules(rules []ExcludeRule) *ExcludeRules {
5555 if rule .Path != "" {
5656 parsedRule .path = regexp .MustCompile (rule .Path )
5757 }
58- // TODO: Forbid text-only, linter-only or path-only exclude rule.
5958 r .rules = append (r .rules , parsedRule )
6059 }
6160 return r
You can’t perform that action at this time.
0 commit comments