Skip to content

Commit 4fbd027

Browse files
authored
feat: detects linters inside formatters (#5544)
1 parent 3f6f904 commit 4fbd027

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

pkg/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (c *Config) Validate() error {
6464
c.Run.Validate,
6565
c.Output.Validate,
6666
c.Linters.Validate,
67+
c.Formatters.Validate,
6768
c.Severity.Validate,
6869
}
6970

pkg/config/formatters.go

+15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
package config
22

3+
import (
4+
"fmt"
5+
"slices"
6+
)
7+
38
type Formatters struct {
49
Enable []string `mapstructure:"enable"`
510
Settings FormatterSettings `mapstructure:"settings"`
611
Exclusions FormatterExclusions `mapstructure:"exclusions"`
712
}
813

14+
func (f *Formatters) Validate() error {
15+
for _, n := range f.Enable {
16+
if !slices.Contains(getAllFormatterNames(), n) {
17+
return fmt.Errorf("%s is a formatter", n)
18+
}
19+
}
20+
21+
return nil
22+
}
23+
924
type FormatterExclusions struct {
1025
Generated string `mapstructure:"generated"`
1126
Paths []string `mapstructure:"paths"`

pkg/config/linters.go

+4-15
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ type Linters struct {
2626
func (l *Linters) Validate() error {
2727
validators := []func() error{
2828
l.Exclusions.Validate,
29-
l.validateNoFormattersEnabled,
30-
l.validateNoFormattersDisabled,
29+
l.validateNoFormatters,
3130
}
3231

3332
for _, v := range validators {
@@ -39,18 +38,8 @@ func (l *Linters) Validate() error {
3938
return nil
4039
}
4140

42-
func (l *Linters) validateNoFormattersEnabled() error {
43-
for _, n := range l.Enable {
44-
if slices.Contains(getAllFormatterNames(), n) {
45-
return fmt.Errorf("%s is a formatter", n)
46-
}
47-
}
48-
49-
return nil
50-
}
51-
52-
func (l *Linters) validateNoFormattersDisabled() error {
53-
for _, n := range l.Disable {
41+
func (l *Linters) validateNoFormatters() error {
42+
for _, n := range slices.Concat(l.Enable, l.Disable) {
5443
if slices.Contains(getAllFormatterNames(), n) {
5544
return fmt.Errorf("%s is a formatter", n)
5645
}
@@ -60,5 +49,5 @@ func (l *Linters) validateNoFormattersDisabled() error {
6049
}
6150

6251
func getAllFormatterNames() []string {
63-
return []string{"gci", "gofmt", "gofumpt", "goimports"}
52+
return []string{"gci", "gofmt", "gofumpt", "goimports", "golines"}
6453
}

0 commit comments

Comments
 (0)