Skip to content

feat: detects linters inside formatters #5544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (c *Config) Validate() error {
c.Run.Validate,
c.Output.Validate,
c.Linters.Validate,
c.Formatters.Validate,
c.Severity.Validate,
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/config/formatters.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down
19 changes: 4 additions & 15 deletions pkg/config/linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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"}
}
Loading