From f7380246d6ed61c335fa11fd30150980cf4323f9 Mon Sep 17 00:00:00 2001 From: elmiko Date: Tue, 15 Oct 2024 12:03:22 -0400 Subject: [PATCH] update goimports targets This change removes the old goimports command execution in favor of using the golangci-lint configuration to include goimports. The fmt target is also updated to use the normal `go fmt` command. --- .golangci.yaml | 13 +++++++++++++ Makefile | 4 ++-- hack/goimports.sh | 22 ---------------------- 3 files changed, 15 insertions(+), 24 deletions(-) create mode 100644 .golangci.yaml delete mode 100755 hack/goimports.sh diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 000000000..7f1373979 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,13 @@ +linters: + # https://golangci-lint.run/usage/linters/#enabled-by-default-linters + enable: + # default linters + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - unused + # optional linters + - goimports + diff --git a/Makefile b/Makefile index c922ea906..0b32cd0a6 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ manifests: # Run go fmt against code .PHONY: fmt fmt: - hack/goimports.sh + go fmt ./... # Run go vet against code .PHONY: vet @@ -69,7 +69,7 @@ vet: # Run golangci-lint against code .PHONY: lint lint: - ( GOLANGCI_LINT_CACHE=$(PROJECT_DIR)/.cache $(GOLANGCI_LINT) run --timeout 10m ) + ( GOLANGCI_LINT_CACHE=$(PROJECT_DIR)/.cache $(GOLANGCI_LINT) run --timeout 10m -v) # Run go mod .PHONY: vendor diff --git a/hack/goimports.sh b/hack/goimports.sh deleted file mode 100755 index 132cc91ad..000000000 --- a/hack/goimports.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o pipefail - -REPO_ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")/..") - -function runGoimports() { - local GOIMPORTS_PATH=$REPO_ROOT/bin/goimports - GOBIN="$REPO_ROOT"/bin go install -mod=readonly golang.org/x/tools/cmd/goimports@latest - - local LOCAL_PACKAGE="github.com/openshift/cluster-cloud-controller-manager-operator" - local GOIMPORTS_ARGS=("-local $LOCAL_PACKAGE -w $REPO_ROOT/cmd $REPO_ROOT/pkg") - - if [[ $# -ne 0 ]] ; then - GOIMPORTS_ARGS="$@" - fi - echo "Run goimports:" - (set -x; $GOIMPORTS_PATH $GOIMPORTS_ARGS) -} - -runGoimports "$@"