mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
feat: disable copyloopvar and intrange on Go < 1.22 (#4397)
This commit is contained in:
parent
c65868c105
commit
64492b5e59
12 changed files with 148 additions and 32 deletions
|
@ -1,7 +1,8 @@
|
|||
package linter
|
||||
|
||||
import (
|
||||
"golang.org/x/tools/go/analysis"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/tools/go/packages"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
|
@ -133,23 +134,27 @@ func (lc *Config) Name() string {
|
|||
return lc.Linter.Name()
|
||||
}
|
||||
|
||||
func (lc *Config) WithNoopFallback(cfg *config.Config) *Config {
|
||||
if cfg != nil && config.IsGreaterThanOrEqualGo122(cfg.Run.Go) {
|
||||
lc.Linter = &Noop{
|
||||
name: lc.Linter.Name(),
|
||||
desc: lc.Linter.Desc(),
|
||||
run: func(_ *analysis.Pass) (any, error) {
|
||||
return nil, nil
|
||||
},
|
||||
}
|
||||
|
||||
func (lc *Config) WithNoopFallback(cfg *config.Config, cond func(cfg *config.Config) error) *Config {
|
||||
if err := cond(cfg); err != nil {
|
||||
lc.Linter = NewNoop(lc.Linter, err.Error())
|
||||
lc.LoadMode = 0
|
||||
|
||||
return lc.WithLoadFiles()
|
||||
}
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
func IsGoLowerThanGo122() func(cfg *config.Config) error {
|
||||
return func(cfg *config.Config) error {
|
||||
if cfg == nil || config.IsGoGreaterThanOrEqual(cfg.Run.Go, "1.22") {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("this linter is disabled because the Go version (%s) of your project is lower than Go 1.22", cfg.Run.Go)
|
||||
}
|
||||
}
|
||||
|
||||
func NewConfig(linter Linter) *Config {
|
||||
lc := &Config{
|
||||
Linter: linter,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue