feat: allow running only a specific linter without modifying the file configuration (#4438)
This commit is contained in:
parent
92c05581a3
commit
803970f0ed
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user