Skip to content

Commit e35febc

Browse files
committed
chore(offtopic): extract govet validation from FileReader
1 parent 5741436 commit e35febc

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

pkg/config/linters_settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ type GovetSettings struct {
606606
}
607607

608608
func (cfg *GovetSettings) Validate() error {
609+
// TODO(ldez) need to be move into the linter file.
609610
if cfg.EnableAll && cfg.DisableAll {
610611
return errors.New("enable-all and disable-all can't be combined")
611612
}

pkg/config/reader.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,42 +116,41 @@ func (r *FileReader) parseConfig() error {
116116
}
117117

118118
func (r *FileReader) validateConfig() error {
119-
c := r.cfg
120-
if len(c.Run.Args) != 0 {
119+
if len(r.cfg.Run.Args) != 0 {
121120
return errors.New("option run.args in config isn't supported now")
122121
}
123122

124-
if c.Run.CPUProfilePath != "" {
123+
if r.cfg.Run.CPUProfilePath != "" {
125124
return errors.New("option run.cpuprofilepath in config isn't allowed")
126125
}
127126

128-
if c.Run.MemProfilePath != "" {
127+
if r.cfg.Run.MemProfilePath != "" {
129128
return errors.New("option run.memprofilepath in config isn't allowed")
130129
}
131130

132-
if c.Run.TracePath != "" {
131+
if r.cfg.Run.TracePath != "" {
133132
return errors.New("option run.tracepath in config isn't allowed")
134133
}
135134

136-
if c.Run.IsVerbose {
135+
if r.cfg.Run.IsVerbose {
137136
return errors.New("can't set run.verbose option with config: only on command-line")
138137
}
139-
for i, rule := range c.Issues.ExcludeRules {
138+
139+
for i, rule := range r.cfg.Issues.ExcludeRules {
140140
if err := rule.Validate(); err != nil {
141141
return fmt.Errorf("error in exclude rule #%d: %w", i, err)
142142
}
143143
}
144-
if len(c.Severity.Rules) > 0 && c.Severity.Default == "" {
144+
145+
if len(r.cfg.Severity.Rules) > 0 && r.cfg.Severity.Default == "" {
145146
return errors.New("can't set severity rule option: no default severity defined")
146147
}
147-
for i, rule := range c.Severity.Rules {
148+
for i, rule := range r.cfg.Severity.Rules {
148149
if err := rule.Validate(); err != nil {
149150
return fmt.Errorf("error in severity rule #%d: %w", i, err)
150151
}
151152
}
152-
if err := c.LintersSettings.Govet.Validate(); err != nil {
153-
return fmt.Errorf("error in govet config: %w", err)
154-
}
153+
155154
return nil
156155
}
157156

pkg/golinters/govet.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ func NewGovet(settings *config.GovetSettings) *goanalysis.Linter {
142142
conf = settings.Settings
143143
}
144144

145+
err := settings.Validate()
146+
if err != nil {
147+
linterLogger.Fatalf("govet configuration: %v", err)
148+
}
149+
145150
return goanalysis.NewLinter(
146151
"govet",
147152
"Vet examines Go source code and reports suspicious constructs. "+

0 commit comments

Comments
 (0)