Skip to content

Commit 001273b

Browse files
committed
feat: propagate formatter exclusions to linter exclusions
1 parent 7afd1b4 commit 001273b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

pkg/config/loader.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (l *Loader) Load(opts LoadOptions) error {
8888
l.cfg.Linters.LinterExclusions.Rules = append(l.cfg.Linters.LinterExclusions.Rules, l.cfg.Issues.ExcludeRules...)
8989
}
9090

91-
l.handleFormatterOverrides()
91+
l.handleFormatters()
9292

9393
if opts.CheckDeprecation {
9494
err = l.handleDeprecation()
@@ -504,6 +504,11 @@ func (l *Loader) handleEnableOnlyOption() error {
504504
return nil
505505
}
506506

507+
func (l *Loader) handleFormatters() {
508+
l.handleFormatterOverrides()
509+
l.handleFormatterExclusions()
510+
}
511+
507512
// Overrides linter settings with formatter settings if the formatter is enabled.
508513
func (l *Loader) handleFormatterOverrides() {
509514
if slices.Contains(l.cfg.Formatters.Enable, "gofmt") {
@@ -523,6 +528,22 @@ func (l *Loader) handleFormatterOverrides() {
523528
}
524529
}
525530

531+
// Add formatter exclusions to linters exclusions.
532+
func (l *Loader) handleFormatterExclusions() {
533+
if len(l.cfg.Formatters.Enable) == 0 {
534+
return
535+
}
536+
537+
for _, path := range l.cfg.Formatters.Exclusions.Paths {
538+
l.cfg.Linters.LinterExclusions.Rules = append(l.cfg.Linters.LinterExclusions.Rules, ExcludeRule{
539+
BaseRule: BaseRule{
540+
Linters: l.cfg.Formatters.Enable,
541+
Path: path,
542+
},
543+
})
544+
}
545+
}
546+
526547
func customDecoderHook() viper.DecoderConfigOption {
527548
return viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
528549
// Default hooks (https://github.com/spf13/viper/blob/518241257478c557633ab36e474dfcaeb9a3c623/viper.go#L135-L138).

0 commit comments

Comments
 (0)