There were several problems: - `fmt` was a duplicate of `fumpt` - `fmt` used globally installed `gofumpt` Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
107 lines
2.6 KiB
Makefile
Executable file
107 lines
2.6 KiB
Makefile
Executable file
#!/usr/bin/make -f
|
|
SHELL = bash
|
|
|
|
BIN = bin
|
|
TMP_DIR := .cache
|
|
|
|
SOURCES = $(shell find . -type f -name "*.go" -print)
|
|
|
|
LINT_VERSION ?= 1.63.4
|
|
LINT_DIR ?= $(abspath $(BIN))/golangci-lint
|
|
LINT_VERSION_DIR = $(LINT_DIR)/$(LINT_VERSION)
|
|
|
|
STATICCHECK_VERSION ?= 2024.1.1
|
|
STATICCHECK_DIR ?= $(abspath $(BIN))/staticcheck
|
|
STATICCHECK_VERSION_DIR ?= $(STATICCHECK_DIR)/$(STATICCHECK_VERSION)
|
|
|
|
GOPLS_VERSION ?= v0.17.1
|
|
GOPLS_DIR ?= $(abspath $(BIN))/gopls
|
|
GOPLS_VERSION_DIR ?= $(GOPLS_DIR)/$(GOPLS_VERSION)
|
|
GOPLS_TEMP_FILE := $(shell mktemp)
|
|
|
|
GOFUMPT_VERSION ?= v0.7.0
|
|
GOFUMPT_DIR ?= $(abspath $(BIN))/gofumpt
|
|
GOFUMPT_VERSION_DIR ?= $(GOFUMPT_DIR)/$(GOFUMPT_VERSION)
|
|
|
|
# Run all code formatters
|
|
fmts: fumpt imports
|
|
|
|
# Reformat imports
|
|
imports:
|
|
@echo "⇒ Processing goimports check"
|
|
@goimports -w .
|
|
|
|
# Run Unit Test with go test
|
|
test: GOFLAGS ?= "-count=1"
|
|
test:
|
|
@echo "⇒ Running go test"
|
|
@GOFLAGS="$(GOFLAGS)" go test ./...
|
|
|
|
# Activate pre-commit hooks
|
|
pre-commit:
|
|
pre-commit install -t pre-commit -t commit-msg
|
|
|
|
# Deactivate pre-commit hooks
|
|
unpre-commit:
|
|
pre-commit uninstall -t pre-commit -t commit-msg
|
|
|
|
pre-commit-run:
|
|
@pre-commit run -a --hook-stage manual
|
|
|
|
# Install linters
|
|
lint-install:
|
|
@rm -rf $(LINT_DIR)
|
|
@mkdir -p $(LINT_DIR)
|
|
@CGO_ENABLED=1 GOBIN=$(LINT_VERSION_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION)
|
|
|
|
# Run linters
|
|
lint:
|
|
@if [ ! -d "$(LINT_VERSION_DIR)" ]; then \
|
|
make lint-install; \
|
|
fi
|
|
$(LINT_VERSION_DIR)/golangci-lint run
|
|
|
|
# Install staticcheck
|
|
staticcheck-install:
|
|
@rm -rf $(STATICCHECK_DIR)
|
|
@mkdir -p $(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 -p $(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 -p $(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 .
|