diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 0858b13..df20356 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -14,7 +14,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.21.4' + go-version: '1.22.4' id: go - name: Check out code into the Go module directory diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b0e0c8b..6e97695 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.21.4' + go-version: '1.22.4' - name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 diff --git a/.golangci.json b/.golangci.json index b7806c7..b498eab 100644 --- a/.golangci.json +++ b/.golangci.json @@ -7,8 +7,6 @@ "bodyclose", "wsl", "funlen", - "maligned", - "exhaustivestruct", "gci", "wrapcheck", "varnamelen", @@ -18,20 +16,14 @@ "thelper", "paralleltest", "tagliatelle", - "scopelint", - "golint", - "interfacer", "nonamedreturns", "exhaustruct", "nolintlint", - "deadcode", "wastedassign", - "structcheck", - "varcheck", - "ifshort", - "nosnakecase", "rowserrcheck", - "depguard" + "depguard", + "mnd", + "execinquery" ] }, "linters-settings": { diff --git a/Dockerfile b/Dockerfile index 887b636..d8568b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -ARG GOLANG_DOCKER_TAG=1.21.4-alpine3.18 -ARG ALPINE_DOCKER_TAG=3.18 +ARG GOLANG_DOCKER_TAG=1.22.4-alpine3.19 +ARG ALPINE_DOCKER_TAG=3.19 FROM golang:$GOLANG_DOCKER_TAG as builder diff --git a/Makefile b/Makefile index aef8c9e..0669abe 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -GOLANG_CI_LINT_VER:=v1.53.2 +GOLANG_CI_LINT_VER:=v1.59.1 OUT_BIN?=${PWD}/bin/gherkingen COVER_PACKAGES=./... VERSION?=${shell git describe --tags} @@ -11,8 +11,8 @@ build: cmd/gherkingen/main.go .PHONY: build -lint: bin/golangci-lint - ./bin/golangci-lint run +lint: bin/golangci-lint-${GOLANG_CI_LINT_VER} + ./bin/golangci-lint-${GOLANG_CI_LINT_VER} run .PHONY: lint test: @@ -37,8 +37,9 @@ vendor: go mod vendor .PHONY: vendor -bin/golangci-lint: +bin/golangci-lint-${GOLANG_CI_LINT_VER}: curl \ -sSfL \ https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \ | sh -s $(GOLANG_CI_LINT_VER) + mv ./bin/golangci-lint ./bin/golangci-lint-${GOLANG_CI_LINT_VER} diff --git a/go.mod b/go.mod index d8468b5..3ae368d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hedhyw/gherkingen/v3 -go 1.20 +go 1.22 require ( github.com/cucumber/common/gherkin/go/v24 v24.1.0 diff --git a/go.sum b/go.sum index 9421088..6f23f3a 100644 --- a/go.sum +++ b/go.sum @@ -16,11 +16,13 @@ github.com/hedhyw/semerr v0.6.7/go.mod h1:GqxYzQ0igy0bi6pc0e38FScn9rQk1n4l+PuVKl github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 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/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= 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/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -29,6 +31,7 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 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/internal/app/app_test.go b/internal/app/app_test.go index 51bc464..ff84a93 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -33,8 +33,6 @@ func TestApplicationCommandLineTool(t *testing.T) { } for name, testCase := range testCases { - testCase := testCase - t.Run(name, func(t *testing.T) { t.Parallel() @@ -62,7 +60,6 @@ func TestApplicationCommandLineTool(t *testing.T) { } for name, testCase := range testCases { - testCase := testCase t.Run(name, func(t *testing.T) { t.Parallel() @@ -87,8 +84,6 @@ func TestApplicationCommandLineTool(t *testing.T) { } for name, testCase := range testCases { - testCase := testCase - t.Run(name, func(t *testing.T) { t.Parallel() @@ -114,7 +109,6 @@ func TestApplicationCommandLineTool(t *testing.T) { } for name, testCase := range testCases { - testCase := testCase t.Run(name, func(t *testing.T) { t.Parallel() @@ -147,8 +141,6 @@ func TestApplicationCommandLineToolCustom(t *testing.T) { } for name, testCase := range testCases { - testCase := testCase - t.Run(name, func(t *testing.T) { t.Parallel() @@ -177,8 +169,6 @@ func TestApplicationCommandLineToolCustom(t *testing.T) { } for name, testCase := range testCases { - testCase := testCase - t.Run(name, func(t *testing.T) { t.Parallel() @@ -205,8 +195,6 @@ func TestApplicationCommandLineToolCustom(t *testing.T) { } for name, testCase := range testCases { - testCase := testCase - t.Run(name, func(t *testing.T) { t.Parallel() @@ -263,8 +251,6 @@ func TestApplicationCommandLineToolFailures(t *testing.T) { } for name, testCase := range testCases { - testCase := testCase - t.Run(name, func(t *testing.T) { t.Parallel() diff --git a/internal/assets/assets_test.go b/internal/assets/assets_test.go index 7adc1f2..153d1da 100644 --- a/internal/assets/assets_test.go +++ b/internal/assets/assets_test.go @@ -28,8 +28,6 @@ func TestOpenTemplate(t *testing.T) { } for _, f := range files { - f := f - t.Run(f, func(t *testing.T) { t.Parallel() diff --git a/internal/docplugin/goplugin/goaliaser/goaliaser_test.go b/internal/docplugin/goplugin/goaliaser/goaliaser_test.go index 3af5146..2049c7b 100644 --- a/internal/docplugin/goplugin/goaliaser/goaliaser_test.go +++ b/internal/docplugin/goplugin/goaliaser/goaliaser_test.go @@ -33,14 +33,12 @@ func TestStringValue(t *testing.T) { p := goaliaser.New() - for i, tc := range testCases { - i, tc := i, tc - - t.Run(tc.In, func(t *testing.T) { + for i, testCase := range testCases { + t.Run(testCase.In, func(t *testing.T) { t.Parallel() - got := p.StringValue(tc.In) - assert.Equal(t, tc.Exp, got, i) + got := p.StringValue(testCase.In) + assert.Equal(t, testCase.Exp, got, i) }) } } @@ -200,8 +198,6 @@ func TestNameAlias(t *testing.T) { p := goaliaser.New() for i, tc := range testCases { - i, tc := i, tc - t.Run(tc.In, func(t *testing.T) { t.Parallel() diff --git a/internal/docplugin/goplugin/goplugin.go b/internal/docplugin/goplugin/goplugin.go index e2f1815..bf67e65 100644 --- a/internal/docplugin/goplugin/goplugin.go +++ b/internal/docplugin/goplugin/goplugin.go @@ -100,7 +100,7 @@ func (p GoPlugin) walkStruct( return fmt.Errorf("handling struct: %s: %w", rt.Name(), err) } - for i := 0; i < rt.NumField(); i++ { + for i := range rt.NumField() { if !rv.Field(i).CanInterface() { continue } @@ -121,7 +121,7 @@ func (p GoPlugin) walkSlice( ) (err error) { rt := rv.Type() - for i := 0; i < rv.Len(); i++ { + for i := range rv.Len() { el := rv.Index(i) if !el.CanInterface() { diff --git a/internal/docplugin/goplugin/goplugin_test.go b/internal/docplugin/goplugin/goplugin_test.go index c7e7622..6ed28d3 100644 --- a/internal/docplugin/goplugin/goplugin_test.go +++ b/internal/docplugin/goplugin/goplugin_test.go @@ -181,7 +181,7 @@ func TestExample(t *testing.T) { examples := make([]*model.TableRow, 0, count) - for i := 0; i < count; i++ { + for range count { examples = append(examples, &model.TableRow{ Cells: []*model.TableCell{{ Value: "hello_world", @@ -449,21 +449,19 @@ func TestParallel(t *testing.T) { ctx := context.Background() - for _, tc := range [2]bool{true, false} { - tc := tc - - t.Run(strconv.FormatBool(tc), func(t *testing.T) { + for _, testCase := range [2]bool{true, false} { + t.Run(strconv.FormatBool(testCase), func(t *testing.T) { t.Parallel() p := goplugin.New(goplugin.Args{ - Parallel: tc, + Parallel: testCase, }) doc := getExampleDocument() if assert.NoError(t, p.Process(ctx, doc)) { - assert.Equal(t, tc, doc.Feature.PluginData["GoParallel"]) - assert.Equal(t, tc, doc.Feature.Children[0].Scenario.PluginData["GoParallel"]) - assert.Equal(t, tc, doc.Feature.Children[0].Rule.PluginData["GoParallel"]) + assert.Equal(t, testCase, doc.Feature.PluginData["GoParallel"]) + assert.Equal(t, testCase, doc.Feature.Children[0].Scenario.PluginData["GoParallel"]) + assert.Equal(t, testCase, doc.Feature.Children[0].Rule.PluginData["GoParallel"]) } }) } diff --git a/internal/docplugin/goplugin/gotype_test.go b/internal/docplugin/goplugin/gotype_test.go index f8ee13b..7ecd8fc 100644 --- a/internal/docplugin/goplugin/gotype_test.go +++ b/internal/docplugin/goplugin/gotype_test.go @@ -50,14 +50,12 @@ func TestDeterminateGoType(t *testing.T) { Exp: goTypeString, }} - for i, tc := range testCases { - i, tc := i, tc - - t.Run(strings.Join(tc.In, "_"), func(t *testing.T) { + for i, testCase := range testCases { + t.Run(strings.Join(testCase.In, "_"), func(t *testing.T) { t.Parallel() - got := determinateGoType(tc.In) - assert.Equal(t, tc.Exp, got, i) + got := determinateGoType(testCase.In) + assert.Equal(t, testCase.Exp, got, i) }) } } @@ -123,19 +121,17 @@ func TestGoValue(t *testing.T) { ExpGoType: goTypeFloat64, }} - for i, tc := range testCases { - i, tc := i, tc - - t.Run(string(tc.InGoType)+"_"+tc.In, func(t *testing.T) { + for i, testCase := range testCases { + t.Run(string(testCase.InGoType)+"_"+testCase.In, func(t *testing.T) { t.Parallel() - gotVal, gotType := goValue(goaliaser.New(), tc.In, tc.InGoType) - if gotVal != tc.Exp { - t.Errorf("%d:\n\tin: %s\n\texp: %s\n\tgot: %s", i, tc.In, tc.Exp, gotVal) + gotVal, gotType := goValue(goaliaser.New(), testCase.In, testCase.InGoType) + if gotVal != testCase.Exp { + t.Errorf("%d:\n\tin: %s\n\texp: %s\n\tgot: %s", i, testCase.In, testCase.Exp, gotVal) } - if gotType != tc.ExpGoType { - t.Errorf("%d:\n\tin: %s\n\texp: %s\n\tgot: %s", i, tc.In, tc.ExpGoType, gotType) + if gotType != testCase.ExpGoType { + t.Errorf("%d:\n\tin: %s\n\texp: %s\n\tgot: %s", i, testCase.In, testCase.ExpGoType, gotType) } }) } diff --git a/internal/generator/generator_test.go b/internal/generator/generator_test.go index 5b2fae2..37bb0cf 100644 --- a/internal/generator/generator_test.go +++ b/internal/generator/generator_test.go @@ -24,7 +24,7 @@ func TestGenerateFailed(t *testing.T) { }{{ OK: true, Name: "ok", - Prepare: func(args *generator.Args) {}, + Prepare: func(*generator.Args) {}, }, { OK: false, Name: "invalid_format", @@ -50,10 +50,8 @@ func TestGenerateFailed(t *testing.T) { }, }} - for _, tc := range testCases { - tc := tc - - t.Run(tc.Name, func(t *testing.T) { + for _, testCase := range testCases { + t.Run(testCase.Name, func(t *testing.T) { t.Parallel() args := generator.Args{ @@ -65,10 +63,10 @@ func TestGenerateFailed(t *testing.T) { GenerateUUID: uuid.NewString, } - tc.Prepare(&args) + testCase.Prepare(&args) _, err := generator.Generate(args) - if tc.OK { + if testCase.OK { assert.NoError(t, err) } else { assert.Error(t, err) diff --git a/internal/generator/golang_test.go b/internal/generator/golang_test.go index 3c9650b..55cc621 100644 --- a/internal/generator/golang_test.go +++ b/internal/generator/golang_test.go @@ -60,8 +60,6 @@ func TestGenerateAssetTemplatesShouldNotFail(t *testing.T) { require.NoError(t, err) for _, tmpl := range templates { - tmpl := tmpl - t.Run(tmpl, func(t *testing.T) { t.Parallel() diff --git a/internal/generator/raw_test.go b/internal/generator/raw_test.go index 9b483b9..57a3a42 100644 --- a/internal/generator/raw_test.go +++ b/internal/generator/raw_test.go @@ -108,22 +108,20 @@ func TestGenerateRaw(t *testing.T) { }, } - for _, tc := range testCases { - tc := tc - - t.Run(tc.Template, func(t *testing.T) { + for _, testCase := range testCases { + t.Run(testCase.Template, func(t *testing.T) { t.Parallel() gotDataRaw, err := generator.Generate(generator.Args{ Format: model.FormatRaw, InputSource: exampleFeature, - TemplateSource: []byte(tc.Template), + TemplateSource: []byte(testCase.Template), PackageName: "generated_test.go", Plugin: requireNewPlugin(t), GenerateUUID: uuid.NewString, }) if assert.NoError(t, err) { - assert.Equal(t, tc.Exp, string(gotDataRaw)) + assert.Equal(t, testCase.Exp, string(gotDataRaw)) } }) } diff --git a/internal/model/document_test.go b/internal/model/document_test.go index 4a674da..637162f 100644 --- a/internal/model/document_test.go +++ b/internal/model/document_test.go @@ -405,13 +405,11 @@ func TestGherkinDocumentFromNil(t *testing.T) { func() any { return (&model.Location{}).From(nil) }, } - for i, tc := range testCases { - tc := tc - + for i, testCase := range testCases { t.Run(strconv.Itoa(i), func(t *testing.T) { t.Parallel() - assert.Nil(t, tc()) + assert.Nil(t, testCase()) }) } } diff --git a/pkg/bdd/bdd.go b/pkg/bdd/bdd.go index 368169b..e9abcd5 100644 --- a/pkg/bdd/bdd.go +++ b/pkg/bdd/bdd.go @@ -277,7 +277,7 @@ func prepareReplacer(tb testing.TB, testCase interface{}) *strings.Replacer { count := rt.NumField() replaceArgs := make([]string, 0, count*2) - for i := 0; i < count; i++ { + for i := range count { if !rv.Field(i).CanInterface() { continue }