From 43bd1d73e135a739404e5c812614f56e3d880029 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Mon, 24 Mar 2025 21:01:54 +0300 Subject: [PATCH] Migrate to golangci-lint v2 --- .github/workflows/ci.yml | 4 +- .golangci.yml | 97 +++++++++++++++++++++----------------- .lefthook/pre-commit/lint | 2 +- imagemeta/iptc/iptc.go | 5 +- metrics/otel/otel_test.go | 2 +- processing_handler_test.go | 2 +- 6 files changed, 62 insertions(+), 50 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ca4abdb..e4053638 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,9 +46,9 @@ jobs: - name: Download mods run: go mod download - name: Lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.61.0 + version: v2.0.0 args: --timeout 5m0s env: LD_LIBRARY_PATH: "/usr/local/lib:/root/vips/${{ matrix.vips-version }}/lib" diff --git a/.golangci.yml b/.golangci.yml index 212f1f09..632c9b77 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,50 +1,61 @@ +version: "2" linters: - disable-all: true + default: none enable: - # - errcheck + - bodyclose - gocritic - # - goconst - - goimports - - gosimple - govet - ineffassign - staticcheck - - stylecheck - - typecheck - - unused - - bodyclose - testifylint - -linters-settings: - govet: - enable-all: true - disable: - - fieldalignment - -issues: - exclude-dirs: - - .tmp - - vendor - exclude-rules: - # - path: _test\.go - # linters: - # - goconst - - - linters: [bodyclose] - path: ".*_test.go" - - - linters: [bodyclose] - path: "router/timeout_response.go" - - # False positives on CGO generated code - - linters: [staticcheck] - text: "SA4000:" - path: vips/.* - - # False positives on CGO generated code - - linters: [gocritic] - text: "dupSubExpr" - path: vips/.* - - - linters: [stylecheck] - text: "ST1005:" + - unused + settings: + govet: + disable: + - fieldalignment + enable-all: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - bodyclose + path: .*_test.go + - linters: + - bodyclose + path: router/timeout_response.go + # False positives on CGO generated code + - linters: + - staticcheck + path: vips/.* + text: 'SA4000:' + # False positives on CGO generated code + - linters: + - gocritic + path: vips/.* + text: dupSubExpr + # False positives on CGO generated code + - linters: + - staticcheck + text: 'ST1005:' + paths: + - .tmp + - vendor + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - goimports + exclusions: + generated: lax + paths: + - .tmp + - vendor + - third_party$ + - builtin$ + - examples$ diff --git a/.lefthook/pre-commit/lint b/.lefthook/pre-commit/lint index 9531204d..4a28c49f 100755 --- a/.lefthook/pre-commit/lint +++ b/.lefthook/pre-commit/lint @@ -12,6 +12,6 @@ if [ -x "$(which brew)" ]; then fi export CGO_LDFLAGS_ALLOW="-s|-w" -export CGO_CFLAGS_ALLOW="-Xpreprocessor" +export CGO_CFLAGS_ALLOW="-I|-Xpreprocessor" golangci-lint run diff --git a/imagemeta/iptc/iptc.go b/imagemeta/iptc/iptc.go index 53313ccc..ea090594 100644 --- a/imagemeta/iptc/iptc.go +++ b/imagemeta/iptc/iptc.go @@ -49,9 +49,10 @@ func (m IptcMap) MarshalJSON() ([]byte, error) { // Add some additional fields for backward compatibility if key.RecordID == 2 { - if key.TagID == 5 { + switch key.TagID { + case 5: mm["Name"] = values[0] - } else if key.TagID == 120 { + case 120: mm["Caption"] = values[0] } } diff --git a/metrics/otel/otel_test.go b/metrics/otel/otel_test.go index 278797d2..5c8cd7cc 100644 --- a/metrics/otel/otel_test.go +++ b/metrics/otel/otel_test.go @@ -36,7 +36,7 @@ func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointNoProtocol() { s.Require().True(config.OpenTelemetryEnable) s.Require().Equal("https://otel_endpoint:1234", os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")) - s.Require().Equal("", os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL")) + s.Require().Empty(os.Getenv("OTEL_EXPORTER_OTLP_PROTOCOL")) } func (s *OtelTestSuite) TestMapDeprecatedConfigEndpointGrpcProtocol() { diff --git a/processing_handler_test.go b/processing_handler_test.go index f4186248..cfb00b6c 100644 --- a/processing_handler_test.go +++ b/processing_handler_test.go @@ -594,7 +594,7 @@ func (s *ProcessingHandlerTestSuite) TestLastModifiedDisabled() { rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL) res := rw.Result() - s.Require().Equal("", res.Header.Get("Last-Modified")) + s.Require().Empty(res.Header.Get("Last-Modified")) } func (s *ProcessingHandlerTestSuite) TestModifiedSinceReqExactMatchLastModifiedDisabled() {