Skip to content

Commit

Permalink
feat:add more linter in configuration file (#686)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
No-SilverBullet and luky116 authored Dec 12, 2024
1 parent 406b8ba commit 3188ecf
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
25 changes: 20 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

linters-settings:
govet:
check-shadowing: false
shadow: true
golint:
min-confidence: 0
gocyclo:
Expand Down Expand Up @@ -56,25 +56,40 @@ 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:
- gosec
- 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"

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 6 additions & 2 deletions pkg/datasource/sql/datasource/mysql/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
}
7 changes: 5 additions & 2 deletions pkg/datasource/sql/undo/base/undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/datasource/sql/undo/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/rm/rm_remoting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/rm/tcc/fence/fennce_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/rm/tcc/tcc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package tcc
import (
"context"
"encoding/json"
"fmt"
"errors"
"reflect"
"sync"
"time"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3188ecf

Please sign in to comment.