[#4] Synchronize with frostfs-node repository

- gitlint removed
- golangci-lint modified
- gofumpt added
- go-staticcheck-repo-mod and go-mod-tidy added
- mk scripts added with linters scenarios

Signed-off-by: George Bartolomey <george@bh4.ru>
This commit is contained in:
George Bartolomey 2024-07-12 16:58:19 +03:00
parent 3b9c32fc1d
commit 887b238f4b
Signed by: george.bartolomey
GPG key ID: 35BC54839D73BFAD
7 changed files with 133 additions and 30 deletions

View file

@ -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

View file

@ -4,7 +4,7 @@
# options for analysis running # options for analysis running
run: run:
# timeout for analysis, e.g. 30s, 5m, default is 1m # timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 10m timeout: 20m
# include test files or not, default is true # include test files or not, default is true
tests: false tests: false
@ -31,18 +31,33 @@ linters-settings:
statements: 60 # default 40 statements: 60 # default 40
gocognit: gocognit:
min-complexity: 40 # default 30 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: linters:
enable: enable:
# mandatory linters # mandatory linters
- govet - govet
- revive - revive
# some default golangci-lint linters
- errcheck - errcheck
- gosimple - gosimple
- godot
- ineffassign - ineffassign
- staticcheck - staticcheck
- typecheck - typecheck
- unused - unused
# extra linters
- bidichk - bidichk
- durationcheck - durationcheck
- exhaustive - exhaustive
@ -50,15 +65,17 @@ linters:
- gofmt - gofmt
- goimports - goimports
- misspell - misspell
- whitespace
# extra linters
- godot
- predeclared - predeclared
- reassign - reassign
- whitespace
- containedctx - containedctx
- funlen - funlen
- gocognit - gocognit
- contextcheck - contextcheck
- importas
- truecloudlab-linters
- perfsprint
- testifylint
- protogetter
disable-all: true disable-all: true
fast: false fast: false

View file

@ -2,15 +2,8 @@ ci:
autofix_prs: false autofix_prs: false
repos: 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 - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 rev: v4.5.0
hooks: hooks:
- id: check-added-large-files - id: check-added-large-files
- id: check-case-conflict - id: check-case-conflict
@ -23,23 +16,41 @@ repos:
- id: trailing-whitespace - id: trailing-whitespace
args: [--markdown-linebreak-ext=md] args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer - id: end-of-file-fixer
exclude: ".key$" exclude: "(.key|.svg)$"
- repo: https://github.com/shellcheck-py/shellcheck-py - repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2 rev: v0.9.0.6
hooks: hooks:
- id: shellcheck - id: shellcheck
- repo: https://github.com/golangci/golangci-lint - repo: local
rev: v1.51.2
hooks: hooks:
- id: golangci-lint - id: make-lint
name: Run Make Lint
entry: make lint
language: system
pass_filenames: false
- repo: local - repo: local
hooks: hooks:
- id: go-unit-tests - id: go-unit-tests
name: go unit tests name: go unit tests
entry: make test entry: make test GOFLAGS=''
pass_filenames: false pass_filenames: false
types: [go] types: [go]
language: system 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

19
mk/fumpt.mk Normal file
View file

@ -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/

24
mk/gopls.mk Normal file
View file

@ -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)

25
mk/linters.mk Normal file
View file

@ -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

18
mk/staticcheck.mk Normal file
View file

@ -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 ./...