From 9b793cf80bc8fa6240f6edd45d58040bf37b3d2f Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 1 Apr 2017 22:30:46 +0800 Subject: [PATCH] refactor: check gofmt error. (#203) --- Makefile | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 044a8f4..85a15e2 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,12 @@ EXECUTABLE := gorush DEPLOY_ACCOUNT := appleboy DEPLOY_IMAGE := $(EXECUTABLE) +GOFMT ?= gofmt "-s" TARGETS ?= linux darwin windows ARCHS ?= amd64 386 PACKAGES ?= $(shell go list ./... | grep -v /vendor/) +GOFILES := find . -name "*.go" -type f -not -path "./vendor/*" SOURCES ?= $(shell find . -name "*.go" -type f) TAGS ?= LDFLAGS ?= -X 'main.Version=$(VERSION)' @@ -39,23 +41,16 @@ endif @echo "Already set ANDROID_API_KEY and ANDROID_TEST_TOKEN globale variable." fmt: - find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w + $(GOFILES) | xargs $(GOFMT) -w .PHONY: fmt-check fmt-check: - @if git diff --quiet --exit-code; then \ - $(MAKE) fmt && git diff --exit-code || { \ - git checkout .; \ - echo; \ - echo "Please run 'make fmt' and commit the result"; \ - echo; \ - false; } >&2; \ - else { \ - echo; \ - echo "'make fmt-check' cannot be run with unstaged changes"; \ - echo; \ - false; } >&2; \ - fi + # get all go files and run go fmt on them + @files=$$($(GOFILES) | xargs $(GOFMT) -l); if [ -n "$$files" ]; then \ + echo "Please run 'make fmt' and commit the result:"; \ + echo "$${files}"; \ + exit 1; \ + fi; vet: go vet $(PACKAGES)