Skip to content

Commit

Permalink
make/lint: Check that files are formatted (#18)
Browse files Browse the repository at this point in the history
This verifies that all Go files are properly formatted
regardless of whether they're generated or not.

Depends on #17
Resolves #13
  • Loading branch information
abhinav committed Oct 20, 2022
1 parent 1d79109 commit 1a94aa8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ CFF = $(GOBIN)/cff
MOCKGEN = $(GOBIN)/mockgen
STATICCHECK = $(GOBIN)/staticcheck

SRC_FILES = $(shell find . '(' -path '*test*' -o -path '*/examples/*' -prune ')' -o -name '*.go' -print)
SRC_FILES = $(shell find . '(' -path './.*' -o -path '*test*' -o -path '*/examples/*' -prune ')' -o -name '*.go' -print)

# All go files are in scope for formatting -- even if they're generated.
GOFMT_FILES = $(shell find . -path './.*' -prune -o -name '*.go' -print)

.PHONY: build
build: $(CFF)
Expand Down Expand Up @@ -48,13 +51,26 @@ tidy:
go mod tidy \
) &&) true

.PHONY: fmt
fmt:
@gofmt -w -l $(GOFMT_FILES)

.PHONY: lint
lint: staticcheck
lint: staticcheck checkfmt

.PHONY: staticcheck
staticcheck: $(STATICCHECK)
$(STATICCHECK) ./...

.PHONY: checkfmt
checkfmt:
@DIFF=$$(gofmt -d $(GOFMT_FILES)); \
if [[ -n "$$DIFF" ]]; then \
echo "--- gofmt would cause changes:"; \
echo "$$DIFF"; \
exit 1; \
fi

$(CFF): $(SRC_FILES)
go install go.uber.org/cff/cmd/cff

Expand Down

0 comments on commit 1a94aa8

Please sign in to comment.