Skip to content

Commit e1fc30d

Browse files
committed
* first implementation
* migration from golangci-lint v1 to v2
1 parent 872ba58 commit e1fc30d

File tree

25 files changed

+1080
-154
lines changed

25 files changed

+1080
-154
lines changed

.golangci.yml

Lines changed: 170 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,175 @@
1+
version: "2"
2+
13
linters:
4+
default: all
5+
disable:
6+
- wsl
7+
- wrapcheck
8+
- unqueryvet
9+
- testpackage
10+
- testifylint
11+
- modernize
12+
- funcorder
13+
- depguard
14+
- noinlineerr
15+
- nonamedreturns
16+
17+
settings:
18+
varnamelen:
19+
ignore-names:
20+
- tr
21+
- tx
22+
- t
23+
- xtx
24+
- sp
25+
- in
26+
- s
27+
- oo
28+
ignore-decls:
29+
- wg sync.WaitGroup
30+
- wg *sync.WaitGroup
31+
- db *gorm.DB
32+
- db redis.UniversalClient
33+
- m Manager
34+
wsl_v5:
35+
default: all
36+
disable:
37+
- assign
38+
- assign-exclusive
39+
- assign-expr
40+
staticcheck:
41+
checks:
42+
- "all"
43+
- "-ST1000"
44+
- "-ST1003"
45+
- "-ST1016"
46+
- "-ST1020"
47+
- "-ST1021"
48+
- "-ST1022"
49+
- "-QF1008"
50+
51+
exclusions:
52+
generated: lax
53+
54+
paths:
55+
- trm/manager/mock
56+
- sql/mock
57+
58+
rules:
59+
- linters:
60+
- staticcheck
61+
text: 'ST1000:'
62+
63+
- linters:
64+
- lll
65+
source: '^//go:generate '
66+
67+
- linters:
68+
- lll
69+
source: '(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&''\\(\\)\\*\\+,;=.]+'
70+
71+
- linters:
72+
- lll
73+
source: '// ?TODO '
74+
75+
- linters:
76+
- lll
77+
source: 'func \(r \*readonlyFuncWithoutTxDecorator\)'
78+
79+
- path: '_test\.go'
80+
linters:
81+
- wsl_v5
82+
text: 'only cuddled expressions if assigning variable or using from line above'
83+
84+
- path: '_test\.go'
85+
linters:
86+
- wsl_v5
87+
text: 'assignments should only be cuddled with other assignments'
88+
89+
- path: '.*_test\.go'
90+
source: 't\.Run\('
91+
linters:
92+
- wsl_v5
93+
text: 'missing whitespace above this line'
94+
95+
- path: '_test\.go'
96+
linters:
97+
- revive
98+
text: 'seems to be unused, consider removing or renaming it as _'
99+
100+
- path: '_test\.go'
101+
linters:
102+
- revive
103+
text: 'context-keys-type: should not use basic type string as key in context.WithValue'
104+
105+
- path: '_test\.go'
106+
linters:
107+
- revive
108+
text: 'context-keys-type: should not use basic type untyped string as key in context.WithValue'
109+
110+
- path: '_test\.go'
111+
linters:
112+
- staticcheck
113+
text: 'SA1029: should not use built-in type string as key for value; define your own type to avoid collisions'
114+
115+
- path: '(.+/)?context\.go'
116+
linters:
117+
- ireturn
118+
119+
- path: '(.+/)?transaction\.go'
120+
linters:
121+
- ireturn
122+
source: '\) Begin\(ctx'
123+
124+
- path: '(.+/)?settings\.go'
125+
linters:
126+
- ireturn
127+
source: '(?:EnrichBy|SetPropagation|SetCtxKey|CtxKey|SetCancelable|SetTimeout)'
128+
129+
- linters:
130+
- gochecknoglobals
131+
source: 'DefaultCtxGetter'
132+
133+
- path: '_test\.go'
134+
source: 'prepare: func\('
135+
text: 'test helper function should start from t.Helper()'
136+
linters:
137+
- thelper
138+
139+
- &internal_text
140+
path: '(^trm/internal|^internal)'
141+
text: 'var-naming: don''t use an underscore in package name'
142+
143+
- <<: *internal_text
144+
text: 'package-comments: should have a package comment'
145+
146+
- <<: *internal_text
147+
text: 'ST1003: should not use underscores in package names'
148+
149+
- path: '(_test\.go|^trm/internal|^internal)'
150+
linters:
151+
- funlen
152+
- gochecknoglobals
153+
- goconst
154+
- gomnd
155+
- containedctx
156+
- err113
157+
- errcheck
158+
- nolintlint
159+
- forcetypeassert
160+
- exhaustruct
161+
- varnamelen
162+
- noinlineerr
163+
- cyclop
164+
- noctx
165+
166+
formatters:
2167
enable:
3-
- asasalint
4-
- bodyclose
5-
- containedctx
6-
- contextcheck
7-
- dogsled
8-
- dupl
9-
- durationcheck
10-
- errchkjson
11-
- errname
12-
- errorlint
13-
- exhaustive
14-
- exhaustruct
15-
- forcetypeassert # https://github.com/gostaticanalysis/forcetypeassert#forcetypeassert
16-
- funlen
17-
- gochecknoglobals
18-
- gochecknoinits
19-
- gocognit
20-
- goconst
21-
- gocritic
22-
- gocyclo
23-
- godot
24-
- err113
25168
- gofmt
26169
- gofumpt
27170
- goimports
28-
- gomoddirectives
29-
- goprintffuncname # https://github.com/jirfag/go-printf-func-name#go-printf-func-name
30-
- grouper
31-
- gosec
32-
- importas
33-
- interfacebloat
34-
- ireturn
35-
- lll
36-
- makezero # https://github.com/ashanbrown/makezero#purpose
37-
- misspell
38-
- nakedret
39-
- nestif
40-
- nilerr # https://github.com/gostaticanalysis/nilerr#nilerr
41-
- nilnil # https://github.com/Antonboom/nilnil#motivation
42-
- nolintlint # https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/nolintlint/README.md#purpose
43-
- paralleltest
44-
- prealloc # https://github.com/alexkohler/prealloc#purpose
45-
- revive
46-
- rowserrcheck
47-
- sqlclosecheck
48-
- stylecheck
49-
- tagliatelle
50-
- tparallel # https://github.com/moricho/tparallel
51-
- unconvert # https://github.com/mdempsky/unconvert#usage
52-
- unparam
53-
- usestdlibvars
54-
- wastedassign
55-
- whitespace
56-
- wsl # https://github.com/bombsimon/wsl/blob/master/doc/rules.md
57-
58-
linters-settings:
59-
wsl:
60-
allow-assign-and-anything: true
61-
62-
issues:
63-
exclude-dirs:
64-
- trm/manager/mock
65-
- sql/mock
66-
exclude-use-default: false
67-
exclude:
68-
- ST1000 # ST1000: at least one file in a package should have a package comment
69-
exclude-rules:
70-
- linters:
71-
- lll
72-
source: "^//go:generate "
73-
- linters:
74-
- lll
75-
source: "(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+"
76-
- linters:
77-
- lll
78-
source: "// ?TODO "
79-
- path: _test\.go
80-
linters:
81-
- wsl
82-
text: "only cuddled expressions if assigning variable or using from line above"
83-
- path: _test\.go
84-
linters:
85-
- wsl
86-
text: "assignments should only be cuddled with other assignments"
87-
- path: _test\.go
88-
linters:
89-
- revive
90-
text: "seems to be unused, consider removing or renaming it as _"
91-
- path: _test\.go
92-
linters:
93-
- revive
94-
text: "context-keys-type: should not use basic type string as key in context.WithValue"
95-
- path: _test\.go
96-
linters:
97-
- revive
98-
text: "context-keys-type: should not use basic type untyped string as key in context.WithValue"
99-
- path: _test\.go
100-
linters:
101-
- staticcheck
102-
text: "SA1029: should not use built-in type string as key for value; define your own type to avoid collisions"
103-
- path: (.+/)?context\.go
104-
linters:
105-
- ireturn
106-
- path: (.+/)?transaction\.go
107-
linters:
108-
- ireturn
109-
source: \) Begin\(ctx
110-
- path: (.+/)?settings\.go
111-
linters:
112-
- ireturn
113-
source: "(?:EnrichBy|SetPropagation|SetCtxKey|CtxKey|SetCancelable|SetTimeout)"
114-
- linters:
115-
- gochecknoglobals
116-
source: "DefaultCtxGetter"
117-
- &internal_text
118-
path: (^trm/internal|^internal)
119-
text: "var-naming: don't use an underscore in package name"
120-
- <<: *internal_text
121-
text: "package-comments: should have a package comment"
122-
- <<: *internal_text
123-
text: "ST1003: should not use underscores in package names"
124-
- path: (_test\.go|^trm/internal|^internal)
125-
linters:
126-
- funlen
127-
- gochecknoglobals
128-
- goconst
129-
- gomnd
130-
- containedctx
131-
- err113
132-
- errcheck
133-
- nolintlint
134-
- forcetypeassert
135-
- exhaustruct
171+
172+
exclusions:
173+
paths:
174+
- trm/manager/mock
175+
- sql/mock

drivers/goredis8/readonly_func_without_tx.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
// readonlyFuncWithoutTxDecorator calls readonly commands outside of a transaction.
1010
type readonlyFuncWithoutTxDecorator struct {
1111
Cmdable
12+
1213
readOnly redis.Cmdable
1314
}
1415

@@ -199,12 +200,12 @@ func (r *readonlyFuncWithoutTxDecorator) ZCard(ctx context.Context, key string)
199200
return r.readOnly.ZCard(ctx, key)
200201
}
201202

202-
func (r *readonlyFuncWithoutTxDecorator) ZCount(ctx context.Context, key, min, max string) *redis.IntCmd {
203-
return r.readOnly.ZCount(ctx, key, min, max)
203+
func (r *readonlyFuncWithoutTxDecorator) ZCount(ctx context.Context, key, minValue, maxValue string) *redis.IntCmd {
204+
return r.readOnly.ZCount(ctx, key, minValue, maxValue)
204205
}
205206

206-
func (r *readonlyFuncWithoutTxDecorator) ZLexCount(ctx context.Context, key, min, max string) *redis.IntCmd {
207-
return r.readOnly.ZLexCount(ctx, key, min, max)
207+
func (r *readonlyFuncWithoutTxDecorator) ZLexCount(ctx context.Context, key, minValue, maxValue string) *redis.IntCmd {
208+
return r.readOnly.ZLexCount(ctx, key, minValue, maxValue)
208209
}
209210

210211
func (r *readonlyFuncWithoutTxDecorator) ZInter(ctx context.Context, store *redis.ZStore) *redis.StringSliceCmd {

drivers/goredis8/readonly_func_without_tx_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const (
3939

4040
group = "group"
4141

42-
min = "min"
43-
max = "max"
42+
minValue = "min"
43+
maxValue = "max"
4444
)
4545

4646
var (
@@ -57,6 +57,8 @@ func newReadOnlyFuncWithoutTxDecorator() (Cmdable, redismock.ClientMock) {
5757
}
5858

5959
func check(t *testing.T, cmd redis.Cmder, mock redismock.ClientMock) {
60+
t.Helper()
61+
6062
require.NoError(t, cmd.Err())
6163
require.NoError(t, mock.ExpectationsWereMet())
6264
}
@@ -573,9 +575,9 @@ func Test_readonlyFuncWithoutTxDecorator_ZCount(t *testing.T) {
573575
t.Parallel()
574576

575577
cmdable, mock := newReadOnlyFuncWithoutTxDecorator()
576-
mock.ExpectZCount(key1, min, max).SetVal(0)
578+
mock.ExpectZCount(key1, minValue, maxValue).SetVal(0)
577579

578-
cmd := cmdable.ZCount(context.Background(), key1, min, max)
580+
cmd := cmdable.ZCount(context.Background(), key1, minValue, maxValue)
579581

580582
check(t, cmd, mock)
581583
}
@@ -584,9 +586,9 @@ func Test_readonlyFuncWithoutTxDecorator_ZLexCount(t *testing.T) {
584586
t.Parallel()
585587

586588
cmdable, mock := newReadOnlyFuncWithoutTxDecorator()
587-
mock.ExpectZLexCount(key1, min, max).SetVal(0)
589+
mock.ExpectZLexCount(key1, minValue, maxValue).SetVal(0)
588590

589-
cmd := cmdable.ZLexCount(context.Background(), key1, min, max)
591+
cmd := cmdable.ZLexCount(context.Background(), key1, minValue, maxValue)
590592

591593
check(t, cmd, mock)
592594
}

drivers/goredis8/settings.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Opt func(*Settings) error
1919
// Settings contains settings for redis.Transaction.
2020
type Settings struct {
2121
trm.Settings
22+
2223
isMulti *bool
2324
watchKeys []string
2425
txDecorator []TxDecorator
@@ -97,7 +98,8 @@ func (s *Settings) IsMultiOrNil() *bool {
9798
return s.isMulti
9899
}
99100

100-
// SetIsMulti set using or not Multi for transaction, see https://redis.uptrace.dev/guide/go-redis-pipelines.html#transactions.
101+
// SetIsMulti set using or not Multi for transaction,
102+
// see https://redis.uptrace.dev/guide/go-redis-pipelines.html#transactions.
101103
func (s *Settings) SetIsMulti(in *bool) *Settings {
102104
return s.setIsMulti(in)
103105
}

0 commit comments

Comments
 (0)