From 447eee261db03a6e128b9eb9661a3cc9ce1c3394 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 19 May 2020 14:19:18 +0300 Subject: [PATCH] Makefile: add gofmt and gofmt-verify targets For re-formatting the code and checking that we comply. Inspired by what we have in node-feature-discovery-operator. --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Makefile b/Makefile index 10ea75abd..1d046bd13 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ .FORCE: GO_CMD := go +GO_FMT := gofmt IMAGE_BUILD_CMD := docker build IMAGE_BUILD_EXTRA_OPTS := @@ -44,6 +45,17 @@ mock: mockery --name=APIHelpers --dir=pkg/apihelper --inpkg --note="Re-generate by running 'make mock'" mockery --name=LabelerClient --dir=pkg/labeler --inpkg --note="Re-generate by running 'make mock'" +gofmt: + @$(GO_FMT) -w -l $$(find . -name '*.go') + +gofmt-verify: + @out=`$(GO_FMT) -l -d $$(find . -name '*.go')`; \ + if [ -n "$$out" ]; then \ + echo "$$out"; \ + exit 1; \ + fi + + test: $(GO_CMD) test ./cmd/... ./pkg/...