Skip to content

Commit 44db92b

Browse files
committed
ci: enable more linters
- forbidigo - gocritic - lll - reassign - stylecheck - unconvert
1 parent c2498be commit 44db92b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+991
-763
lines changed

.github/workflows/check.yaml

+2-11
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,15 @@ jobs:
4040
uses: golangci/golangci-lint-action@v3
4141
continue-on-error: true
4242
with:
43-
# The suppression of the rule `errcheck` may be removed after adding
44-
# errors check in all methods calling EncodeXxx inside.
45-
# For now those methods are not even able to return any error
46-
# cause of internal implementation of writer interface (see smallbuf.go).
47-
#
48-
# The `//nolint` workaround was not the acceptable way of warnings suppression,
49-
# cause those comments get rendered in documentation by godoc.
50-
# See https://github.com/tarantool/go-tarantool/pull/160#discussion_r858608221
51-
#
5243
# The first run is for GitHub Actions error format.
53-
args: -E goimports -D errcheck
44+
args: --config=.golangci.yaml
5445

5546
- name: golangci-lint
5647
uses: golangci/golangci-lint-action@v3
5748
with:
5849
# The second run is for human-readable error format with a file name
5950
# and a line number.
60-
args: --out-${NO_FUTURE}format colored-line-number -E goimports -D errcheck
51+
args: --out-${NO_FUTURE}format colored-line-number --config=.golangci.yaml
6152

6253
codespell:
6354
runs-on: ubuntu-latest

.golangci.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
run:
2+
timeout: 3m
3+
4+
linters:
5+
disable:
6+
- errcheck
7+
enable:
8+
- forbidigo
9+
- gocritic
10+
- goimports
11+
- lll
12+
- reassign
13+
- stylecheck
14+
- unconvert
15+
16+
linters-settings:
17+
gocritic:
18+
disabled-checks:
19+
- ifElseChain
20+
lll:
21+
line-length: 100
22+
tab-width: 4
23+
stylecheck:
24+
checks: ["all", "-ST1003"]
25+
26+
issues:
27+
exclude-rules:
28+
- linters:
29+
- lll
30+
source: "\t?// *(see )?https://"

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1313
- Type() method to the Request interface (#158)
1414
- Enumeration types for RLimitAction/iterators (#158)
1515
- IsNullable flag for Field (#302)
16+
- More linters on CI (#310)
1617

1718
### Changed
1819

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ format:
3939

4040
.PHONY: golangci-lint
4141
golangci-lint:
42-
golangci-lint run -E goimports -D errcheck
42+
golangci-lint run --config=.golangci.yaml
4343

4444
.PHONY: test
4545
test:

box_error_test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ var mpDecodeSamples = map[string]struct {
129129
"InnerMapInvalidErrorType": {
130130
[]byte{0x81, 0x00, 0x91, 0x81, 0x00, 0xc1},
131131
false,
132-
regexp.MustCompile(`msgpack: (?:unexpected|invalid|unknown) code.c1 decoding (?:string\/bytes|bytes) length`),
132+
regexp.MustCompile(`msgpack: (?:unexpected|invalid|unknown) code.c1` +
133+
` decoding (?:string\/bytes|bytes) length`),
133134
},
134135
"InnerMapInvalidErrorFile": {
135136
[]byte{0x81, 0x00, 0x91, 0x81, 0x01, 0xc1},
136137
false,
137-
regexp.MustCompile(`msgpack: (?:unexpected|invalid|unknown) code.c1 decoding (?:string\/bytes|bytes) length`),
138+
regexp.MustCompile(`msgpack: (?:unexpected|invalid|unknown) code.c1` +
139+
` decoding (?:string\/bytes|bytes) length`),
138140
},
139141
"InnerMapInvalidErrorLine": {
140142
[]byte{0x81, 0x00, 0x91, 0x81, 0x02, 0xc1},
@@ -144,7 +146,8 @@ var mpDecodeSamples = map[string]struct {
144146
"InnerMapInvalidErrorMessage": {
145147
[]byte{0x81, 0x00, 0x91, 0x81, 0x03, 0xc1},
146148
false,
147-
regexp.MustCompile(`msgpack: (?:unexpected|invalid|unknown) code.c1 decoding (?:string\/bytes|bytes) length`),
149+
regexp.MustCompile(`msgpack: (?:unexpected|invalid|unknown) code.c1 decoding` +
150+
` (?:string\/bytes|bytes) length`),
148151
},
149152
"InnerMapInvalidErrorErrno": {
150153
[]byte{0x81, 0x00, 0x91, 0x81, 0x04, 0xc1},
@@ -164,7 +167,8 @@ var mpDecodeSamples = map[string]struct {
164167
"InnerMapInvalidErrorFieldsKey": {
165168
[]byte{0x81, 0x00, 0x91, 0x81, 0x06, 0x81, 0xc1},
166169
false,
167-
regexp.MustCompile(`msgpack: (?:unexpected|invalid|unknown) code.c1 decoding (?:string\/bytes|bytes) length`),
170+
regexp.MustCompile(`msgpack: (?:unexpected|invalid|unknown) code.c1` +
171+
` decoding (?:string\/bytes|bytes) length`),
168172
},
169173
"InnerMapInvalidErrorFieldsValue": {
170174
[]byte{0x81, 0x00, 0x91, 0x81, 0x06, 0x81, 0xa3, 0x6b, 0x65, 0x79, 0xc1},
@@ -435,7 +439,8 @@ func TestErrorTypeSelect(t *testing.T) {
435439
var resp *Response
436440
var offset uint32 = 0
437441
var limit uint32 = 1
438-
resp, err = conn.Select(space, index, offset, limit, IterEq, []interface{}{testcase.tuple.pk})
442+
resp, err = conn.Select(space, index, offset, limit, IterEq,
443+
[]interface{}{testcase.tuple.pk})
439444
require.Nil(t, err)
440445
require.NotNil(t, resp.Data)
441446
require.Equalf(t, len(resp.Data), 1, "Exactly one tuple had been found")
@@ -479,7 +484,8 @@ func TestErrorTypeSelectTyped(t *testing.T) {
479484
var offset uint32 = 0
480485
var limit uint32 = 1
481486
var resp []TupleBoxError
482-
err = conn.SelectTyped(space, index, offset, limit, IterEq, []interface{}{testcase.tuple.pk}, &resp)
487+
err = conn.SelectTyped(space, index, offset, limit, IterEq,
488+
[]interface{}{testcase.tuple.pk}, &resp)
483489
require.Nil(t, err)
484490
require.NotNil(t, resp)
485491
require.Equalf(t, len(resp), 1, "Exactly one tuple had been found")

connection.go

+22-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ const shutdownEventKey = "box.shutdown"
3333
type ConnEventKind int
3434
type ConnLogKind int
3535

36+
var (
37+
errUnknownRequest = errors.New("the passed connected request doesn't belong " +
38+
"to the current connection or connection pool")
39+
)
40+
3641
const (
3742
// Connected signals that connection is established or reestablished.
3843
Connected ConnEventKind = iota + 1
@@ -84,13 +89,16 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
8489
case LogReconnectFailed:
8590
reconnects := v[0].(uint)
8691
err := v[1].(error)
87-
log.Printf("tarantool: reconnect (%d/%d) to %s failed: %s", reconnects, conn.opts.MaxReconnects, conn.addr, err)
92+
log.Printf("tarantool: reconnect (%d/%d) to %s failed: %s",
93+
reconnects, conn.opts.MaxReconnects, conn.addr, err)
8894
case LogLastReconnectFailed:
8995
err := v[0].(error)
90-
log.Printf("tarantool: last reconnect to %s failed: %s, giving it up", conn.addr, err)
96+
log.Printf("tarantool: last reconnect to %s failed: %s, giving it up",
97+
conn.addr, err)
9198
case LogUnexpectedResultId:
9299
resp := v[0].(*Response)
93-
log.Printf("tarantool: connection %s got unexpected resultId (%d) in response", conn.addr, resp.RequestId)
100+
log.Printf("tarantool: connection %s got unexpected resultId (%d) in response",
101+
conn.addr, resp.RequestId)
94102
case LogWatchEventReadFailed:
95103
err := v[0].(error)
96104
log.Printf("tarantool: unable to parse watch event: %s", err)
@@ -145,7 +153,8 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
145153
// by timeout). Client reconnect will happen if connection options enable
146154
// reconnect. Beware that graceful shutdown event initialization is asynchronous.
147155
//
148-
// More on graceful shutdown: https://www.tarantool.io/en/doc/latest/dev_guide/internals/iproto/graceful_shutdown/
156+
// More on graceful shutdown:
157+
// https://www.tarantool.io/en/doc/latest/dev_guide/internals/iproto/graceful_shutdown/
149158
type Connection struct {
150159
addr string
151160
c Conn
@@ -579,7 +588,8 @@ func (conn *Connection) dial() (err error) {
579588
go conn.reader(c, c)
580589

581590
// Subscribe shutdown event to process graceful shutdown.
582-
if conn.shutdownWatcher == nil && isFeatureInSlice(WatchersFeature, conn.serverProtocolInfo.Features) {
591+
if conn.shutdownWatcher == nil &&
592+
isFeatureInSlice(WatchersFeature, conn.serverProtocolInfo.Features) {
583593
watcher, werr := conn.newWatcherImpl(shutdownEventKey, shutdownEventCallback)
584594
if werr != nil {
585595
return werr
@@ -696,7 +706,10 @@ func (conn *Connection) closeConnection(neterr error, forever bool) (err error)
696706
}
697707
for i := range conn.shard {
698708
conn.shard[i].buf.Reset()
699-
requestsLists := []*[requestsMap]futureList{&conn.shard[i].requests, &conn.shard[i].requestsWithCtx}
709+
requestsLists := []*[requestsMap]futureList{
710+
&conn.shard[i].requests,
711+
&conn.shard[i].requestsWithCtx,
712+
}
700713
for _, requests := range requestsLists {
701714
for pos := range requests {
702715
requests[pos].clear(neterr, conn)
@@ -1207,7 +1220,7 @@ func read(r io.Reader, lenbuf []byte) (response []byte, err error) {
12071220
return
12081221
}
12091222
if lenbuf[0] != 0xce {
1210-
err = errors.New("Wrong response header")
1223+
err = errors.New("wrong response header")
12111224
return
12121225
}
12131226
length = (int(lenbuf[1]) << 24) +
@@ -1216,7 +1229,7 @@ func read(r io.Reader, lenbuf []byte) (response []byte, err error) {
12161229
int(lenbuf[4])
12171230

12181231
if length == 0 {
1219-
err = errors.New("Response should not be 0 length")
1232+
err = errors.New("response should not be 0 length")
12201233
return
12211234
}
12221235
response = make([]byte, length)
@@ -1241,7 +1254,7 @@ func (conn *Connection) Do(req Request) *Future {
12411254
if connectedReq, ok := req.(ConnectedRequest); ok {
12421255
if connectedReq.Conn() != conn {
12431256
fut := NewFuture()
1244-
fut.SetError(fmt.Errorf("the passed connected request doesn't belong to the current connection or connection pool"))
1257+
fut.SetError(errUnknownRequest)
12451258
return fut
12461259
}
12471260
}

connector.go

+28-24
Original file line numberDiff line numberDiff line change
@@ -13,78 +13,82 @@ type Connector interface {
1313

1414
// Deprecated: the method will be removed in the next major version,
1515
// use a PingRequest object + Do() instead.
16-
Ping() (resp *Response, err error)
16+
Ping() (*Response, error)
1717
// Deprecated: the method will be removed in the next major version,
1818
// use a SelectRequest object + Do() instead.
19-
Select(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) (resp *Response, err error)
19+
Select(space, index interface{}, offset, limit uint32, iterator Iter,
20+
key interface{}) (*Response, error)
2021
// Deprecated: the method will be removed in the next major version,
2122
// use an InsertRequest object + Do() instead.
22-
Insert(space interface{}, tuple interface{}) (resp *Response, err error)
23+
Insert(space interface{}, tuple interface{}) (*Response, error)
2324
// Deprecated: the method will be removed in the next major version,
2425
// use a ReplicaRequest object + Do() instead.
25-
Replace(space interface{}, tuple interface{}) (resp *Response, err error)
26+
Replace(space interface{}, tuple interface{}) (*Response, error)
2627
// Deprecated: the method will be removed in the next major version,
2728
// use a DeleteRequest object + Do() instead.
28-
Delete(space, index interface{}, key interface{}) (resp *Response, err error)
29+
Delete(space, index interface{}, key interface{}) (*Response, error)
2930
// Deprecated: the method will be removed in the next major version,
3031
// use a UpdateRequest object + Do() instead.
31-
Update(space, index interface{}, key, ops interface{}) (resp *Response, err error)
32+
Update(space, index interface{}, key, ops interface{}) (*Response, error)
3233
// Deprecated: the method will be removed in the next major version,
3334
// use a UpsertRequest object + Do() instead.
34-
Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error)
35+
Upsert(space interface{}, tuple, ops interface{}) (*Response, error)
3536
// Deprecated: the method will be removed in the next major version,
3637
// use a CallRequest object + Do() instead.
37-
Call(functionName string, args interface{}) (resp *Response, err error)
38+
Call(functionName string, args interface{}) (*Response, error)
3839
// Deprecated: the method will be removed in the next major version,
3940
// use a Call16Request object + Do() instead.
40-
Call16(functionName string, args interface{}) (resp *Response, err error)
41+
Call16(functionName string, args interface{}) (*Response, error)
4142
// Deprecated: the method will be removed in the next major version,
4243
// use a Call17Request object + Do() instead.
43-
Call17(functionName string, args interface{}) (resp *Response, err error)
44+
Call17(functionName string, args interface{}) (*Response, error)
4445
// Deprecated: the method will be removed in the next major version,
4546
// use an EvalRequest object + Do() instead.
46-
Eval(expr string, args interface{}) (resp *Response, err error)
47+
Eval(expr string, args interface{}) (*Response, error)
4748
// Deprecated: the method will be removed in the next major version,
4849
// use an ExecuteRequest object + Do() instead.
49-
Execute(expr string, args interface{}) (resp *Response, err error)
50+
Execute(expr string, args interface{}) (*Response, error)
5051

5152
// Deprecated: the method will be removed in the next major version,
5253
// use a SelectRequest object + Do() instead.
53-
GetTyped(space, index interface{}, key interface{}, result interface{}) (err error)
54+
GetTyped(space, index interface{}, key interface{}, result interface{}) error
5455
// Deprecated: the method will be removed in the next major version,
5556
// use a SelectRequest object + Do() instead.
56-
SelectTyped(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}, result interface{}) (err error)
57+
SelectTyped(space, index interface{}, offset, limit uint32, iterator Iter, key interface{},
58+
result interface{}) error
5759
// Deprecated: the method will be removed in the next major version,
5860
// use an InsertRequest object + Do() instead.
59-
InsertTyped(space interface{}, tuple interface{}, result interface{}) (err error)
61+
InsertTyped(space interface{}, tuple interface{}, result interface{}) error
6062
// Deprecated: the method will be removed in the next major version,
6163
// use a ReplaceRequest object + Do() instead.
62-
ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error)
64+
ReplaceTyped(space interface{}, tuple interface{}, result interface{}) error
6365
// Deprecated: the method will be removed in the next major version,
6466
// use a DeleteRequest object + Do() instead.
65-
DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error)
67+
DeleteTyped(space, index interface{}, key interface{}, result interface{}) error
6668
// Deprecated: the method will be removed in the next major version,
6769
// use a UpdateRequest object + Do() instead.
68-
UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error)
70+
UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) error
6971
// Deprecated: the method will be removed in the next major version,
7072
// use a CallRequest object + Do() instead.
71-
CallTyped(functionName string, args interface{}, result interface{}) (err error)
73+
CallTyped(functionName string, args interface{}, result interface{}) error
7274
// Deprecated: the method will be removed in the next major version,
7375
// use a Call16Request object + Do() instead.
74-
Call16Typed(functionName string, args interface{}, result interface{}) (err error)
76+
Call16Typed(functionName string, args interface{}, result interface{}) error
7577
// Deprecated: the method will be removed in the next major version,
7678
// use a Call17Request object + Do() instead.
77-
Call17Typed(functionName string, args interface{}, result interface{}) (err error)
79+
Call17Typed(functionName string, args interface{}, result interface{}) error
7880
// Deprecated: the method will be removed in the next major version,
7981
// use an EvalRequest object + Do() instead.
80-
EvalTyped(expr string, args interface{}, result interface{}) (err error)
82+
EvalTyped(expr string, args interface{}, result interface{}) error
8183
// Deprecated: the method will be removed in the next major version,
8284
// use an ExecuteRequest object + Do() instead.
83-
ExecuteTyped(expr string, args interface{}, result interface{}) (SQLInfo, []ColumnMetaData, error)
85+
ExecuteTyped(expr string, args interface{},
86+
result interface{}) (SQLInfo, []ColumnMetaData, error)
8487

8588
// Deprecated: the method will be removed in the next major version,
8689
// use a SelectRequest object + Do() instead.
87-
SelectAsync(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) *Future
90+
SelectAsync(space, index interface{}, offset, limit uint32, iterator Iter,
91+
key interface{}) *Future
8892
// Deprecated: the method will be removed in the next major version,
8993
// use an InsertRequest object + Do() instead.
9094
InsertAsync(space interface{}, tuple interface{}) *Future

crud/error.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ func (e *Error) DecodeMsgpack(d *msgpack.Decoder) error {
7070
}
7171

7272
// Error converts an Error to a string.
73-
func (err Error) Error() string {
74-
return err.Str
73+
func (e Error) Error() string {
74+
return e.Str
7575
}
7676

7777
// ErrorMany describes CRUD error object for `_many` methods.
@@ -104,9 +104,9 @@ func (e *ErrorMany) DecodeMsgpack(d *msgpack.Decoder) error {
104104
}
105105

106106
// Error converts an Error to a string.
107-
func (errs ErrorMany) Error() string {
107+
func (e ErrorMany) Error() string {
108108
var str []string
109-
for _, err := range errs.Errors {
109+
for _, err := range e.Errors {
110110
str = append(str, err.Str)
111111
}
112112

0 commit comments

Comments
 (0)