Skip to content

Commit f6b5896

Browse files
strkappleboy
authored andcommitted
Include formatting check to the make test (and thus also check) rule (#1366)
* 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 * Forbid running "make fmt" with Go version != 1.7 or 1.8 * Ignore bindata.go for spelling and formatting checks also remove duplicated variable assignment for GOFILES * Run `make fmt`
1 parent 6ec07a6 commit f6b5896

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
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/*" -not -path "*/bindata.go")
8+
GOFMT ?= gofmt -s
79

810
GOFLAGS := -i -v
911
EXTRA_GOFLAGS ?=
@@ -12,7 +14,6 @@ LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/'
1214

1315
PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations,$(shell go list ./... | grep -v /vendor/))
1416
SOURCES ?= $(shell find . -name "*.go" -type f)
15-
GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
1617

1718
TAGS ?=
1819

@@ -42,9 +43,12 @@ clean:
4243
go clean -i ./...
4344
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)
4445

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

4953
.PHONY: vet
5054
vet:
@@ -88,8 +92,18 @@ misspell:
8892
fi
8993
misspell -w -i unknwon $(GOFILES)
9094

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

95109
.PHONY: test-coverage

models/repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"code.gitea.io/gitea/modules/markdown"
1212
"code.gitea.io/gitea/modules/setting"
1313

14-
"github.com/stretchr/testify/assert"
1514
"github.com/Unknwon/com"
15+
"github.com/stretchr/testify/assert"
1616
)
1717

1818
func TestRepo(t *testing.T) {

modules/setting/setting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ var (
177177

178178
// Repository local settings
179179
Local struct {
180-
LocalCopyPath string
180+
LocalCopyPath string
181181
} `ini:"-"`
182182
}{
183183
AnsiCharset: "",
@@ -214,7 +214,7 @@ var (
214214

215215
// Repository local settings
216216
Local: struct {
217-
LocalCopyPath string
217+
LocalCopyPath string
218218
}{
219219
LocalCopyPath: "tmp/local-repo",
220220
},

0 commit comments

Comments
 (0)