From 4f0751a976ac3a7c176d18dfba63187b0a550c84 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 21 Aug 2019 15:41:49 +0200 Subject: [PATCH 1/2] Extend makefile with 'make goimports' target So the target can be run in CI and fail in case files are not properly goimport formated. --- Makefile | 4 ++++ hack/goimports.sh | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100755 hack/goimports.sh diff --git a/Makefile b/Makefile index fc234c65ae..4b57b92f19 100644 --- a/Makefile +++ b/Makefile @@ -123,6 +123,10 @@ lint: ## Go lint your code fmt: ## Go fmt your code hack/go-fmt.sh . +.PHONY: goimports +goimports: ## Go fmt your code + hack/goimports.sh . + .PHONY: vet vet: ## Apply go vet to all go files hack/go-vet.sh ./... diff --git a/hack/goimports.sh b/hack/goimports.sh new file mode 100755 index 0000000000..3925936d9f --- /dev/null +++ b/hack/goimports.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +REPO_NAME=$(basename "${PWD}") +if [ "$IS_CONTAINER" != "" ]; then + for TARGET in "${@}"; do + find "${TARGET}" -name '*.go' ! -path '*/vendor/*' ! -path '*/.build/*' -exec goimports -w {} \+ + done + git diff --exit-code +else + docker run -it --rm \ + --env IS_CONTAINER=TRUE \ + --volume "${PWD}:/go/src/sigs.k8s.io/${REPO_NAME}:z" \ + --workdir "/go/src/sigs.k8s.io/${REPO_NAME}" \ + openshift/origin-release:golang-1.12 \ + ./hack/goimports.sh "${@}" +fi From 6b25a0463750ff310c19fc9d2b68ce1a1b21a113 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 21 Aug 2019 15:42:51 +0200 Subject: [PATCH 2/2] Run 'make goimports' --- pkg/client/mock/client_generated.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/client/mock/client_generated.go b/pkg/client/mock/client_generated.go index 11233bcb91..3314b9b9a1 100644 --- a/pkg/client/mock/client_generated.go +++ b/pkg/client/mock/client_generated.go @@ -5,11 +5,12 @@ package mock import ( + reflect "reflect" + ec2 "github.com/aws/aws-sdk-go/service/ec2" elb "github.com/aws/aws-sdk-go/service/elb" elbv2 "github.com/aws/aws-sdk-go/service/elbv2" gomock "github.com/golang/mock/gomock" - reflect "reflect" ) // MockClient is a mock of Client interface