Merge pull request #51 from andyz-dev/makefile

[Enhancement] Makefile: Add lint target and factor the check target
pull/56/head
Andy Zhou 5 years ago committed by GitHub
commit 1a2e961a52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      Makefile

@ -31,10 +31,20 @@ PKG_GOLANGCI_LINT := github.com/golangci/golangci-lint/cmd/golangci-lint
export GO111MODULE=on export GO111MODULE=on
# go source files, ignore vendor directory # go source directories.
SRC = *.go cli/*.go # DIRS defines a single level directly, we only look at *.go in this directory.
# REC_DIRS defines a source code tree. All go files are analyzed recursively.
DIRS := .
REC_DIRS := cli
.PHONY: all build build-cross clean fmt simplify check extra-clean install-tools # Rules for finding all go source files using 'DIRS' and 'REC_DIRS'
GO_SRC := $(foreach dir,$(DIRS),$(wildcard $(dir)/*.go))
GO_SRC += $(foreach dir,$(REC_DIRS),$(shell find $(dir) -name "*.go"))
# Rules for directory list as input for the golangci-lint program
LINT_DIRS := $(DIRS) $(foreach dir,$(REC_DIRS),$(dir)/...)
.PHONY: all build build-cross clean fmt check-fmt lint check extra-clean install-tools
all: clean fmt check build all: clean fmt check build
@ -52,13 +62,18 @@ extra-clean: clean
go clean -i $(PKG_GOX) go clean -i $(PKG_GOX)
go clean -i $(PKG_GOLANGCI_LINT) go clean -i $(PKG_GOLANGCI_LINT)
# fmt will fix the golang source style in place.
fmt: fmt:
@gofmt -s -l -w $(SRC) @gofmt -s -l -w $(GO_SRC)
# check-fmt returns an error code if any source code contains format error.
check-fmt:
@test -z $(shell gofmt -s -l $(GO_SRC) | tee /dev/stderr) || echo "[WARN] Fix formatting issues with 'make fmt'"
lint:
@golangci-lint run $(LINT_DIRS)
check: check: check-fmt lint
@test -z $(shell gofmt -l main.go | tee /dev/stderr) || echo "[WARN] Fix formatting issues with 'make fmt'"
@golangci-lint run
@go vet main.go
# Check for required executables # Check for required executables
HAS_GOX := $(shell command -v gox 2> /dev/null) HAS_GOX := $(shell command -v gox 2> /dev/null)

Loading…
Cancel
Save