浏览代码

Migrate to golangci-lint v2

DarthSim 1 月之前
父节点
当前提交
43bd1d73e1
共有 6 个文件被更改,包括 62 次插入50 次删除
  1. 2 2
      .github/workflows/ci.yml
  2. 54 43
      .golangci.yml
  3. 1 1
      .lefthook/pre-commit/lint
  4. 3 2
      imagemeta/iptc/iptc.go
  5. 1 1
      metrics/otel/otel_test.go
  6. 1 1
      processing_handler_test.go

+ 2 - 2
.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"

+ 54 - 43
.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$

+ 1 - 1
.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

+ 3 - 2
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]
 			}
 		}

+ 1 - 1
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() {

+ 1 - 1
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() {