Skip to content

Commit 803970f

Browse files
authored
feat: allow running only a specific linter without modifying the file configuration (#4438)
1 parent 92c0558 commit 803970f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

pkg/commands/flagsets.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ 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("enable-only", nil,
33+
color.GreenString("Override linters configuration section to only run the specific linter(s)")) // Flags only.
3134
}
3235

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

pkg/config/loader.go

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

6262
l.handleGoVersion()
6363

64+
err = l.handleEnableOnlyOption()
65+
if err != nil {
66+
return err
67+
}
68+
69+
return nil
70+
}
71+
72+
func (l *Loader) handleEnableOnlyOption() error {
73+
only, err := l.fs.GetStringSlice("enable-only")
74+
if err != nil {
75+
return err
76+
}
77+
78+
if len(only) > 0 {
79+
l.cfg.Linters = Linters{
80+
Enable: only,
81+
DisableAll: true,
82+
}
83+
}
84+
6485
return nil
6586
}
6687

@@ -73,13 +94,14 @@ func (l *Loader) handleGoVersion() {
7394

7495
l.cfg.LintersSettings.ParallelTest.Go = l.cfg.Run.Go
7596

76-
trimmedGoVersion := trimGoVersion(l.cfg.Run.Go)
77-
78-
l.cfg.LintersSettings.Gocritic.Go = trimmedGoVersion
7997
if l.cfg.LintersSettings.Gofumpt.LangVersion == "" {
8098
l.cfg.LintersSettings.Gofumpt.LangVersion = l.cfg.Run.Go
8199
}
82100

101+
trimmedGoVersion := trimGoVersion(l.cfg.Run.Go)
102+
103+
l.cfg.LintersSettings.Gocritic.Go = trimmedGoVersion
104+
83105
// staticcheck related linters.
84106
if l.cfg.LintersSettings.Staticcheck.GoVersion == "" {
85107
l.cfg.LintersSettings.Staticcheck.GoVersion = trimmedGoVersion

0 commit comments

Comments
 (0)