Skip to content

Commit 6f16f24

Browse files
authored
refactor: check gofmt error. (#68)
1 parent 00b96ae commit 6f16f24

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

Makefile

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.PHONY: test
22

3+
GOFMT ?= gofmt "-s"
34
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
5+
GOFILES := find . -name "*.go" -type f -not -path "./vendor/*"
46

57
install:
68
@hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
@@ -15,23 +17,16 @@ embedmd:
1517
embedmd -d *.md
1618

1719
fmt:
18-
find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w
20+
$(GOFILES) | xargs $(GOFMT) -w
1921

2022
.PHONY: fmt-check
2123
fmt-check:
22-
@if git diff --quiet --exit-code; then \
23-
$(MAKE) fmt && git diff --exit-code || { \
24-
git checkout .; \
25-
echo; \
26-
echo "Please run 'make fmt' and commit the result"; \
27-
echo; \
28-
false; } >&2; \
29-
else { \
30-
echo; \
31-
echo "'make fmt-check' cannot be run with unstaged changes"; \
32-
echo; \
33-
false; } >&2; \
34-
fi
24+
# get all go files and run go fmt on them
25+
@files=$$($(GOFILES) | xargs $(GOFMT) -l); if [ -n "$$files" ]; then \
26+
echo "Please run 'make fmt' and commit the result:"; \
27+
echo "$${files}"; \
28+
exit 1; \
29+
fi;
3530

3631
test: fmt-check
3732
for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done;

0 commit comments

Comments
 (0)