From 9d574a3aa4697893c0fb90387267fabb2d1775f3 Mon Sep 17 00:00:00 2001 From: George Bartolomey Date: Sat, 14 Sep 2024 20:29:42 +0300 Subject: [PATCH] fixup: Add fumpt, gopls and staticcheck Make scenarios --- mk/fumpt.mk | 19 +++++++++++++++++++ mk/gopls.mk | 24 ++++++++++++++++++++++++ linters.mk => mk/linters.mk | 5 ----- mk/staticcheck.mk | 18 ++++++++++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 mk/fumpt.mk create mode 100644 mk/gopls.mk rename linters.mk => mk/linters.mk (90%) create mode 100644 mk/staticcheck.mk diff --git a/mk/fumpt.mk b/mk/fumpt.mk new file mode 100644 index 0000000..fb2ee65 --- /dev/null +++ b/mk/fumpt.mk @@ -0,0 +1,19 @@ +BIN ?= bin +GOFUMPT_VERSION ?= v0.7.0 +GOFUMPT_DIR ?= $(abspath $(BIN))/gofumpt +GOFUMPT_VERSION_DIR ?= $(GOFUMPT_DIR)/$(GOFUMPT_VERSION) + +.PHONY: fumpt fumpt-install + +# Install gofumpt +fumpt-install: + @rm -rf $(GOFUMPT_DIR) + @mkdir $(GOFUMPT_DIR) + @GOBIN=$(GOFUMPT_VERSION_DIR) go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION) + +$(GOFUMPT_VERSION_DIR): fumpt-install + +# Run gofumpt +fumpt: $(GOFUMPT_VERSION_DIR) + @echo "⇒ Processing gofumpt check" + $(GOFUMPT_VERSION_DIR)/gofumpt -l -w cmd/ pkg/ misc/ diff --git a/mk/gopls.mk b/mk/gopls.mk new file mode 100644 index 0000000..3052a3e --- /dev/null +++ b/mk/gopls.mk @@ -0,0 +1,24 @@ +BIN ?= bin +GOPLS_VERSION ?= v0.15.1 +GOPLS_DIR ?= $(abspath $(BIN))/gopls +GOPLS_VERSION_DIR ?= $(GOPLS_DIR)/$(GOPLS_VERSION) +GOPLS_TEMP_FILE := $(shell mktemp) + +.PHONY: gopls-install gopls-run + +# Install gopls +gopls-install: + @rm -rf $(GOPLS_DIR) + @mkdir $(GOPLS_DIR) + @GOBIN=$(GOPLS_VERSION_DIR) go install golang.org/x/tools/gopls@$(GOPLS_VERSION) + +$(GOPLS_VERSION_DIR): gopls-install + +# Run gopls +gopls-run: $(GOPLS_VERSION_DIR) + $(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) diff --git a/linters.mk b/mk/linters.mk similarity index 90% rename from linters.mk rename to mk/linters.mk index 9b16dea..1e9b082 100644 --- a/linters.mk +++ b/mk/linters.mk @@ -23,8 +23,3 @@ $(LINT_DIR): # Run linters lint: $(LINT_DIR) $(LINT_DIR)/golangci-lint run - -# Run gofumpt -fumpt: - @echo "⇒ Processing gofumpt check" - @gofumpt -l -w cmd/ pkg/ misc/ diff --git a/mk/staticcheck.mk b/mk/staticcheck.mk new file mode 100644 index 0000000..d9a8229 --- /dev/null +++ b/mk/staticcheck.mk @@ -0,0 +1,18 @@ +BIN ?= bin +STATICCHECK_VERSION ?= 2024.1.1 +STATICCHECK_DIR ?= $(abspath $(BIN))/staticcheck +STATICCHECK_VERSION_DIR ?= $(STATICCHECK_DIR)/$(STATICCHECK_VERSION) + +.PHONY: staticcheck-install staticcheck-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) + +$(STATICCHECK_VERSION_DIR): staticcheck-install + +# Run staticcheck +staticcheck-run: $(STATICCHECK_VERSION_DIR) + @$(STATICCHECK_VERSION_DIR)/staticcheck ./...