diff --git a/.gitlint b/.gitlint deleted file mode 100644 index e7218ac..0000000 --- a/.gitlint +++ /dev/null @@ -1,11 +0,0 @@ -[general] -fail-without-commits=True -regex-style-search=True -contrib=CC1 - -[title-match-regex] -regex=^\[\#[0-9Xx]+\]\s - -[ignore-by-title] -regex=^Release(.*) -ignore=title-match-regex diff --git a/.golangci.yml b/.golangci.yml index dba7f0c..405bddc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,7 +4,7 @@ # options for analysis running run: # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 10m + timeout: 20m # include test files or not, default is true tests: false @@ -31,18 +31,33 @@ linters-settings: statements: 60 # default 40 gocognit: min-complexity: 40 # default 30 + importas: + no-unaliased: true + no-extra-aliases: false + alias: + pkg: git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object + alias: objectSDK + custom: + truecloudlab-linters: + path: bin/linters/external_linters.so + original-url: git.frostfs.info/TrueCloudLab/linters.git linters: enable: # mandatory linters - govet - revive + + # some default golangci-lint linters - errcheck - gosimple + - godot - ineffassign - staticcheck - typecheck - unused + + # extra linters - bidichk - durationcheck - exhaustive @@ -50,15 +65,17 @@ linters: - gofmt - goimports - misspell - - whitespace - - # extra linters - - godot - predeclared - reassign + - whitespace - containedctx - funlen - gocognit - contextcheck + - importas + - truecloudlab-linters + - perfsprint + - testifylint + - protogetter disable-all: true fast: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 169b7bf..d2d90fa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,15 +2,8 @@ ci: autofix_prs: false repos: - - repo: https://github.com/jorisroovers/gitlint - rev: v0.19.1 - hooks: - - id: gitlint - stages: [commit-msg] - - id: gitlint-ci - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-added-large-files - id: check-case-conflict @@ -23,23 +16,41 @@ repos: - id: trailing-whitespace args: [--markdown-linebreak-ext=md] - id: end-of-file-fixer - exclude: ".key$" + exclude: "(.key|.svg)$" - repo: https://github.com/shellcheck-py/shellcheck-py - rev: v0.9.0.2 + rev: v0.9.0.6 hooks: - id: shellcheck - - repo: https://github.com/golangci/golangci-lint - rev: v1.51.2 + - repo: local hooks: - - id: golangci-lint + - id: make-lint + name: Run Make Lint + entry: make lint + language: system + pass_filenames: false - repo: local hooks: - id: go-unit-tests name: go unit tests - entry: make test + entry: make test GOFLAGS='' pass_filenames: false types: [go] language: system + + - repo: local + hooks: + - id: gofumpt + name: gofumpt + entry: make fumpt + pass_filenames: false + types: [go] + language: system + + - repo: https://github.com/TekWizely/pre-commit-golang + rev: v1.0.0-rc.1 + hooks: + - id: go-staticcheck-repo-mod + - id: go-mod-tidy 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/mk/linters.mk b/mk/linters.mk new file mode 100644 index 0000000..1e9b082 --- /dev/null +++ b/mk/linters.mk @@ -0,0 +1,25 @@ +GO_VERSION ?= 1.22 +LINT_VERSION ?= 1.56.1 +TRUECLOUDLAB_LINT_VERSION ?= 0.0.5 +BIN ?= bin +OUTPUT_LINT_DIR ?= $(abspath $(BIN))/linters +LINT_DIR ?= $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION) +TMP_DIR := .cache + +.PHONY: lint fumpt + +# Install linters +$(LINT_DIR): + @rm -rf $(OUTPUT_LINT_DIR) + @mkdir $(OUTPUT_LINT_DIR) + @mkdir -p $(TMP_DIR) + @rm -rf $(TMP_DIR)/linters + @git -c advice.detachedHead=false clone --branch v$(TRUECLOUDLAB_LINT_VERSION) https://git.frostfs.info/TrueCloudLab/linters.git $(TMP_DIR)/linters + @@make -C $(TMP_DIR)/linters lib CGO_ENABLED=1 OUT_DIR=$(OUTPUT_LINT_DIR) + @rm -rf $(TMP_DIR)/linters + @rmdir $(TMP_DIR) 2>/dev/null || true + @CGO_ENABLED=1 GOBIN=$(LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION) + +# Run linters +lint: $(LINT_DIR) + $(LINT_DIR)/golangci-lint run 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 ./...