refactor: update gofmt check (#233)

This commit is contained in:
Bo-Yi Wu 2017-06-04 21:26:45 -05:00 committed by GitHub
parent 5651d9e51f
commit fb7109835a
1 changed files with 6 additions and 5 deletions

View File

@ -10,7 +10,7 @@ GOFMT ?= gofmt "-s"
TARGETS ?= linux darwin windows TARGETS ?= linux darwin windows
ARCHS ?= amd64 386 ARCHS ?= amd64 386
PACKAGES ?= $(shell go list ./... | grep -v /vendor/) PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
GOFILES := find . -name "*.go" -type f -not -path "./vendor/*" GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
SOURCES ?= $(shell find . -name "*.go" -type f) SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?= TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)' LDFLAGS ?= -X 'main.Version=$(VERSION)'
@ -42,16 +42,17 @@ endif
@echo "Already set ANDROID_API_KEY and ANDROID_TEST_TOKEN globale variable." @echo "Already set ANDROID_API_KEY and ANDROID_TEST_TOKEN globale variable."
fmt: fmt:
$(GOFILES) | xargs $(GOFMT) -w $(GOFMT) -w $(GOFILES)
.PHONY: fmt-check .PHONY: fmt-check
fmt-check: fmt-check:
# get all go files and run go fmt on them # get all go files and run go fmt on them
@files=$$($(GOFILES) | xargs $(GOFMT) -l); if [ -n "$$files" ]; then \ @diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \ echo "Please run 'make fmt' and commit the result:"; \
echo "$${files}"; \ echo "$${diff}"; \
exit 1; \ exit 1; \
fi; fi;
vet: vet:
go vet $(PACKAGES) go vet $(PACKAGES)