diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 4463702f..2145f0cf 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -16,6 +16,4 @@ jobs: uses: reviewdog/action-golangci-lint@v2 with: reviewdog_flags: '-conf=.reviewdog.yml -diff="git diff main"' - golangci_lint_version: v1.52.2 - - name: looppointer - run: make lint/looppointer + golangci_lint_version: v1.61.0 diff --git a/.golangci.yml b/.golangci.yml index 5c5f3b42..d4954dbb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,25 +5,27 @@ linters: enable-all: true disable: - containedctx + - contextcheck + - depguard - dupl + - err113 - exhaustive + - exhaustruct - funlen - gci - gochecknoglobals - gochecknoinits - gocognit - godox - - goerr113 - - gomnd - - ifshort + - interfacebloat - ireturn - lll + - mnd - nestif - nlreturn - - nosnakecase - paralleltest + - perfsprint - prealloc - - scopelint - testpackage - tparallel - unparam @@ -31,20 +33,33 @@ linters: - wrapcheck - wsl - # deplicated - - deadcode - - exhaustivestruct - - golint - - interfacer - - maligned - - scopelint - - structcheck - - varcheck + # deprecated + - execinquery + - exportloopref + - gomnd # disabled because of generics - rowserrcheck - wastedassign + # TODO: fix + - copyloopvar + - cyclop + - errcheck + - forbidigo + - goconst + - gocyclo + - govet + - inamedparam + - intrange + - maintidx + - nilnil + - predeclared + - revive + - staticcheck + - stylecheck + - tagliatelle + skip-dirs: - gen @@ -85,6 +100,9 @@ linters-settings: - 'github\.com/zoncoen/scenarigo/template/ast\..+$' - 'github\.com/zoncoen/scenarigo/template/parser\..+$' - 'github\.com/zoncoen/scenarigo/template\.Template$' + gosec: + excludes: + - G115 maintidx: under: 30 stylecheck: diff --git a/Makefile b/Makefile index 2c3f2861..d6859025 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ $(GOCREDITS): | $(BIN_DIR) @$(GO) install github.com/Songmu/gocredits/cmd/gocredits@v0.3.0 GOLANGCI_LINT := $(BIN_DIR)/golangci-lint -GOLANGCI_LINT_VERSION := 1.57.2 +GOLANGCI_LINT_VERSION := 1.61.0 GOLANGCI_LINT_OS_ARCH := $(shell echo golangci-lint-$(GOLANGCI_LINT_VERSION)-$(GOOS)-$(GOARCH)) GOLANGCI_LINT_GZIP := $(GOLANGCI_LINT_OS_ARCH).tar.gz $(GOLANGCI_LINT): | $(BIN_DIR) @@ -78,10 +78,6 @@ $(GOLANGCI_LINT): | $(BIN_DIR) @tar -C $(BIN_DIR) --strip=1 -xf $(GOLANGCI_LINT_GZIP) $(GOLANGCI_LINT_OS_ARCH)/golangci-lint @rm $(GOLANGCI_LINT_GZIP) -LOOPPOINTER := $(BIN_DIR)/looppointer -$(LOOPPOINTER): | $(BIN_DIR) - @$(GO) install github.com/kyoh86/looppointer/cmd/looppointer@v0.2.1 - .PHONY: build build: | $(BIN_DIR) @$(GO) install ./cmd/scenarigo @@ -146,11 +142,6 @@ test/examples/%: .PHONY: lint lint: $(GOLANGCI_LINT) $(LOOPPOINTER) ## run lint @$(GOLANGCI_LINT) run - @make lint/looppointer - -.PHONY: lint/looppointer -lint/looppointer: $(LOOPPOINTER) - @$(GO) vet -vettool=$(LOOPPOINTER) ./... .PHONY: lint/fix lint/fix: $(GOLANGCI_LINT) $(LOOPPOINTER) ## fix lint errors diff --git a/cmd/scenarigo/cmd/plugin/build.go b/cmd/scenarigo/cmd/plugin/build.go index e64dc149..9d84312a 100644 --- a/cmd/scenarigo/cmd/plugin/build.go +++ b/cmd/scenarigo/cmd/plugin/build.go @@ -626,7 +626,6 @@ func (pb *pluginBuilder) updateReplaceDirectives(cmd *cobra.Command, goCmd strin reason: fmt.Sprintf("change the replaced old version of %s from %s to %s", o.replace.Old.Path, o.replace.Old.Version, v.Old.Version), } } - } if replace != nil { if v, ok := requires[replace.Old.Path]; ok { diff --git a/cmd/scenarigo/cmd/plugin/build_test.go b/cmd/scenarigo/cmd/plugin/build_test.go index 90cfd97d..44a5fc96 100644 --- a/cmd/scenarigo/cmd/plugin/build_test.go +++ b/cmd/scenarigo/cmd/plugin/build_test.go @@ -2220,7 +2220,7 @@ func create(t *testing.T, path, content string) { t.Fatalf("failed to create %s: %s", path, err) } defer f.Close() - if _, err := f.Write([]byte(content)); err != nil { + if _, err := f.WriteString(content); err != nil { t.Fatalf("failed to write %s: %s", path, err) } } @@ -2236,7 +2236,7 @@ func createExecutable(t *testing.T, path, stdout string) { t.Fatalf("failed to create %s: %s", path, err) } defer f.Close() - if _, err := f.Write([]byte(fmt.Sprintf("#!%s\n%s %q", bash, echo, stdout))); err != nil { + if _, err := f.WriteString(fmt.Sprintf("#!%s\n%s %q", bash, echo, stdout)); err != nil { t.Fatalf("failed to write %s: %s", path, err) } } diff --git a/internal/reflectutil/struct_test.go b/internal/reflectutil/struct_test.go index 36405115..150a5bf9 100644 --- a/internal/reflectutil/struct_test.go +++ b/internal/reflectutil/struct_test.go @@ -45,7 +45,7 @@ func getField(t *testing.T, v reflect.Value, name string) reflect.StructField { } type testStruct struct { - YAML string `yaml:"yamltag" json:"jsontag"` + YAML string `json:"jsontag" yaml:"yamltag"` JSON string `json:"jsontag"` Name string } diff --git a/mock/protocol/grpc/handler_test.go b/mock/protocol/grpc/handler_test.go index e8a6b325..0f36e492 100644 --- a/mock/protocol/grpc/handler_test.go +++ b/mock/protocol/grpc/handler_test.go @@ -22,7 +22,7 @@ func TestUnaryHandler_failure(t *testing.T) { svcName := protoreflect.FullName("scenarigo.testdata.test.Test") sd, err := fds.ResolveService(svcName) if err != nil { - t.Fatalf("failed to resovle service: %s", err) + t.Fatalf("failed to resolve service: %s", err) } md := sd.Methods().ByName("Echo") @@ -139,7 +139,7 @@ func TestUnaryHandler_failure(t *testing.T) { decode: func(_ any) error { return nil }, expect: ".response.message: failed to execute template of response", }, - "invalid reponse status code": { + "invalid response status code": { mocks: []protocol.Mock{ { Protocol: "grpc", @@ -152,7 +152,7 @@ func TestUnaryHandler_failure(t *testing.T) { decode: func(_ any) error { return nil }, expect: ".response.status.code: invalid status code", }, - "invalid reponse message": { + "invalid response message": { mocks: []protocol.Mock{ { Protocol: "grpc", diff --git a/protocol/grpc/grpc_test.go b/protocol/grpc/grpc_test.go index dde02c9f..b780ec3a 100644 --- a/protocol/grpc/grpc_test.go +++ b/protocol/grpc/grpc_test.go @@ -194,9 +194,9 @@ func (*OneofMessage_A_) isOneofMessage_Value() {} func (*OneofMessage_B_) isOneofMessage_Value() {} type OneofMessage_A struct { - FooValue string `protobuf:"bytes,1,opt,name=foo_value,json=fooValue,proto3" json:"foo_value,omitempty"` + FooValue string `json:"foo_value,omitempty" protobuf:"bytes,1,opt,name=foo_value,json=fooValue,proto3"` } type OneofMessage_B struct { - BarValue string `protobuf:"bytes,1,opt,name=bar_value,json=barValue,proto3" json:"bar_value,omitempty"` + BarValue string `json:"bar_value,omitempty" protobuf:"bytes,1,opt,name=bar_value,json=barValue,proto3"` } diff --git a/reporter/report.go b/reporter/report.go index 27328e6f..efe7163e 100644 --- a/reporter/report.go +++ b/reporter/report.go @@ -110,17 +110,17 @@ This struct can be marshalled as JUnit-like format XML. fmt.Println(b) */ type TestReport struct { - XMLName xml.Name `json:"-" xml:"testsuites"` + XMLName xml.Name `json:"-" xml:"testsuites"` Name string `json:"name,omitempty" xml:"name,attr,omitempty"` - Result TestResult `json:"result" xml:"-"` - Files []ScenarioFileReport `json:"files" xml:"testsuite"` + Result TestResult `json:"result" xml:"-"` + Files []ScenarioFileReport `json:"files" xml:"testsuite"` } // ScenarioFileReport represents a result report of a test scenario file. type ScenarioFileReport struct { - Name string `json:"name" xml:"name,attr,omitempty"` - Result TestResult `json:"result" xml:"-"` - Duration TestDuration `json:"duration" xml:"time,attr"` + Name string `json:"name" xml:"name,attr,omitempty"` + Result TestResult `json:"result" xml:"-"` + Duration TestDuration `json:"duration" xml:"time,attr"` Scenarios []ScenarioReport `json:"scenarios" xml:"testcase"` } diff --git a/schema/scenario.go b/schema/scenario.go index 578d8e1e..f0e96160 100644 --- a/schema/scenario.go +++ b/schema/scenario.go @@ -78,7 +78,7 @@ func (s *Scenario) Validate() error { // Step represents a step of scenario. type Step struct { - ID string `yaml:"id,omitempty" validate:"alphanum"` + ID string `validate:"alphanum" yaml:"id,omitempty"` Title string `yaml:"title,omitempty"` Description string `yaml:"description,omitempty"` If string `yaml:"if,omitempty"` diff --git a/test/e2e/scenario_test.go b/test/e2e/scenario_test.go index 589645ac..aab2abca 100644 --- a/test/e2e/scenario_test.go +++ b/test/e2e/scenario_test.go @@ -89,8 +89,8 @@ func (s *testGRPCServer) Echo(ctx gocontext.Context, req *test.EchoRequest) (*te return nil, sts.Err() } return &test.EchoResponse{ - MessageId: req.MessageId, - MessageBody: req.MessageBody, + MessageId: req.GetMessageId(), + MessageBody: req.GetMessageBody(), UserType: test.UserType_CUSTOMER, State: test.State_ACTIVE, }, nil