This is an automated email from the ASF dual-hosted git repository.

luky116 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 3188ecf8 feat:add more linter in configuration file (#686)
3188ecf8 is described below

commit 3188ecf883b7585afe2c609d635e3a717d449533
Author: xinfan.wu <13708123...@163.com>
AuthorDate: Thu Dec 12 23:59:46 2024 +0800

    feat:add more linter in configuration file (#686)
    
    * feat:add more linter
    
    * feat:change golangclilint version to 1.57.x to support more linter
    
    * feat:adjust lint conf and adjust the code to pass the check
    
    ---------
    
    Co-authored-by: JayLiu <38887641+luky...@users.noreply.github.com>
---
 .golangci.yml                                  | 25 ++++++++++++++++++++-----
 go.mod                                         |  1 -
 go.sum                                         |  2 --
 pkg/datasource/sql/datasource/mysql/trigger.go |  8 ++++++--
 pkg/datasource/sql/undo/base/undo.go           |  7 +++++--
 pkg/datasource/sql/undo/executor/executor.go   |  4 +++-
 pkg/rm/rm_remoting.go                          |  2 +-
 pkg/rm/tcc/fence/fennce_driver_test.go         |  2 +-
 pkg/rm/tcc/tcc_service.go                      |  4 ++--
 9 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/.golangci.yml b/.golangci.yml
index 1180b708..bb7d6eda 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -17,7 +17,7 @@
 
 linters-settings:
   govet:
-    check-shadowing: false
+    shadow: true
   golint:
     min-confidence: 0
   gocyclo:
@@ -56,13 +56,22 @@ linters:
     - staticcheck
     - ineffassign
     - misspell
+   # - errcheck
+    - asciicheck
+    - bodyclose
+    - rowserrcheck
+    #- makezero
+    - durationcheck
+    # - prealloc
+    # - predeclared
+
 
 run:
-  skip-dirs:
-    - test/testdata_etc
-    - pkg/golinters/goanalysis/(checker|passes)
 
 issues:
+  exclude-dirs:
+    - test/testdata_etc
+    - pkg/golinters/goanalysis/(checker|passes)
   exclude-rules:
     - text: "weak cryptographic primitive"
       linters:
@@ -70,11 +79,17 @@ issues:
     - linters:
         - staticcheck
       text: "SA1019:"
+    - path: _test\.go
+      linters:
+        - errcheck
+        - gosec
+        - rowserrcheck
+        - govet
 
 # golangci.com configuration
 # https://github.com/golangci/golangci/wiki/Configuration
 service:
-  golangci-lint-version: 1.49.x # use the fixed version to not introduce new 
linters unexpectedly
+  golangci-lint-version: 1.57.x # use the fixed version to not introduce new 
linters unexpectedly
   prepare:
     - echo "here I can run custom commands, but no preparation needed for this 
repo"
 
diff --git a/go.mod b/go.mod
index 784cc194..e35e9966 100644
--- a/go.mod
+++ b/go.mod
@@ -31,7 +31,6 @@ require (
 )
 
 require (
-       github.com/agiledragon/gomonkey v2.0.2+incompatible
        github.com/agiledragon/gomonkey/v2 v2.9.0
        go.etcd.io/etcd/api/v3 v3.5.6
        go.etcd.io/etcd/client/v3 v3.5.6
diff --git a/go.sum b/go.sum
index e4c461f0..461c515b 100644
--- a/go.sum
+++ b/go.sum
@@ -54,8 +54,6 @@ github.com/VividCortex/gohistogram v1.0.0/go.mod 
h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/
 github.com/Workiva/go-datastructures v1.0.52 
h1:PLSK6pwn8mYdaoaCZEMsXBpBotr4HHn9abU0yMQt0NI=
 github.com/Workiva/go-datastructures v1.0.52/go.mod 
h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
 github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod 
h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
-github.com/agiledragon/gomonkey v2.0.2+incompatible 
h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
-github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod 
h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
 github.com/agiledragon/gomonkey/v2 v2.9.0 
h1:PDiKKybR596O6FHW+RVSG0Z7uGCBNbmbUXh3uCNQ7Hc=
 github.com/agiledragon/gomonkey/v2 v2.9.0/go.mod 
h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
 github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod 
h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
diff --git a/pkg/datasource/sql/datasource/mysql/trigger.go 
b/pkg/datasource/sql/datasource/mysql/trigger.go
index 5512a416..d9339a6d 100644
--- a/pkg/datasource/sql/datasource/mysql/trigger.go
+++ b/pkg/datasource/sql/datasource/mysql/trigger.go
@@ -144,7 +144,9 @@ func (m *mysqlTrigger) getColumnMetas(ctx context.Context, 
dbName string, table
                columnMeta.Autoincrement = 
strings.Contains(strings.ToLower(extra), "auto_increment")
                columnMetas = append(columnMetas, columnMeta)
        }
-
+       if err := rows.Err(); err != nil {
+               return nil, err
+       }
        if len(columnMetas) == 0 {
                return nil, fmt.Errorf("can't find column")
        }
@@ -204,6 +206,8 @@ func (m *mysqlTrigger) getIndexes(ctx context.Context, 
dbName string, tableName
                result = append(result, index)
 
        }
-
+       if err := rows.Err(); err != nil {
+               return nil, err
+       }
        return result, nil
 }
diff --git a/pkg/datasource/sql/undo/base/undo.go 
b/pkg/datasource/sql/undo/base/undo.go
index 331930e7..394cacbd 100644
--- a/pkg/datasource/sql/undo/base/undo.go
+++ b/pkg/datasource/sql/undo/base/undo.go
@@ -297,7 +297,10 @@ func (m *BaseUndoLogManager) Undo(ctx context.Context, 
dbType types.DBType, xid
                }
                undoLogRecords = append(undoLogRecords, record)
        }
-
+       if err := rows.Err(); err != nil {
+               log.Errorf("read rows next fail, xid: %s, branchID:%s err:%v", 
xid, branchID, err)
+               return err
+       }
        var exists bool
        for _, record := range undoLogRecords {
                exists = true
@@ -410,7 +413,7 @@ func (m *BaseUndoLogManager) DBType() types.DBType {
 
 // HasUndoLogTable check undo log table if exist
 func (m *BaseUndoLogManager) HasUndoLogTable(ctx context.Context, conn 
*sql.Conn) (res bool, err error) {
-       if _, err = conn.QueryContext(ctx, getCheckUndoLogTableExistSql()); err 
!= nil {
+       if _, err = conn.QueryContext(ctx, getCheckUndoLogTableExistSql()); err 
!= nil { //nolint:rowserrcheck
                // 1146 mysql table not exist fault code
                if e, ok := err.(*mysql.SQLError); ok && e.Code == 
mysql.ErrNoSuchTable {
                        return false, nil
diff --git a/pkg/datasource/sql/undo/executor/executor.go 
b/pkg/datasource/sql/undo/executor/executor.go
index f4d9a8bb..f4c9aed4 100644
--- a/pkg/datasource/sql/undo/executor/executor.go
+++ b/pkg/datasource/sql/undo/executor/executor.go
@@ -159,7 +159,9 @@ func (b *BaseExecutor) queryCurrentRecords(ctx 
context.Context, conn *sql.Conn)
                }
                rowImages = append(rowImages, types.RowImage{Columns: columns})
        }
-
+       if err := rows.Err(); err != nil {
+               return nil, err
+       }
        image.Rows = rowImages
        return &image, nil
 }
diff --git a/pkg/rm/rm_remoting.go b/pkg/rm/rm_remoting.go
index 67522501..563ebc8b 100644
--- a/pkg/rm/rm_remoting.go
+++ b/pkg/rm/rm_remoting.go
@@ -156,7 +156,7 @@ func isRegisterSuccess(response interface{}) bool {
 func isReportSuccess(response interface{}) error {
        if res, ok := response.(message.BranchReportResponse); ok {
                if res.ResultCode == message.ResultCodeFailed {
-                       return fmt.Errorf(res.Msg)
+                       return errors.New(res.Msg)
                }
        } else {
                return ErrBranchReportResponseFault
diff --git a/pkg/rm/tcc/fence/fennce_driver_test.go 
b/pkg/rm/tcc/fence/fennce_driver_test.go
index cfaddd2a..c0e804e8 100644
--- a/pkg/rm/tcc/fence/fennce_driver_test.go
+++ b/pkg/rm/tcc/fence/fennce_driver_test.go
@@ -24,7 +24,7 @@ import (
        "reflect"
        "testing"
 
-       "github.com/agiledragon/gomonkey"
+       gomonkey "github.com/agiledragon/gomonkey/v2"
        "github.com/go-sql-driver/mysql"
        "github.com/stretchr/testify/assert"
 )
diff --git a/pkg/rm/tcc/tcc_service.go b/pkg/rm/tcc/tcc_service.go
index ffedff1e..87335c65 100644
--- a/pkg/rm/tcc/tcc_service.go
+++ b/pkg/rm/tcc/tcc_service.go
@@ -20,7 +20,7 @@ package tcc
 import (
        "context"
        "encoding/json"
-       "fmt"
+       "errors"
        "reflect"
        "sync"
        "time"
@@ -94,7 +94,7 @@ func (t *TCCServiceProxy) registeBranch(ctx context.Context, 
params interface{})
        if !tm.IsGlobalTx(ctx) {
                errStr := "BranchRegister error, transaction should be opened"
                log.Errorf(errStr)
-               return fmt.Errorf(errStr)
+               return errors.New(errStr)
        }
 
        tccContext := t.initBusinessActionContext(ctx, params)


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to