File tree 3 files changed +39
-1
lines changed 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1
1
package config
2
2
3
3
import (
4
+ "errors"
5
+ "fmt"
6
+ "regexp"
4
7
"time"
5
8
)
6
9
@@ -233,6 +236,37 @@ type ExcludeRule struct {
233
236
Text string
234
237
}
235
238
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
+
236
270
type Issues struct {
237
271
ExcludePatterns []string `mapstructure:"exclude"`
238
272
ExcludeRules []ExcludeRule `mapstructure:"exclude-rules"`
Original file line number Diff line number Diff line change @@ -105,6 +105,11 @@ func (r *FileReader) validateConfig() error {
105
105
if c .Run .IsVerbose {
106
106
return errors .New ("can't set run.verbose option with config: only on command-line" )
107
107
}
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
+ }
108
113
109
114
return nil
110
115
}
Original file line number Diff line number Diff line change @@ -55,7 +55,6 @@ func NewExcludeRules(rules []ExcludeRule) *ExcludeRules {
55
55
if rule .Path != "" {
56
56
parsedRule .path = regexp .MustCompile (rule .Path )
57
57
}
58
- // TODO: Forbid text-only, linter-only or path-only exclude rule.
59
58
r .rules = append (r .rules , parsedRule )
60
59
}
61
60
return r
You can’t perform that action at this time.
0 commit comments