feat: add fmt check command. (#202)

This commit is contained in:
Bo-Yi Wu 2017-03-30 14:29:53 +08:00 committed by GitHub
parent 5b2b3695e5
commit 590a44209d
1 changed files with 17 additions and 1 deletions

View File

@ -41,6 +41,22 @@ endif
fmt: fmt:
find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -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
vet: vet:
go vet $(PACKAGES) go vet $(PACKAGES)
@ -76,7 +92,7 @@ build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES) $(EXECUTABLE): $(SOURCES)
go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@ go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
test: test: fmt-check
for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done; for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done;
redis_test: init redis_test: init