Skip to content

Commit

Permalink
chore: update lint configuration (#105)
Browse files Browse the repository at this point in the history
* switch to local lint config and update to 1.57

* use go version from go.mod
  • Loading branch information
k15r authored Apr 16, 2024
1 parent bb4b32d commit 78446cc
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 32 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
version: v1.57
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup go environment
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version-file: go.mod
cache: false

- name: Sync go dependencies
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,3 @@ vendor/

# Lint files
lint-report.json
.golangci.yaml

27 changes: 18 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions pkg/cloudevents/builder/eventmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package builder
import (
"context"
"encoding/json"
"fmt"
log "log"
"testing"

Expand Down Expand Up @@ -45,31 +44,31 @@ 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,
},
{
name: "should return cleaned source and type (without application)",
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,
},
{
name: "should return merged type segments if exceeds segments limit",
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,
},
{
name: "should return application name as source",
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,
},
{
Expand All @@ -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,
},
{
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloudevents/builder/generic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package builder

import (
"errors"
"fmt"
"strings"

Expand All @@ -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{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/handler/handler_v1alpha1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions pkg/legacy/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package legacy

import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/nats/connect.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion pkg/oauth/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sender/jetstream/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/subscribed/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 78446cc

Please sign in to comment.