From fedaf59bb831d65028375e2b110aa0a23dd02c7c Mon Sep 17 00:00:00 2001 From: George Bartolomey Date: Fri, 12 Jul 2024 16:58:19 +0300 Subject: [PATCH] [#4] Synchronize with frostfs-node repository - gitlint removed - golangci-lint modified - gofumpt added - go-staticcheck-repo-mod and go-mod-tidy added - linters.mk added with linter configuration scenarios Signed-off-by: George Bartolomey --- .gitlint | 11 ----------- .golangci.yml | 32 +++++++++++++++++++++++++++----- .pre-commit-config.yaml | 39 +++++++++++++++++++++++++-------------- linters.mk | 30 ++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 30 deletions(-) delete mode 100644 .gitlint create mode 100644 linters.mk 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..1314f19 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,38 @@ 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 + settings: + noliteral: + target-methods : ["reportFlushError", "reportError"] + disable-packages: ["codes", "err", "res","exec"] + constants-package: "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" 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 +70,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/linters.mk b/linters.mk new file mode 100644 index 0000000..9b16dea --- /dev/null +++ b/linters.mk @@ -0,0 +1,30 @@ +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 + +# Run gofumpt +fumpt: + @echo "⇒ Processing gofumpt check" + @gofumpt -l -w cmd/ pkg/ misc/