diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index 4ba1f2adb3dd..e341b9fe13e4 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -28,6 +28,9 @@ func setupLintersFlagSet(v *viper.Viper, fs *pflag.FlagSet) { fs.StringSliceP("presets", "p", nil, color.GreenString(fmt.Sprintf("Enable presets (%s) of linters. Run 'golangci-lint help linters' to see "+ "them. This option implies option --disable-all", strings.Join(lintersdb.AllPresets(), "|")))) + + fs.StringSlice("enable-only", nil, + color.GreenString("Override linters configuration section to only run the specific linter(s)")) // Flags only. } func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) { diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 3884cad462d7..0cad5f0c2a80 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -61,6 +61,27 @@ func (l *Loader) Load() error { l.handleGoVersion() + err = l.handleEnableOnlyOption() + if err != nil { + return err + } + + return nil +} + +func (l *Loader) handleEnableOnlyOption() error { + only, err := l.fs.GetStringSlice("enable-only") + if err != nil { + return err + } + + if len(only) > 0 { + l.cfg.Linters = Linters{ + Enable: only, + DisableAll: true, + } + } + return nil } @@ -73,13 +94,14 @@ func (l *Loader) handleGoVersion() { l.cfg.LintersSettings.ParallelTest.Go = l.cfg.Run.Go - trimmedGoVersion := trimGoVersion(l.cfg.Run.Go) - - l.cfg.LintersSettings.Gocritic.Go = trimmedGoVersion if l.cfg.LintersSettings.Gofumpt.LangVersion == "" { l.cfg.LintersSettings.Gofumpt.LangVersion = l.cfg.Run.Go } + trimmedGoVersion := trimGoVersion(l.cfg.Run.Go) + + l.cfg.LintersSettings.Gocritic.Go = trimmedGoVersion + // staticcheck related linters. if l.cfg.LintersSettings.Staticcheck.GoVersion == "" { l.cfg.LintersSettings.Staticcheck.GoVersion = trimmedGoVersion