diff --git a/.github/workflows/lint-go.yml b/.github/workflows/lint-go.yml index b99c87f..4e0b98b 100644 --- a/.github/workflows/lint-go.yml +++ b/.github/workflows/lint-go.yml @@ -13,7 +13,18 @@ on: jobs: code-linter: name: "Run golangci-lint" - uses: kyma-project/eventing-tools/.github/workflows/lint-go-reusable.yml@main - with: - go-version: '1.21' - lint-config-uri: https://raw.githubusercontent.com/kyma-project/eventing-tools/a9cc2c5524838736f3f8fd084021a0116675476d/config/lint/.golangci.yaml + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: golangci-lint + uses: golangci/golangci-lint-action@v4.0.0 + with: + version: v1.57 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9203068..c39e828 100755 --- a/.gitignore +++ b/.gitignore @@ -45,5 +45,3 @@ vendor/ # Lint files lint-report.json -.golangci.yaml - diff --git a/Makefile b/Makefile index b6ff91e..6c12af4 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ DIRS_TO_CHECK = go list ./... | grep -v "$(VERIFY_IGNORE)" # DIRS_TO_IGNORE is a command used to determine which directories should not be verified DIRS_TO_IGNORE = go list ./... | grep "$(VERIFY_IGNORE)" +GOLANG_CI_LINT_VERSION ?= v1.57 ##@ General # The help target prints out all targets with their descriptions organized @@ -42,21 +43,29 @@ help: ## Display this help. ##@ Development -.PHONY: lint -lint: ## Check lint issues using `golangci-lint` - golangci-lint run --timeout 5m --config=./.golangci.yaml +## Location to install dependencies to +LOCALBIN ?= $(shell pwd)/bin +$(LOCALBIN): + mkdir -p $(LOCALBIN) + +golangci_lint: + test -s $(LOCALBIN)/golangci-lint && $(LOCALBIN)/golangci-lint version | grep -q $(GOLANG_CI_LINT_VERSION) || \ + GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANG_CI_LINT_VERSION) + +lint: golangci_lint + $(LOCALBIN)/golangci-lint run .PHONY: lint-compact -lint-compact: ## Check lint issues using `golangci-lint` in compact result format - golangci-lint run --timeout 5m --config=./.golangci.yaml --print-issued-lines=false +lint-compact: golangci_lint ## Check lint issues using `golangci-lint` in compact result format + $(LOCALBIN)/golangci-lint run --print-issued-lines=false .PHONY: lint-fix -lint-fix: ## Check and fix lint issues using `golangci-lint` - golangci-lint run --fix --timeout 5m --config=./.golangci.yaml +lint-fix: golangci_lint + $(LOCALBIN)/golangci-lint run --fix .PHONY: lint-report -lint-report: ## Check lint issues using `golangci-lint` then export them to a file, then print the list of linters used - golangci-lint run --timeout 5m --config=./.golangci.yaml --issues-exit-code 0 --out-format json > ./lint-report.json +lint-report: golangci_lint + $(LOCALBIN)/golangci-lint run --issues-exit-code 0 --out-format json > ./lint-report.json .PHONY: lint-report-issue-category lint-report-issue-category: ## Get lint issues categories diff --git a/pkg/cloudevents/builder/eventmesh_test.go b/pkg/cloudevents/builder/eventmesh_test.go index f22ede8..55e0a1b 100644 --- a/pkg/cloudevents/builder/eventmesh_test.go +++ b/pkg/cloudevents/builder/eventmesh_test.go @@ -3,7 +3,6 @@ package builder import ( "context" "encoding/json" - "fmt" log "log" "testing" @@ -45,7 +44,7 @@ func Test_EventMesh_Build(t *testing.T) { givenSource: "source1", givenType: "order.created.v1", givenApplicationName: "appName1", - wantType: fmt.Sprintf("%s.source1.order.created.v1", eventMeshPrefix), + wantType: eventMeshPrefix + ".source1.order.created.v1", wantSource: sampleEventMeshNamespace, }, { @@ -53,7 +52,7 @@ func Test_EventMesh_Build(t *testing.T) { givenSource: "source1", givenType: "o-rder.creat ed.v1", givenApplicationName: "appName1", - wantType: fmt.Sprintf("%s.source1.order.created.v1", eventMeshPrefix), + wantType: eventMeshPrefix + ".source1.order.created.v1", wantSource: sampleEventMeshNamespace, }, { @@ -61,7 +60,7 @@ func Test_EventMesh_Build(t *testing.T) { givenSource: "source1", givenType: "haha.hehe.hmm.order.created.v1", givenApplicationName: "appName1", - wantType: fmt.Sprintf("%s.source1.hahahehehmmorder.created.v1", eventMeshPrefix), + wantType: eventMeshPrefix + ".source1.hahahehehmmorder.created.v1", wantSource: sampleEventMeshNamespace, }, { @@ -69,7 +68,7 @@ func Test_EventMesh_Build(t *testing.T) { givenSource: "appName1", givenType: "order.created.v1", givenApplicationName: "appName1", - wantType: fmt.Sprintf("%s.appName1.order.created.v1", eventMeshPrefix), + wantType: eventMeshPrefix + ".appName1.order.created.v1", wantSource: sampleEventMeshNamespace, }, { @@ -78,7 +77,7 @@ func Test_EventMesh_Build(t *testing.T) { givenType: "order.created.v1", givenApplicationName: "appName1", givenApplicationLabels: map[string]string{application.TypeLabel: "t..e--s__t!!a@@p##p%%t^^y&&p**e"}, - wantType: fmt.Sprintf("%s.testapptype.order.created.v1", eventMeshPrefix), + wantType: eventMeshPrefix + ".testapptype.order.created.v1", wantSource: sampleEventMeshNamespace, }, { diff --git a/pkg/cloudevents/builder/generic.go b/pkg/cloudevents/builder/generic.go index ea7292c..3ea6d4b 100644 --- a/pkg/cloudevents/builder/generic.go +++ b/pkg/cloudevents/builder/generic.go @@ -1,6 +1,7 @@ package builder import ( + "errors" "fmt" "strings" @@ -12,7 +13,7 @@ import ( "github.com/kyma-project/eventing-manager/pkg/logger" ) -var ErrEventTypeCannotHaveEmptySegments = fmt.Errorf("event type cannot have empty segments after cleaning") +var ErrEventTypeCannotHaveEmptySegments = errors.New("event type cannot have empty segments after cleaning") // Perform a compile-time check. var _ CloudEventBuilder = &GenericBuilder{} diff --git a/pkg/handler/handler_v1alpha1_test.go b/pkg/handler/handler_v1alpha1_test.go index ec6e11b..bd27ddd 100644 --- a/pkg/handler/handler_v1alpha1_test.go +++ b/pkg/handler/handler_v1alpha1_test.go @@ -34,7 +34,7 @@ import ( emlogger "github.com/kyma-project/eventing-manager/pkg/logger" ) -var ErrUnableToClean = fmt.Errorf("unable to clean") +var ErrUnableToClean = errors.New("unable to clean") func Test_extractCloudEventFromRequest(t *testing.T) { type args struct { @@ -55,7 +55,7 @@ func Test_extractCloudEventFromRequest(t *testing.T) { args: args{ request: CreateValidStructuredRequestV1Alpha1(t), }, - wantType: fmt.Sprintf("sap.kyma.custom.%s", epptestingutils.CloudEventType), + wantType: "sap.kyma.custom." + epptestingutils.CloudEventType, wants: wants{ event: CreateCloudEvent(t), errorAssertionFunc: assert.NoError, @@ -86,7 +86,7 @@ func Test_extractCloudEventFromRequest(t *testing.T) { args: args{ request: CreateValidBinaryRequestV1Alpha1(t), }, - wantType: fmt.Sprintf("sap.kyma.custom.%s", epptestingutils.CloudEventType), + wantType: "sap.kyma.custom." + epptestingutils.CloudEventType, wants: wants{ event: CreateCloudEvent(t), errorAssertionFunc: assert.NoError, diff --git a/pkg/legacy/legacy_test.go b/pkg/legacy/legacy_test.go index af20792..2e83f26 100644 --- a/pkg/legacy/legacy_test.go +++ b/pkg/legacy/legacy_test.go @@ -2,7 +2,6 @@ package legacy import ( "context" - "fmt" "net/http" "net/http/httptest" "testing" @@ -252,7 +251,7 @@ func TestRemoveNonAlphanumeric(t *testing.T) { } for _, tc := range testCases { tc := tc - t.Run(fmt.Sprintf("%s eventType", tc.name), func(t *testing.T) { + t.Run(tc.name+" eventType", func(t *testing.T) { t.Parallel() gotEventType := removeNonAlphanumeric(tc.givenEventType) diff --git a/pkg/nats/connect.go b/pkg/nats/connect.go index 0d9a3b7..d7d6d6f 100644 --- a/pkg/nats/connect.go +++ b/pkg/nats/connect.go @@ -1,12 +1,13 @@ package nats import ( + "errors" "fmt" "github.com/nats-io/nats.go" ) -var ErrNATSConnectionNotConnected = fmt.Errorf("NATS connection not connected") +var ErrNATSConnectionNotConnected = errors.New("NATS connection not connected") type Opt = nats.Option diff --git a/pkg/oauth/client_test.go b/pkg/oauth/client_test.go index cff54ae..c73f3e5 100644 --- a/pkg/oauth/client_test.go +++ b/pkg/oauth/client_test.go @@ -97,7 +97,7 @@ func TestGetToken(t *testing.T) { client := NewClient(context.Background(), cfg) defer client.CloseIdleConnections() - for i := 0; i < test.requestsCount; i++ { + for range test.requestsCount { req, err := http.NewRequest(http.MethodPost, emsCEURL, nil) if err != nil { t.Errorf("Failed to create HTTP request with error: %v", err) diff --git a/pkg/sender/jetstream/jetstream_test.go b/pkg/sender/jetstream/jetstream_test.go index 49b0c16..7a79ab7 100644 --- a/pkg/sender/jetstream/jetstream_test.go +++ b/pkg/sender/jetstream/jetstream_test.go @@ -160,7 +160,7 @@ func createCloudEvent(t *testing.T) *event.Event { func getStreamConfig(maxBytes int64) *natsgo.StreamConfig { return &natsgo.StreamConfig{ Name: epptestingutils.StreamName, - Subjects: []string{fmt.Sprintf("%s.>", env.JetStreamSubjectPrefix)}, + Subjects: []string{env.JetStreamSubjectPrefix + ".>"}, Storage: natsgo.MemoryStorage, Retention: natsgo.InterestPolicy, Discard: natsgo.DiscardNew, diff --git a/pkg/subscribed/helpers.go b/pkg/subscribed/helpers.go index ba0ff0b..87e79ef 100644 --- a/pkg/subscribed/helpers.go +++ b/pkg/subscribed/helpers.go @@ -185,7 +185,7 @@ func FilterEventTypeVersionsV1alpha1(eventTypePrefix, bebNs, appName string, func preparePrefix(eventTypePrefix string, appName string) string { if len(strings.TrimSpace(eventTypePrefix)) == 0 { - return strings.ToLower(fmt.Sprintf("%s.", appName)) + return strings.ToLower(appName + ".") } return strings.ToLower(fmt.Sprintf("%s.%s.", eventTypePrefix, appName)) }