diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5969189..7b27f18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest env: GO_VERSION: stable - GOLANGCI_LINT_VERSION: v1.57.2 + GOLANGCI_LINT_VERSION: v1.60.3 CGO_ENABLED: 0 steps: diff --git a/.golangci.yml b/.golangci.yml index e0ace8f..7e9f739 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -53,17 +53,9 @@ linters-settings: linters: enable-all: true disable: - - scopelint # deprecated - - interfacer # deprecated - - maligned # deprecated - - golint # deprecated - - exhaustivestruct # deprecated - - scopelint # deprecated - - varcheck # deprecated - - structcheck # deprecated - - nosnakecase # deprecated - - deadcode # deprecated - - ifshort # deprecated + - execinquery # deprecated + - exportloopref # deprecated + - gomnd # deprecated - sqlclosecheck # not relevant (SQL) - rowserrcheck # not relevant (SQL) - cyclop # duplicate of gocyclo @@ -71,8 +63,8 @@ linters: - dupl - wsl - nlreturn - - gomnd - - goerr113 + - mnd + - err113 - wrapcheck - exhaustive - exhaustruct @@ -99,3 +91,6 @@ issues: linters: - funlen - noctx + +output: + show-stats: true diff --git a/go.mod b/go.mod index 9ce066f..66ee2b6 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module github.com/traefik/mocktail -go 1.21 +go 1.22.0 require ( github.com/ettle/strcase v0.2.0 - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.9.0 ) require ( diff --git a/go.sum b/go.sum index eb22b76..8da4f94 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,12 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q= github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/mocktail.go b/mocktail.go index c845c5d..7674c24 100644 --- a/mocktail.go +++ b/mocktail.go @@ -153,7 +153,7 @@ func walk(root, moduleName string) (map[string]PackageDesc, error) { return fmt.Errorf("type %q in %q is not an interface", lookup.Type(), fp) } - for i := 0; i < interfaceType.NumMethods(); i++ { + for i := range interfaceType.NumMethods() { method := interfaceType.Method(i) interfaceDesc.Methods = append(interfaceDesc.Methods, method) @@ -197,7 +197,7 @@ func getTupleImports(tuples ...*types.Tuple) []string { var imports []string for _, tuple := range tuples { - for i := 0; i < tuple.Len(); i++ { + for i := range tuple.Len() { imports = append(imports, getTypeImports(tuple.At(i).Type())...) } } diff --git a/syrup.go b/syrup.go index 12b78b5..a070135 100644 --- a/syrup.go +++ b/syrup.go @@ -121,7 +121,7 @@ func (s Syrup) mockedMethod(writer io.Writer) error { params := s.Signature.Params() var argNames []string - for i := 0; i < params.Len(); i++ { + for i := range params.Len() { param := params.At(i) if param.Type().String() == contextType { @@ -147,7 +147,7 @@ func (s Syrup) mockedMethod(writer io.Writer) error { w.Print("(") } - for i := 0; i < results.Len(); i++ { + for i := range results.Len() { w.Print(s.getTypeName(results.At(i).Type(), false)) if i+1 < results.Len() { w.Print(", ") @@ -168,7 +168,7 @@ func (s Syrup) mockedMethod(writer io.Writer) error { s.writeReturnsFnCaller(w, argNames, params, results) - for i := 0; i < results.Len(); i++ { + for i := range results.Len() { if i == 0 { w.Println() } @@ -186,7 +186,7 @@ func (s Syrup) mockedMethod(writer io.Writer) error { } } - for i := 0; i < results.Len(); i++ { + for i := range results.Len() { if i == 0 { w.Println() w.Print("\treturn ") @@ -230,7 +230,7 @@ func (s Syrup) methodOn(writer io.Writer) error { params := s.Signature.Params() var argNames []string - for i := 0; i < params.Len(); i++ { + for i := range params.Len() { param := params.At(i) if param.Type().String() == contextType { @@ -276,7 +276,7 @@ func (s Syrup) methodOnRaw(writer io.Writer) error { params := s.Signature.Params() var argNames []string - for i := 0; i < params.Len(); i++ { + for i := range params.Len() { param := params.At(i) if param.Type().String() == contextType { @@ -374,7 +374,7 @@ func (s Syrup) typedReturns(writer io.Writer) error { w.Printf("func (_c *%s%sCall) TypedReturns(", structBaseName, s.Method.Name()) var returnNames string - for i := 0; i < results.Len(); i++ { + for i := range results.Len() { rName := string(rune(int('a') + i)) w.Printf("%s %s", rName, s.getTypeName(results.At(i).Type(), false)) @@ -408,7 +408,7 @@ func (s Syrup) typedRun(writer io.Writer) error { var pos int var paramNames []string - for i := 0; i < params.Len(); i++ { + for i := range params.Len() { param := params.At(i) pType := param.Type() @@ -479,7 +479,7 @@ func (s Syrup) callMethodsOn(writer io.Writer, methods []*types.Func) error { params := sign.Params() var argNames []string - for i := 0; i < params.Len(); i++ { + for i := range params.Len() { param := params.At(i) if param.Type().String() == contextType { @@ -525,7 +525,7 @@ func (s Syrup) callMethodOnRaw(writer io.Writer, methods []*types.Func) error { params := sign.Params() var argNames []string - for i := 0; i < params.Len(); i++ { + for i := range params.Len() { param := params.At(i) if param.Type().String() == contextType { @@ -603,7 +603,7 @@ func (s Syrup) getTypeName(t types.Type, last bool) string { func (s Syrup) getTupleTypes(t *types.Tuple) []string { var tupleTypes []string - for i := 0; i < t.Len(); i++ { + for i := range t.Len() { param := t.At(i) tupleTypes = append(tupleTypes, s.getTypeName(param.Type(), false)) @@ -645,7 +645,7 @@ func (s Syrup) getChanTypeName(t *types.Chan) string { func (s Syrup) createFuncSignature(params, results *types.Tuple) string { fnSign := "func(" - for i := 0; i < params.Len(); i++ { + for i := range params.Len() { param := params.At(i) if param.Type().String() == contextType { continue @@ -661,7 +661,7 @@ func (s Syrup) createFuncSignature(params, results *types.Tuple) string { if results != nil { fnSign += "(" - for i := 0; i < results.Len(); i++ { + for i := range results.Len() { rType := results.At(i).Type() fnSign += s.getTypeName(rType, false) if i+1 < results.Len() {