build(deps): bump github.com/karamaru-alpha/copyloopvar from 1.0.4 to 1.0.8 (#4444)
This commit is contained in:
parent
b5c339f4fe
commit
df70758a05
@ -149,6 +149,11 @@ linters-settings:
|
|||||||
first-strong-isolate: false
|
first-strong-isolate: false
|
||||||
pop-directional-isolate: false
|
pop-directional-isolate: false
|
||||||
|
|
||||||
|
copyloopvar:
|
||||||
|
# If true, ignore aliasing of loop variables.
|
||||||
|
# Default: false
|
||||||
|
ignore-alias: true
|
||||||
|
|
||||||
cyclop:
|
cyclop:
|
||||||
# The maximal code complexity to report.
|
# The maximal code complexity to report.
|
||||||
# Default: 10
|
# Default: 10
|
||||||
|
2
go.mod
2
go.mod
@ -61,7 +61,7 @@ require (
|
|||||||
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af
|
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af
|
||||||
github.com/jjti/go-spancheck v0.5.3
|
github.com/jjti/go-spancheck v0.5.3
|
||||||
github.com/julz/importas v0.1.0
|
github.com/julz/importas v0.1.0
|
||||||
github.com/karamaru-alpha/copyloopvar v1.0.4
|
github.com/karamaru-alpha/copyloopvar v1.0.8
|
||||||
github.com/kisielk/errcheck v1.7.0
|
github.com/kisielk/errcheck v1.7.0
|
||||||
github.com/kkHAIKE/contextcheck v1.1.4
|
github.com/kkHAIKE/contextcheck v1.1.4
|
||||||
github.com/kulti/thelper v0.6.3
|
github.com/kulti/thelper v0.6.3
|
||||||
|
4
go.sum
generated
4
go.sum
generated
@ -322,8 +322,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
|
|||||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||||
github.com/julz/importas v0.1.0 h1:F78HnrsjY3cR7j0etXy5+TU1Zuy7Xt08X/1aJnH5xXY=
|
github.com/julz/importas v0.1.0 h1:F78HnrsjY3cR7j0etXy5+TU1Zuy7Xt08X/1aJnH5xXY=
|
||||||
github.com/julz/importas v0.1.0/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0=
|
github.com/julz/importas v0.1.0/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0=
|
||||||
github.com/karamaru-alpha/copyloopvar v1.0.4 h1:JD6IPXo4+RawkSPe9uMKh9OtTzYKsCelAgPMUwaVxBw=
|
github.com/karamaru-alpha/copyloopvar v1.0.8 h1:gieLARwuByhEMxRwM3GRS/juJqFbLraftXIKDDNJ50Q=
|
||||||
github.com/karamaru-alpha/copyloopvar v1.0.4/go.mod h1:u7CIfztblY0jZLOQZgH3oYsJzpC2A7S6u/lfgSXHy0k=
|
github.com/karamaru-alpha/copyloopvar v1.0.8/go.mod h1:u7CIfztblY0jZLOQZgH3oYsJzpC2A7S6u/lfgSXHy0k=
|
||||||
github.com/kisielk/errcheck v1.7.0 h1:+SbscKmWJ5mOK/bO1zS60F5I9WwZDWOfRsC4RwfwRV0=
|
github.com/kisielk/errcheck v1.7.0 h1:+SbscKmWJ5mOK/bO1zS60F5I9WwZDWOfRsC4RwfwRV0=
|
||||||
github.com/kisielk/errcheck v1.7.0/go.mod h1:1kLL+jV4e+CFfueBmI1dSK2ADDyQnlrnrY/FqKluHJQ=
|
github.com/kisielk/errcheck v1.7.0/go.mod h1:1kLL+jV4e+CFfueBmI1dSK2ADDyQnlrnrY/FqKluHJQ=
|
||||||
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
|
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
|
||||||
|
@ -206,6 +206,7 @@ var defaultLintersSettings = LintersSettings{
|
|||||||
type LintersSettings struct {
|
type LintersSettings struct {
|
||||||
Asasalint AsasalintSettings
|
Asasalint AsasalintSettings
|
||||||
BiDiChk BiDiChkSettings
|
BiDiChk BiDiChkSettings
|
||||||
|
CopyLoopVar CopyLoopVarSettings
|
||||||
Cyclop Cyclop
|
Cyclop Cyclop
|
||||||
Decorder DecorderSettings
|
Decorder DecorderSettings
|
||||||
Depguard DepGuardSettings
|
Depguard DepGuardSettings
|
||||||
@ -313,6 +314,10 @@ type BiDiChkSettings struct {
|
|||||||
PopDirectionalIsolate bool `mapstructure:"pop-directional-isolate"`
|
PopDirectionalIsolate bool `mapstructure:"pop-directional-isolate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CopyLoopVarSettings struct {
|
||||||
|
IgnoreAlias bool `mapstructure:"ignore-alias"`
|
||||||
|
}
|
||||||
|
|
||||||
type Cyclop struct {
|
type Cyclop struct {
|
||||||
MaxComplexity int `mapstructure:"max-complexity"`
|
MaxComplexity int `mapstructure:"max-complexity"`
|
||||||
PackageAverage float64 `mapstructure:"package-average"`
|
PackageAverage float64 `mapstructure:"package-average"`
|
||||||
|
@ -4,16 +4,26 @@ import (
|
|||||||
"github.com/karamaru-alpha/copyloopvar"
|
"github.com/karamaru-alpha/copyloopvar"
|
||||||
"golang.org/x/tools/go/analysis"
|
"golang.org/x/tools/go/analysis"
|
||||||
|
|
||||||
|
"github.com/golangci/golangci-lint/pkg/config"
|
||||||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
|
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCopyLoopVar() *goanalysis.Linter {
|
func NewCopyLoopVar(settings *config.CopyLoopVarSettings) *goanalysis.Linter {
|
||||||
a := copyloopvar.Analyzer
|
a := copyloopvar.NewAnalyzer()
|
||||||
|
|
||||||
|
var cfg map[string]map[string]any
|
||||||
|
if settings != nil {
|
||||||
|
cfg = map[string]map[string]any{
|
||||||
|
a.Name: {
|
||||||
|
"ignore-alias": settings.IgnoreAlias,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return goanalysis.NewLinter(
|
return goanalysis.NewLinter(
|
||||||
a.Name,
|
a.Name,
|
||||||
a.Doc,
|
a.Doc,
|
||||||
[]*analysis.Analyzer{a},
|
[]*analysis.Analyzer{a},
|
||||||
nil,
|
cfg,
|
||||||
).WithLoadMode(goanalysis.LoadModeSyntax)
|
).WithLoadMode(goanalysis.LoadModeSyntax)
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config {
|
|||||||
WithLoadForGoAnalysis().
|
WithLoadForGoAnalysis().
|
||||||
WithURL("https://github.com/kkHAIKE/contextcheck"),
|
WithURL("https://github.com/kkHAIKE/contextcheck"),
|
||||||
|
|
||||||
linter.NewConfig(golinters.NewCopyLoopVar()).
|
linter.NewConfig(golinters.NewCopyLoopVar(&cfg.LintersSettings.CopyLoopVar)).
|
||||||
WithSince("v1.57.0").
|
WithSince("v1.57.0").
|
||||||
WithPresets(linter.PresetStyle).
|
WithPresets(linter.PresetStyle).
|
||||||
WithURL("https://github.com/karamaru-alpha/copyloopvar").
|
WithURL("https://github.com/karamaru-alpha/copyloopvar").
|
||||||
|
3
test/testdata/configs/copyloopvar.yml
vendored
Normal file
3
test/testdata/configs/copyloopvar.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
linters-settings:
|
||||||
|
copyloopvar:
|
||||||
|
ignore-alias: true
|
6
test/testdata/copyloopvar.go
vendored
6
test/testdata/copyloopvar.go
vendored
@ -13,10 +13,12 @@ func copyloopvarCase1() {
|
|||||||
fns = append(fns, func() {
|
fns = append(fns, func() {
|
||||||
fmt.Println(i)
|
fmt.Println(i)
|
||||||
})
|
})
|
||||||
_v := v // want `The copy of the 'for' variable "v" can be deleted \(Go 1\.22\+\)`
|
v := v // want `The copy of the 'for' variable "v" can be deleted \(Go 1\.22\+\)`
|
||||||
fns = append(fns, func() {
|
fns = append(fns, func() {
|
||||||
fmt.Println(_v)
|
fmt.Println(v)
|
||||||
})
|
})
|
||||||
|
_v := v // want `The copy of the 'for' variable "v" can be deleted \(Go 1\.22\+\)`
|
||||||
|
_ = _v
|
||||||
}
|
}
|
||||||
for _, fn := range fns {
|
for _, fn := range fns {
|
||||||
fn()
|
fn()
|
||||||
|
41
test/testdata/copyloopvar_custom.go
vendored
Normal file
41
test/testdata/copyloopvar_custom.go
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//go:build go1.22
|
||||||
|
|
||||||
|
//golangcitest:args -Ecopyloopvar
|
||||||
|
//golangcitest:config_path testdata/configs/copyloopvar.yml
|
||||||
|
package testdata
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func copyloopvarCase1() {
|
||||||
|
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 copyloopvarCase2() {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user