Skip to content

Commit 32be3cf

Browse files
committed
feat: add an option to only run some linters with the CLI
1 parent b14d05c commit 32be3cf

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

pkg/commands/flagsets.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func setupLintersFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
2828
fs.StringSliceP("presets", "p", nil,
2929
color.GreenString(fmt.Sprintf("Enable presets (%s) of linters. Run 'golangci-lint help linters' to see "+
3030
"them. This option implies option --disable-all", strings.Join(lintersdb.AllPresets(), "|"))))
31+
32+
fs.StringSlice("only", nil, color.GreenString("Override linters configuration section to only run the specific linter(s)")) // Flags only.
3133
}
3234

3335
func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {

pkg/config/loader.go

+25
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@ func (l *Loader) Load() error {
6161

6262
l.handleGoVersion()
6363

64+
err = l.handleOnlyOption()
65+
if err != nil {
66+
return err
67+
}
68+
69+
return nil
70+
}
71+
72+
func (l *Loader) handleOnlyOption() error {
73+
only, err := l.fs.GetStringSlice("only")
74+
if err != nil {
75+
return err
76+
}
77+
78+
if len(only) > 0 {
79+
l.cfg.Linters = Linters{
80+
Enable: only,
81+
Disable: nil,
82+
EnableAll: false,
83+
DisableAll: true,
84+
Fast: false,
85+
Presets: nil,
86+
}
87+
}
88+
6489
return nil
6590
}
6691

0 commit comments

Comments
 (0)