Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions pkg/commands/flagsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 25 additions & 3 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ func (l *Loader) Load() error {

l.handleGoVersion()

err = l.handleOnlyOption()
if err != nil {
return err
}

return nil
}

func (l *Loader) handleOnlyOption() error {
only, err := l.fs.GetStringSlice("only")
if err != nil {
return err
}

if len(only) > 0 {
l.cfg.Linters = Linters{
Enable: only,
DisableAll: true,
}
}

return nil
}

Expand All @@ -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
Expand Down