Skip to content

Commit aa5b707

Browse files
committed
fix(exportloopref): disable linter for Go versions >= Go 1.22
The problem reported by the linter has been fixed with Go 1.22. See https://go.dev/blog/loopvar-preview.
1 parent adbdfdb commit aa5b707

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pkg/lint/linter/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ func (lc *Config) WithNoopFallback(cfg *config.Config, cond func(cfg *config.Con
163163
return lc
164164
}
165165

166+
func IsGoGreaterThanOrEqualGo122() func(cfg *config.Config) error {
167+
return func(cfg *config.Config) error {
168+
if cfg == nil || !config.IsGoGreaterThanOrEqual(cfg.Run.Go, "1.22") {
169+
return nil
170+
}
171+
172+
return fmt.Errorf("this linter is disabled because the Go version (%s) of your project is greater than or equal Go 1.22", cfg.Run.Go)
173+
}
174+
}
175+
166176
func IsGoLowerThanGo122() func(cfg *config.Config) error {
167177
return func(cfg *config.Config) error {
168178
if cfg == nil || config.IsGoGreaterThanOrEqual(cfg.Run.Go, "1.22") {

pkg/lint/lintersdb/builder_linter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
278278
WithSince("v1.28.0").
279279
WithPresets(linter.PresetBugs).
280280
WithLoadForGoAnalysis().
281-
WithURL("https://github.com/kyoh86/exportloopref"),
281+
WithURL("https://github.com/kyoh86/exportloopref").
282+
WithNoopFallback(cfg, linter.IsGoGreaterThanOrEqualGo122()),
282283

283284
linter.NewConfig(forbidigo.New(&cfg.LintersSettings.Forbidigo)).
284285
WithSince("v1.34.0").

0 commit comments

Comments
 (0)