Skip to content

Commit ac85f94

Browse files
Merge pull request #3 from No-SilverBullet/feat/add_linter
feat:adjust lint conf and adjust the code to pass the check
2 parents 6a4bebe + 358f4ac commit ac85f94

File tree

9 files changed

+27
-31
lines changed

9 files changed

+27
-31
lines changed

.golangci.yml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
linters-settings:
1919
govet:
20-
check-shadowing: true
20+
shadow: true
2121
golint:
2222
min-confidence: 0
2323
gocyclo:
@@ -56,32 +56,22 @@ linters:
5656
- staticcheck
5757
- ineffassign
5858
- misspell
59-
- typecheck
60-
- varcheck
61-
- unused
62-
- structcheck
63-
- deadcode
64-
- gosimple
65-
- errcheck
59+
# - errcheck
6660
- asciicheck
6761
- bodyclose
68-
- copyloopvar
6962
- rowserrcheck
70-
- makezero
63+
#- makezero
7164
- durationcheck
72-
- prealloc
73-
- predeclared
74-
- revive
75-
- lll
76-
- intrange
65+
# - prealloc
66+
# - predeclared
7767

7868

7969
run:
80-
skip-dirs:
81-
- test/testdata_etc
82-
- pkg/golinters/goanalysis/(checker|passes)
8370

8471
issues:
72+
exclude-dirs:
73+
- test/testdata_etc
74+
- pkg/golinters/goanalysis/(checker|passes)
8575
exclude-rules:
8676
- text: "weak cryptographic primitive"
8777
linters:
@@ -94,7 +84,7 @@ issues:
9484
- errcheck
9585
- gosec
9686
- rowserrcheck
97-
- makezero
87+
- govet
9888

9989
# golangci.com configuration
10090
# https://github.com/golangci/golangci/wiki/Configuration

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ require (
3131
)
3232

3333
require (
34-
github.com/agiledragon/gomonkey v2.0.2+incompatible
3534
github.com/agiledragon/gomonkey/v2 v2.9.0
3635
go.etcd.io/etcd/api/v3 v3.5.6
3736
go.etcd.io/etcd/client/v3 v3.5.6

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/
5454
github.com/Workiva/go-datastructures v1.0.52 h1:PLSK6pwn8mYdaoaCZEMsXBpBotr4HHn9abU0yMQt0NI=
5555
github.com/Workiva/go-datastructures v1.0.52/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
5656
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
57-
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
58-
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
5957
github.com/agiledragon/gomonkey/v2 v2.9.0 h1:PDiKKybR596O6FHW+RVSG0Z7uGCBNbmbUXh3uCNQ7Hc=
6058
github.com/agiledragon/gomonkey/v2 v2.9.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
6159
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=

pkg/datasource/sql/datasource/mysql/trigger.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ func (m *mysqlTrigger) getColumnMetas(ctx context.Context, dbName string, table
144144
columnMeta.Autoincrement = strings.Contains(strings.ToLower(extra), "auto_increment")
145145
columnMetas = append(columnMetas, columnMeta)
146146
}
147-
147+
if err := rows.Err(); err != nil {
148+
return nil, err
149+
}
148150
if len(columnMetas) == 0 {
149151
return nil, fmt.Errorf("can't find column")
150152
}
@@ -204,6 +206,8 @@ func (m *mysqlTrigger) getIndexes(ctx context.Context, dbName string, tableName
204206
result = append(result, index)
205207

206208
}
207-
209+
if err := rows.Err(); err != nil {
210+
return nil, err
211+
}
208212
return result, nil
209213
}

pkg/datasource/sql/undo/base/undo.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ func (m *BaseUndoLogManager) Undo(ctx context.Context, dbType types.DBType, xid
297297
}
298298
undoLogRecords = append(undoLogRecords, record)
299299
}
300-
300+
if err := rows.Err(); err != nil {
301+
log.Errorf("read rows next fail, xid: %s, branchID:%s err:%v", xid, branchID, err)
302+
return err
303+
}
301304
var exists bool
302305
for _, record := range undoLogRecords {
303306
exists = true
@@ -410,7 +413,7 @@ func (m *BaseUndoLogManager) DBType() types.DBType {
410413

411414
// HasUndoLogTable check undo log table if exist
412415
func (m *BaseUndoLogManager) HasUndoLogTable(ctx context.Context, conn *sql.Conn) (res bool, err error) {
413-
if _, err = conn.QueryContext(ctx, getCheckUndoLogTableExistSql()); err != nil {
416+
if _, err = conn.QueryContext(ctx, getCheckUndoLogTableExistSql()); err != nil { //nolint:rowserrcheck
414417
// 1146 mysql table not exist fault code
415418
if e, ok := err.(*mysql.SQLError); ok && e.Code == mysql.ErrNoSuchTable {
416419
return false, nil

pkg/datasource/sql/undo/executor/executor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ func (b *BaseExecutor) queryCurrentRecords(ctx context.Context, conn *sql.Conn)
159159
}
160160
rowImages = append(rowImages, types.RowImage{Columns: columns})
161161
}
162-
162+
if err := rows.Err(); err != nil {
163+
return nil, err
164+
}
163165
image.Rows = rowImages
164166
return &image, nil
165167
}

pkg/rm/rm_remoting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func isRegisterSuccess(response interface{}) bool {
156156
func isReportSuccess(response interface{}) error {
157157
if res, ok := response.(message.BranchReportResponse); ok {
158158
if res.ResultCode == message.ResultCodeFailed {
159-
return fmt.Errorf(res.Msg)
159+
return errors.New(res.Msg)
160160
}
161161
} else {
162162
return ErrBranchReportResponseFault

pkg/rm/tcc/fence/fennce_driver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"reflect"
2525
"testing"
2626

27-
"github.com/agiledragon/gomonkey"
27+
gomonkey "github.com/agiledragon/gomonkey/v2"
2828
"github.com/go-sql-driver/mysql"
2929
"github.com/stretchr/testify/assert"
3030
)

pkg/rm/tcc/tcc_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package tcc
2020
import (
2121
"context"
2222
"encoding/json"
23-
"fmt"
23+
"errors"
2424
"reflect"
2525
"sync"
2626
"time"
@@ -94,7 +94,7 @@ func (t *TCCServiceProxy) registeBranch(ctx context.Context, params interface{})
9494
if !tm.IsGlobalTx(ctx) {
9595
errStr := "BranchRegister error, transaction should be opened"
9696
log.Errorf(errStr)
97-
return fmt.Errorf(errStr)
97+
return errors.New(errStr)
9898
}
9999

100100
tccContext := t.initBusinessActionContext(ctx, params)

0 commit comments

Comments
 (0)