Makefile: Add lint target and factor the check target

pull/51/head
Andy Zhou 5 years ago
parent 89d51a0abc
commit abfd6bd18a
  1. 31
      Makefile
  2. 2
      cli/container.go

@ -31,10 +31,20 @@ PKG_GOLANGCI_LINT := github.com/golangci/golangci-lint/cmd/golangci-lint
export GO111MODULE=on
# go source files, ignore vendor directory
SRC = *.go cli/*.go
# go source directories.
# 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
@ -52,13 +62,18 @@ extra-clean: clean
go clean -i $(PKG_GOX)
go clean -i $(PKG_GOLANGCI_LINT)
# fmt will fix the golang source style in place.
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:
@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: check-fmt lint
# Check for required executables
HAS_GOX := $(shell command -v gox 2> /dev/null)

@ -199,7 +199,7 @@ func removeContainer(ID string) error {
options := types.ContainerRemoveOptions{
RemoveVolumes: true,
Force:true,
Force: true,
}
if err := docker.ContainerRemove(ctx, ID, options); err != nil {

Loading…
Cancel
Save