Skip to content

Commit 7afd1b4

Browse files
committed
feat: formatter settings overrides linter settings
1 parent de33fec commit 7afd1b4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/config/loader.go

+21
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ 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()
92+
9193
if opts.CheckDeprecation {
9294
err = l.handleDeprecation()
9395
if err != nil {
@@ -502,6 +504,25 @@ func (l *Loader) handleEnableOnlyOption() error {
502504
return nil
503505
}
504506

507+
// Overrides linter settings with formatter settings if the formatter is enabled.
508+
func (l *Loader) handleFormatterOverrides() {
509+
if slices.Contains(l.cfg.Formatters.Enable, "gofmt") {
510+
l.cfg.LintersSettings.GoFmt = l.cfg.Formatters.Settings.GoFmt
511+
}
512+
513+
if slices.Contains(l.cfg.Formatters.Enable, "gofumpt") {
514+
l.cfg.LintersSettings.GoFumpt = l.cfg.Formatters.Settings.GoFumpt
515+
}
516+
517+
if slices.Contains(l.cfg.Formatters.Enable, "goimports") {
518+
l.cfg.LintersSettings.GoImports = l.cfg.Formatters.Settings.GoImports
519+
}
520+
521+
if slices.Contains(l.cfg.Formatters.Enable, "gci") {
522+
l.cfg.LintersSettings.Gci = l.cfg.Formatters.Settings.Gci
523+
}
524+
}
525+
505526
func customDecoderHook() viper.DecoderConfigOption {
506527
return viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
507528
// Default hooks (https://github.com/spf13/viper/blob/518241257478c557633ab36e474dfcaeb9a3c623/viper.go#L135-L138).

0 commit comments

Comments
 (0)