2024-10-09 13:04:30 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
|
|
|
|
STATICCHECK_VERSION ?= 2024.1.1
|
|
|
|
LINT_VERSION ?= 1.60.3
|
|
|
|
|
|
|
|
BIN = bin
|
|
|
|
OUTPUT_LINT_DIR ?= $(abspath $(BIN))/linters
|
|
|
|
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)
|
|
|
|
TMP_DIR := .cache
|
|
|
|
|
|
|
|
STATICCHECK_DIR ?= $(abspath $(BIN))/staticcheck
|
|
|
|
STATICCHECK_VERSION_DIR ?= $(STATICCHECK_DIR)/$(STATICCHECK_VERSION)
|
|
|
|
|
|
|
|
GOFUMPT_VERSION ?= v0.7.0
|
|
|
|
GOFUMPT_DIR ?= $(abspath $(BIN))/gofumpt
|
|
|
|
GOFUMPT_VERSION_DIR ?= $(GOFUMPT_DIR)/$(GOFUMPT_VERSION)
|
|
|
|
|
|
|
|
GOPLS_VERSION ?= v0.16.2
|
|
|
|
GOPLS_DIR ?= $(abspath $(BIN))/gopls
|
|
|
|
GOPLS_VERSION_DIR ?= $(GOPLS_DIR)/$(GOPLS_VERSION)
|
|
|
|
GOPLS_TEMP_FILE := $(shell mktemp)
|
2023-10-24 12:43:08 +00:00
|
|
|
|
|
|
|
test:
|
|
|
|
go test -count=1 -v ./...
|
2023-10-30 10:28:29 +00:00
|
|
|
|
2024-10-09 13:04:30 +00:00
|
|
|
# Install linters
|
|
|
|
lint-install:
|
|
|
|
@rm -rf $(OUTPUT_LINT_DIR)
|
|
|
|
@mkdir -p $(OUTPUT_LINT_DIR)
|
|
|
|
@CGO_ENABLED=1 GOBIN=$(LINT_DIR) go install -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION)
|
|
|
|
|
|
|
|
# Run linters
|
|
|
|
lint:
|
|
|
|
@if [ ! -d "$(LINT_DIR)" ]; then \
|
|
|
|
make lint-install; \
|
|
|
|
fi
|
|
|
|
$(LINT_DIR)/golangci-lint run
|
|
|
|
|
|
|
|
# Install staticcheck
|
|
|
|
staticcheck-install:
|
|
|
|
@rm -rf $(STATICCHECK_DIR)
|
|
|
|
@mkdir $(STATICCHECK_DIR)
|
|
|
|
@GOBIN=$(STATICCHECK_VERSION_DIR) go install honnef.co/go/tools/cmd/staticcheck@$(STATICCHECK_VERSION)
|
|
|
|
|
|
|
|
# Run staticcheck
|
|
|
|
staticcheck-run:
|
|
|
|
@if [ ! -d "$(STATICCHECK_VERSION_DIR)" ]; then \
|
|
|
|
make staticcheck-install; \
|
|
|
|
fi
|
|
|
|
@$(STATICCHECK_VERSION_DIR)/staticcheck ./...
|
|
|
|
|
|
|
|
# Install gopls
|
|
|
|
gopls-install:
|
|
|
|
@rm -rf $(GOPLS_DIR)
|
|
|
|
@mkdir $(GOPLS_DIR)
|
|
|
|
@GOBIN=$(GOPLS_VERSION_DIR) go install golang.org/x/tools/gopls@$(GOPLS_VERSION)
|
|
|
|
|
|
|
|
# Run gopls
|
|
|
|
gopls-run:
|
|
|
|
@if [ ! -d "$(GOPLS_VERSION_DIR)" ]; then \
|
|
|
|
make gopls-install; \
|
|
|
|
fi
|
|
|
|
$(GOPLS_VERSION_DIR)/gopls check $(SOURCES) 2>&1 >$(GOPLS_TEMP_FILE)
|
|
|
|
@if [[ $$(wc -l < $(GOPLS_TEMP_FILE)) -ne 0 ]]; then \
|
|
|
|
cat $(GOPLS_TEMP_FILE); \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
rm $(GOPLS_TEMP_FILE)
|
|
|
|
|
|
|
|
# Install gofumpt
|
|
|
|
fumpt-install:
|
|
|
|
@rm -rf $(GOFUMPT_DIR)
|
|
|
|
@mkdir $(GOFUMPT_DIR)
|
|
|
|
@GOBIN=$(GOFUMPT_VERSION_DIR) go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION)
|
|
|
|
|
|
|
|
# Run gofumpt
|
|
|
|
fumpt:
|
|
|
|
@if [ ! -d "$(GOFUMPT_VERSION_DIR)" ]; then \
|
|
|
|
make fumpt-install; \
|
|
|
|
fi
|
|
|
|
@echo "⇒ Processing gofumpt check"
|
|
|
|
$(GOFUMPT_VERSION_DIR)/gofumpt -l -w .
|