@@ -7,9 +7,11 @@ GOTEST := GO111MODULE=on go test -v
77
88
99GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
10+ LLFORMAT_PKG := github.com/bhandras/llformat/cmd/llformat
1011
1112GO_BIN := ${GOPATH}/bin
1213GOIMPORTS_BIN := $(GO_BIN ) /gosimports
14+ LLFORMAT_BIN := $(CURDIR ) /$(TOOLS_DIR ) /llformat
1315
1416GOBUILD := CGO_ENABLED=0 GO111MODULE=on go build -v
1517GOINSTALL := CGO_ENABLED=0 GO111MODULE=on go install -v
@@ -35,6 +37,7 @@ UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS)
3537ifneq ($(workers ) ,)
3638LINT_WORKERS = --concurrency=$(workers )
3739endif
40+ FMT_BASE := $(if $(base ) ,$(base ) ,origin/master)
3841
3942DOCKER_TOOLS = docker run \
4043 --rm \
@@ -64,6 +67,11 @@ $(GOIMPORTS_BIN):
6467 @$(call print, "Installing goimports.")
6568 cd $(TOOLS_DIR ) ; go install -trimpath $(GOIMPORTS_PKG )
6669
70+ $(LLFORMAT_BIN ) : $(TOOLS_DIR ) /go.mod $(TOOLS_DIR ) /go.sum
71+ @$(call print, "Installing llformat.")
72+ cd $(TOOLS_DIR ) ; GOBIN=" $( CURDIR) /$( TOOLS_DIR) " \
73+ go install -trimpath $(LLFORMAT_PKG )
74+
6775
6876# ============
6977# INSTALLATION
@@ -132,11 +140,15 @@ unit-postgres-race:
132140# UTILITIES
133141# =========
134142
135- fmt : $(GOIMPORTS_BIN )
136- @$(call print, "Fixing imports.")
137- gosimports -w $(GOFILES_NOVENDOR )
138- @$(call print, "Formatting source.")
139- gofmt -l -w -s $(GOFILES_NOVENDOR )
143+ fmt : $(LLFORMAT_BIN )
144+ @$(call print, "Formatting all handwritten Go source.")
145+ @./scripts/llformat-files.sh all | \
146+ xargs -0 -n 1 $(LLFORMAT_BIN ) -w
147+
148+ fmt-changed : $(LLFORMAT_BIN )
149+ @$(call print, "Formatting Go source changes against $(FMT_BASE ) .")
150+ @./scripts/llformat-files.sh changed " $( FMT_BASE) " | \
151+ xargs -0 -n 1 $(LLFORMAT_BIN ) -w
140152
141153lint : docker-tools
142154 @$(call print, "Linting source.")
0 commit comments