From bf755621b6b8ee867c2444f8fce3b5e507492e9d Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 12 Sep 2024 23:21:59 +0300 Subject: [PATCH 1/3] workflows: switch to org-wide linter job And update Makefile to use appropriate configuration. Signed-off-by: Roman Khimov --- .github/workflows/tests.yml | 15 +---------- .gitignore | 2 ++ .golangci.yml | 54 ------------------------------------- Makefile | 15 ++++------- 4 files changed, 8 insertions(+), 78 deletions(-) delete mode 100644 .golangci.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0f7d04e..78398c9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,20 +12,7 @@ on: jobs: lint: name: Lint - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Set up Go from go.mod - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: latest + uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master cover: name: Coverage diff --git a/.gitignore b/.gitignore index 7df97f7..44f9619 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ temp coverage.txt coverage.html + +.golangci.yml diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index cd745ec..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,54 +0,0 @@ -# This file contains all available configuration options -# with their default values. - -# options for analysis running -run: - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 5m - - # include test files or not, default is true - tests: true - -# output configuration options -output: - # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - formats: - - format: tab - -# all available settings of specific linters -linters-settings: - exhaustive: - # indicates that switch statements are to be considered exhaustive if a - # 'default' case is present, even if all enum members aren't listed in the - # switch - default-signifies-exhaustive: true - -linters: - enable: - # mandatory linters - - govet - - revive - - # some default golangci-lint linters - - errcheck - - gosimple - - ineffassign - - staticcheck - - typecheck - - unused - - # extra linters - - exhaustive - - godot - - gofmt - - whitespace - - goimports - disable-all: true - fast: false - -issues: - include: - - EXC0002 # should have a comment - - EXC0003 # test/Test ... consider calling this - - EXC0004 # govet - - EXC0005 # C-style breaks diff --git a/Makefile b/Makefile index 4f02fe3..f64de61 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,6 @@ VERSION ?= "$(shell git describe --tags --match "v*" --dirty --always --abbrev=8 BUILD_OS ?= linux BUILD_ARCH ?= amd64 GO_VERSION ?= 1.22 -LINT_VERSION ?= v1.59.0 HUB_IMAGE ?= nspccdev/neofs-rest-gw HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')" @@ -102,8 +101,12 @@ image-dirty: -f Dockerfile.dirty \ -t $(HUB_IMAGE)-dirty:$(HUB_TAG) . +# Fetch linter configuration. +.golangci.yml: + wget -O $@ https://github.com/nspcc-dev/.github/raw/master/.golangci.yml + # Run linters -lint: +lint: .golangci.yml @golangci-lint --timeout=5m run # Make all binaries in clean docker environment @@ -118,14 +121,6 @@ docker/all: --env BUILD_ARCH=$(BUILD_ARCH) \ golang:$(GO_VERSION) make all -# Run linters in Docker -docker/lint: - docker run --rm -it \ - -v `pwd`:/src \ - -u `stat -c "%u:%g" .` \ - --env HOME=/src \ - golangci/golangci-lint:$(LINT_VERSION) bash -c 'cd /src/ && make lint' - # Print version version: @echo $(VERSION) From 387eacd007da0ee6cee6368da1d3c2fabaf12daa Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 12 Sep 2024 23:24:14 +0300 Subject: [PATCH 2/3] metrics: fix errorlint warning metrics/service.go:29:20 errorlint comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error Signed-off-by: Roman Khimov --- metrics/service.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/metrics/service.go b/metrics/service.go index 6070462..31c33b7 100644 --- a/metrics/service.go +++ b/metrics/service.go @@ -2,6 +2,7 @@ package metrics import ( "context" + "errors" "net/http" "go.uber.org/zap" @@ -26,7 +27,7 @@ func (ms *Service) Start() { if ms.enabled { ms.log.Info("service is running", zap.String("endpoint", ms.Addr)) err := ms.ListenAndServe() - if err != nil && err != http.ErrServerClosed { + if err != nil && !errors.Is(err, http.ErrServerClosed) { ms.log.Warn("service couldn't start on configured port") } } else { From 02e0776c7fd15d1231de6275fc6828059dcbeaf7 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 12 Sep 2024 23:24:38 +0300 Subject: [PATCH 3/3] Makefile: drop dep target It's totally obsolete and useless. Signed-off-by: Roman Khimov --- Makefile | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index f64de61..d57377e 100644 --- a/Makefile +++ b/Makefile @@ -25,12 +25,12 @@ BINDIR = bin DIRS = "$(BINDIR)" BINS = "$(BINDIR)/neofs-rest-gw" -.PHONY: help all dep clean format test cover lint docker/lint +.PHONY: help all clean format test cover lint docker/lint # Make all binaries all: generate-server $(BINS) -$(BINS): $(DIRS) dep +$(BINS): $(DIRS) @echo "⇒ Build $@" CGO_ENABLED=0 \ GOOS=$(BUILD_OS) \ @@ -43,15 +43,6 @@ $(DIRS): @echo "⇒ Ensure dir: $@" @mkdir -p $@ -# Pull go dependencies -dep: - @printf "⇒ Download requirements: " - @CGO_ENABLED=0 \ - go mod download && echo OK - @printf "⇒ Tidy requirements: " - @CGO_ENABLED=0 \ - go mod tidy -v && echo OK - # Install generator install-generator: @go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@v2.1.0