From 358f4ace93d5ffcbf10e24ee61ae21df00630eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?xinfan=2Ewu=28=E5=90=B4=E6=AD=86=E5=B8=86=29?= Date: Sun, 10 Nov 2024 17:10:31 +0800 Subject: [PATCH] feat:adjust lint conf and adjust the code to pass the check --- .golangci.yml | 28 ++++++------------- go.mod | 1 - go.sum | 2 -- .../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, 27 insertions(+), 31 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ce9962796..bb7d6eda5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,7 +17,7 @@ linters-settings: govet: - check-shadowing: true + shadow: true golint: min-confidence: 0 gocyclo: @@ -56,32 +56,22 @@ linters: - staticcheck - ineffassign - misspell - - typecheck - - varcheck - - unused - - structcheck - - deadcode - - gosimple - - errcheck + # - errcheck - asciicheck - bodyclose - - copyloopvar - rowserrcheck - - makezero + #- makezero - durationcheck - - prealloc - - predeclared - - revive - - lll - - intrange + # - 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: @@ -94,7 +84,7 @@ issues: - errcheck - gosec - rowserrcheck - - makezero + - govet # golangci.com configuration # https://github.com/golangci/golangci/wiki/Configuration diff --git a/go.mod b/go.mod index eb77d6ab1..4060540be 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 ae805fdea..9eec81972 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 5512a416c..d9339a6d1 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 5861012e2..8d70dade7 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 f4d9a8bba..f4c9aed46 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 675225012..563ebc8b1 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 cfaddd2a1..c0e804e8b 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 ffedff1e6..87335c65e 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)