From a4dc098318a1b3d43a82cd0fb00fb26024208af9 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 1 Apr 2017 22:22:26 +0800 Subject: [PATCH] refactor: check gofmt error. (#63) --- Makefile | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 076d9f7..e6379bc 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,11 @@ EXECUTABLE := drone-ssh # for dockerhub DEPLOY_ACCOUNT := appleboy DEPLOY_IMAGE := $(EXECUTABLE) +GOFMT ?= gofmt "-s" TARGETS ?= linux darwin windows 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)' @@ -27,8 +29,17 @@ endif all: build +.PHONY: fmt-check +fmt-check: + # 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; + fmt: - find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w + $(GOFILES) | xargs $(GOFMT) -w vet: go vet $(PACKAGES) @@ -51,7 +62,7 @@ unconvert: fi for PKG in $(PACKAGES); do unconvert -v $$PKG || exit 1; done; -test: +test: fmt-check for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done; html: