From 37958b281dc68378e6132147ef669e42831813e8 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 13 Mar 2025 17:45:03 +0100 Subject: [PATCH 1/2] feat: detects linters inside formatters --- pkg/config/config.go | 1 + pkg/config/formatters.go | 15 +++++++++++++++ pkg/config/linters.go | 17 +++-------------- 3 files changed, 19 insertions(+), 14 deletions(-) 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..bb62016d9612 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) } From fddc68303499737ccaa66af4d6c88e37aa7638d5 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 13 Mar 2025 17:56:11 +0100 Subject: [PATCH 2/2] fix: missing golines --- pkg/config/linters.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/linters.go b/pkg/config/linters.go index bb62016d9612..590d9448a197 100644 --- a/pkg/config/linters.go +++ b/pkg/config/linters.go @@ -49,5 +49,5 @@ func (l *Linters) validateNoFormatters() error { } func getAllFormatterNames() []string { - return []string{"gci", "gofmt", "gofumpt", "goimports"} + return []string{"gci", "gofmt", "gofumpt", "goimports", "golines"} }