mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-01 17:09:18 -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
pkg/lint
|
@ -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,
|
||||
|
|
|
@ -3,8 +3,6 @@ package linter
|
|||
import (
|
||||
"context"
|
||||
|
||||
"golang.org/x/tools/go/analysis"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
)
|
||||
|
||||
|
@ -15,14 +13,23 @@ type Linter interface {
|
|||
}
|
||||
|
||||
type Noop struct {
|
||||
name string
|
||||
desc string
|
||||
run func(pass *analysis.Pass) (any, error)
|
||||
name string
|
||||
desc string
|
||||
reason string
|
||||
}
|
||||
|
||||
func NewNoop(l Linter, reason string) Noop {
|
||||
return Noop{
|
||||
name: l.Name(),
|
||||
desc: l.Desc(),
|
||||
reason: reason,
|
||||
}
|
||||
}
|
||||
|
||||
func (n Noop) Run(_ context.Context, lintCtx *Context) ([]result.Issue, error) {
|
||||
lintCtx.Log.Warnf("%s is disabled because of generics."+
|
||||
" You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.", n.name)
|
||||
if n.reason != "" {
|
||||
lintCtx.Log.Warnf("%s: %s", n.name, n.reason)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -303,7 +303,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
|||
linter.NewConfig(golinters.NewCopyLoopVar()).
|
||||
WithSince("v1.57.0").
|
||||
WithPresets(linter.PresetStyle).
|
||||
WithURL("https://github.com/karamaru-alpha/copyloopvar"),
|
||||
WithURL("https://github.com/karamaru-alpha/copyloopvar").
|
||||
WithNoopFallback(m.cfg, linter.IsGoLowerThanGo122()),
|
||||
|
||||
linter.NewConfig(golinters.NewCyclop(cyclopCfg)).
|
||||
WithSince("v1.37.0").
|
||||
|
@ -617,7 +618,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
|||
|
||||
linter.NewConfig(golinters.NewIntrange()).
|
||||
WithSince("v1.57.0").
|
||||
WithURL("https://github.com/ckaznocha/intrange"),
|
||||
WithURL("https://github.com/ckaznocha/intrange").
|
||||
WithNoopFallback(m.cfg, linter.IsGoLowerThanGo122()),
|
||||
|
||||
linter.NewConfig(golinters.NewIreturn(ireturnCfg)).
|
||||
WithSince("v1.43.0").
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue