Skip to content

Commit c8d6f3a

Browse files
committed
Include formatting check to the make check rule
... and give it its own standalone target too (make fmt-check) Show diff on fmt-check failure Do not allow running "fmt-check" with incompatible go version Also simplify the `fmt` rule
1 parent 6fe0997 commit c8d6f3a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Makefile

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ BINDATA := modules/{options,public,templates}/bindata.go
44
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
55
JAVASCRIPTS :=
66
DOCKER_TAG := gitea/gitea:latest
7+
GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
8+
GOFMT ?= gofmt -s
79

810
GOFLAGS := -i -v
911
EXTRA_GOFLAGS ?=
@@ -42,10 +44,12 @@ clean:
4244
go clean -i ./...
4345
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)
4446

47+
required-gofmt-version:
48+
@go version | grep -q '\(1.7\|1.8\)' || { echo "We require go version 1.7 or 1.8 to format code" >&2 && exit 1; }
49+
4550
.PHONY: fmt
46-
fmt:
47-
@go version | grep -q '\(1.7\|1.8\)' || { echo "We require go version 1.7 to format code" >&2 && exit 1; }
48-
find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w
51+
fmt: required-gofmt-version
52+
$(GOFMT) -w $(GOFILES)
4953

5054
.PHONY: vet
5155
vet:
@@ -89,8 +93,18 @@ misspell:
8993
fi
9094
misspell -w -i unknwon $(GOFILES)
9195

96+
.PHONY: fmt-check
97+
fmt-check: required-gofmt-version
98+
# get all go files and run go fmt on them
99+
@diff=$$($(GOFMT) -d $(GOFILES)); \
100+
if [ -n "$$diff" ]; then \
101+
echo "Please run 'make fmt' and commit the result:"; \
102+
echo "$${diff}"; \
103+
exit 1; \
104+
fi;
105+
92106
.PHONY: test
93-
test:
107+
test: fmt-check
94108
go test $(PACKAGES)
95109

96110
.PHONY: test-coverage

0 commit comments

Comments
 (0)