Skip to content

Commit

Permalink
feat: add an option to only run some linters with the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 2, 2024
1 parent b14d05c commit 32be3cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/commands/flagsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ 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("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
25 changes: 25 additions & 0 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ 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,
Disable: nil,
EnableAll: false,
DisableAll: true,
Fast: false,
Presets: nil,
}
}

return nil
}

Expand Down

0 comments on commit 32be3cf

Please sign in to comment.