From a8d414f85c6816952c7ba1ad996027f301cf245b Mon Sep 17 00:00:00 2001 From: Luigi Operoso <40476330+brokenpip3@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:44:32 +0000 Subject: [PATCH] fix golangci-lint --- .golangci.yml | 62 ++++++++++++++--------------- Makefile | 8 +++- pkg/client/jenkins.go | 6 ++- pkg/notifications/smtp/smtp_test.go | 2 +- 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5e73bbde..3118979a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,39 +1,37 @@ run: deadline: 10m + allow-parallel-runners: true skip-files: - api/v1alpha2/zz_generated.deepcopy.go -linters-settings: - errcheck: - check-blank: false - ignore: fmt:.*,io/ioutil:^Read.*,Write +issues: + exclude-use-default: false + exclude-rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll linters: - enable-all: true - disable: - - funlen - - gocognit - - godox - - gomnd - - gochecknoglobals - - gochecknoinits - - lll - - prealloc - - wsl - - gocyclo - - scopelint + disable-all: true + enable: - dupl - - gosec - - maligned - - testpackage - - goerr113 + - errcheck + - exportloopref + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - lll + - misspell - nakedret - - nestif - - godot - - ifshort - - structcheck - - deadcode - - golint - - nosnakecase - - exhaustivestruct - - varcheck - - interfacer - + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused diff --git a/Makefile b/Makefile index f21fc29c..c711c8b8 100644 --- a/Makefile +++ b/Makefile @@ -70,10 +70,14 @@ HAS_GOLINT := $(shell which $(PROJECT_DIR)/bin/golangci-lint) lint: ## Verifies `golint` passes @echo "+ $@" ifndef HAS_GOLINT - GOBIN=$(PROJECT_DIR)/bin go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2 + GOBIN=$(PROJECT_DIR)/bin go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2 endif @bin/golangci-lint run +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + @bin/golangci-lint run --fix + .PHONY: goimports HAS_GOIMPORTS := $(shell which $(PROJECT_DIR)/bin/goimports) goimports: ## Verifies `goimports` passes @@ -371,7 +375,7 @@ kind-clean: ## Delete kind cluster IMAGE_NAME := quay.io/$(QUAY_ORGANIZATION)/$(QUAY_REGISTRY):$(GITCOMMIT)-amd64 BUILD_PRESENT := $(shell docker images |grep -q ${IMAGE_NAME}) ifndef BUILD_PRESENT -bats-tests: container-runtime-build-amd64 ## Run bats tests +bats-tests: container-runtime-build-amd64 kind-setup ## Run bats tests @echo "+ $@" kind load docker-image ${IMAGE_NAME} --name $(KIND_CLUSTER_NAME) OPERATOR_IMAGE="${IMAGE_NAME}" TERM=xterm bats -T -p test/bats diff --git a/pkg/client/jenkins.go b/pkg/client/jenkins.go index d0738d0b..ca929588 100644 --- a/pkg/client/jenkins.go +++ b/pkg/client/jenkins.go @@ -202,7 +202,11 @@ func (jenkins *jenkins) GetNodeSecret(name string) (string, error) { if err != nil { return "", errors.WithStack(err) } - defer r.Body.Close() + defer func() { + if err := r.Body.Close(); err != nil { + errors.New("Failed to read response body") + } + }() match := regex.FindStringSubmatch(content) if match == nil { diff --git a/pkg/notifications/smtp/smtp_test.go b/pkg/notifications/smtp/smtp_test.go index c0cf9bd3..d42035d4 100644 --- a/pkg/notifications/smtp/smtp_test.go +++ b/pkg/notifications/smtp/smtp_test.go @@ -92,7 +92,7 @@ func (s *testSession) Data(r io.Reader) error { contentRegex := regexp.MustCompile(`\t+\n\t+(.*):\n\t+(.*)\n\t+`) headersRegex := regexp.MustCompile(`(.*):\s(.*)`) - b, err := ioutil.ReadAll(quotedprintable.NewReader(r)) + b, err := io.ReadAll(quotedprintable.NewReader(r)) if err != nil { return err }