File tree 5 files changed +43
-21
lines changed
5 files changed +43
-21
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
4
"os"
7
5
"regexp"
8
6
"strings"
@@ -34,19 +32,16 @@ func (c *Config) GetConfigDir() string {
34
32
}
35
33
36
34
func (c * Config ) Validate () error {
37
- for i , rule := range c .Issues .ExcludeRules {
38
- if err := rule .Validate (); err != nil {
39
- return fmt .Errorf ("error in exclude rule #%d: %w" , i , err )
40
- }
35
+ if err := c .Issues .Validate (); err != nil {
36
+ return err
41
37
}
42
38
43
- if len ( c . Severity . Rules ) > 0 && c .Severity .Default == "" {
44
- return errors . New ( "can't set severity rule option: no default severity defined" )
39
+ if err := c .Severity .Validate (); err != nil {
40
+ return err
45
41
}
46
- for i , rule := range c .Severity .Rules {
47
- if err := rule .Validate (); err != nil {
48
- return fmt .Errorf ("error in severity rule #%d: %w" , i , err )
49
- }
42
+
43
+ if err := c .LintersSettings .Validate (); err != nil {
44
+ return err
50
45
}
51
46
52
47
return nil
Original file line number Diff line number Diff line change @@ -122,6 +122,16 @@ type Issues struct {
122
122
NeedFix bool `mapstructure:"fix"`
123
123
}
124
124
125
+ func (i * Issues ) Validate () error {
126
+ for i , rule := range i .ExcludeRules {
127
+ if err := rule .Validate (); err != nil {
128
+ return fmt .Errorf ("error in exclude rule #%d: %w" , i , err )
129
+ }
130
+ }
131
+
132
+ return nil
133
+ }
134
+
125
135
type ExcludeRule struct {
126
136
BaseRule `mapstructure:",squash"`
127
137
}
Original file line number Diff line number Diff line change @@ -291,6 +291,10 @@ type LintersSettings struct {
291
291
Custom map [string ]CustomLinterSettings
292
292
}
293
293
294
+ func (s * LintersSettings ) Validate () error {
295
+ return s .Govet .Validate ()
296
+ }
297
+
294
298
type AsasalintSettings struct {
295
299
Exclude []string `mapstructure:"exclude"`
296
300
UseBuiltinExclusions bool `mapstructure:"use-builtin-exclusions"`
@@ -606,15 +610,14 @@ type GovetSettings struct {
606
610
}
607
611
608
612
func (cfg * GovetSettings ) Validate () error {
609
- // TODO(ldez) need to be move into the linter file.
610
613
if cfg .EnableAll && cfg .DisableAll {
611
- return errors .New ("enable-all and disable-all can't be combined" )
614
+ return errors .New ("govet: enable-all and disable-all can't be combined" )
612
615
}
613
616
if cfg .EnableAll && len (cfg .Enable ) != 0 {
614
- return errors .New ("enable-all and enable can't be combined" )
617
+ return errors .New ("govet: enable-all and enable can't be combined" )
615
618
}
616
619
if cfg .DisableAll && len (cfg .Disable ) != 0 {
617
- return errors .New ("disable-all and disable can't be combined" )
620
+ return errors .New ("govet: disable-all and disable can't be combined" )
618
621
}
619
622
return nil
620
623
}
Original file line number Diff line number Diff line change 1
1
package config
2
2
3
+ import (
4
+ "errors"
5
+ "fmt"
6
+ )
7
+
3
8
const severityRuleMinConditionsCount = 1
4
9
5
10
type Severity struct {
@@ -8,6 +13,20 @@ type Severity struct {
8
13
Rules []SeverityRule `mapstructure:"rules"`
9
14
}
10
15
16
+ func (s * Severity ) Validate () error {
17
+ if len (s .Rules ) > 0 && s .Default == "" {
18
+ return errors .New ("can't set severity rule option: no default severity defined" )
19
+ }
20
+
21
+ for i , rule := range s .Rules {
22
+ if err := rule .Validate (); err != nil {
23
+ return fmt .Errorf ("error in severity rule #%d: %w" , i , err )
24
+ }
25
+ }
26
+
27
+ return nil
28
+ }
29
+
11
30
type SeverityRule struct {
12
31
BaseRule `mapstructure:",squash"`
13
32
Severity string
Original file line number Diff line number Diff line change @@ -139,11 +139,6 @@ var (
139
139
func NewGovet (settings * config.GovetSettings ) * goanalysis.Linter {
140
140
var conf map [string ]map [string ]any
141
141
if settings != nil {
142
- err := settings .Validate ()
143
- if err != nil {
144
- linterLogger .Fatalf ("govet configuration: %v" , err )
145
- }
146
-
147
142
conf = settings .Settings
148
143
}
149
144
You can’t perform that action at this time.
0 commit comments