Skip to content

Commit

Permalink
build(deps): bump github.com/karamaru-alpha/copyloopvar from 1.1.0 to…
Browse files Browse the repository at this point in the history
… 1.2.1 (#5307)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
  • Loading branch information
dependabot[bot] and ldez authored Jan 11, 2025
1 parent ace35f0 commit e24c18c
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
github.com/jingyugao/rowserrcheck v1.1.1
github.com/jjti/go-spancheck v0.6.4
github.com/julz/importas v0.2.0
github.com/karamaru-alpha/copyloopvar v1.1.0
github.com/karamaru-alpha/copyloopvar v1.2.1
github.com/kisielk/errcheck v1.8.0
github.com/kkHAIKE/contextcheck v1.1.5
github.com/kulti/thelper v0.6.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/golinters/copyloopvar/copyloopvar_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ import (
func TestFromTestdata(t *testing.T) {
integration.RunTestdata(t)
}

func TestFix(t *testing.T) {
integration.RunFix(t)
}

func TestFixPathPrefix(t *testing.T) {
integration.RunFixPathPrefix(t)
}
39 changes: 39 additions & 0 deletions pkg/golinters/copyloopvar/testdata/fix/in/copyloopvar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//golangcitest:args -Ecopyloopvar
//golangcitest:expected_exitcode 0
package testdata

import "fmt"

func _() {
slice := []int{1, 2, 3}
fns := make([]func(), 0, len(slice)*2)
for i, v := range slice {
i := i // want `The copy of the 'for' variable "i" can be deleted \(Go 1\.22\+\)`
fns = append(fns, func() {
fmt.Println(i)
})
v := v // want `The copy of the 'for' variable "v" can be deleted \(Go 1\.22\+\)`
fns = append(fns, func() {
fmt.Println(v)
})
_v := v
_ = _v
}
for _, fn := range fns {
fn()
}
}

func _() {
loopCount := 3
fns := make([]func(), 0, loopCount)
for i := 1; i <= loopCount; i++ {
i := i // want `The copy of the 'for' variable "i" can be deleted \(Go 1\.22\+\)`
fns = append(fns, func() {
fmt.Println(i)
})
}
for _, fn := range fns {
fn()
}
}
39 changes: 39 additions & 0 deletions pkg/golinters/copyloopvar/testdata/fix/out/copyloopvar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//golangcitest:args -Ecopyloopvar
//golangcitest:expected_exitcode 0
package testdata

import "fmt"

func _() {
slice := []int{1, 2, 3}
fns := make([]func(), 0, len(slice)*2)
for i, v := range slice {
// want `The copy of the 'for' variable "i" can be deleted \(Go 1\.22\+\)`
fns = append(fns, func() {
fmt.Println(i)
})
// want `The copy of the 'for' variable "v" can be deleted \(Go 1\.22\+\)`
fns = append(fns, func() {
fmt.Println(v)
})
_v := v
_ = _v
}
for _, fn := range fns {
fn()
}
}

func _() {
loopCount := 3
fns := make([]func(), 0, loopCount)
for i := 1; i <= loopCount; i++ {
// want `The copy of the 'for' variable "i" can be deleted \(Go 1\.22\+\)`
fns = append(fns, func() {
fmt.Println(i)
})
}
for _, fn := range fns {
fn()
}
}
1 change: 1 addition & 0 deletions pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
linter.NewConfig(copyloopvar.New(&cfg.LintersSettings.CopyLoopVar)).
WithSince("v1.57.0").
WithPresets(linter.PresetStyle).
WithAutoFix().
WithURL("/~https://github.com/karamaru-alpha/copyloopvar").
WithNoopFallback(cfg, linter.IsGoLowerThanGo122()),

Expand Down

0 comments on commit e24c18c

Please sign in to comment.