diff --git a/pkg/config/config.go b/pkg/config/config.go index d77dca07fd92..a6236a23f3af 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -64,6 +64,7 @@ func (c *Config) Validate() error { c.Run.Validate, c.Output.Validate, c.Linters.Validate, + c.Formatters.Validate, c.Severity.Validate, } diff --git a/pkg/config/formatters.go b/pkg/config/formatters.go index 054ea54d6d05..1bb623bc4ba8 100644 --- a/pkg/config/formatters.go +++ b/pkg/config/formatters.go @@ -1,11 +1,26 @@ package config +import ( + "fmt" + "slices" +) + type Formatters struct { Enable []string `mapstructure:"enable"` Settings FormatterSettings `mapstructure:"settings"` Exclusions FormatterExclusions `mapstructure:"exclusions"` } +func (f *Formatters) Validate() error { + for _, n := range f.Enable { + if !slices.Contains(getAllFormatterNames(), n) { + return fmt.Errorf("%s is a formatter", n) + } + } + + return nil +} + type FormatterExclusions struct { Generated string `mapstructure:"generated"` Paths []string `mapstructure:"paths"` diff --git a/pkg/config/linters.go b/pkg/config/linters.go index 06ec251a3826..590d9448a197 100644 --- a/pkg/config/linters.go +++ b/pkg/config/linters.go @@ -26,8 +26,7 @@ type Linters struct { func (l *Linters) Validate() error { validators := []func() error{ l.Exclusions.Validate, - l.validateNoFormattersEnabled, - l.validateNoFormattersDisabled, + l.validateNoFormatters, } for _, v := range validators { @@ -39,18 +38,8 @@ func (l *Linters) Validate() error { return nil } -func (l *Linters) validateNoFormattersEnabled() error { - for _, n := range l.Enable { - if slices.Contains(getAllFormatterNames(), n) { - return fmt.Errorf("%s is a formatter", n) - } - } - - return nil -} - -func (l *Linters) validateNoFormattersDisabled() error { - for _, n := range l.Disable { +func (l *Linters) validateNoFormatters() error { + for _, n := range slices.Concat(l.Enable, l.Disable) { if slices.Contains(getAllFormatterNames(), n) { return fmt.Errorf("%s is a formatter", n) } @@ -60,5 +49,5 @@ func (l *Linters) validateNoFormattersDisabled() error { } func getAllFormatterNames() []string { - return []string{"gci", "gofmt", "gofumpt", "goimports"} + return []string{"gci", "gofmt", "gofumpt", "goimports", "golines"} }