Skip to content

Commit 553a201

Browse files
fix: fix lint issues and update golangci-lint configuration
1 parent 996a76e commit 553a201

File tree

31 files changed

+218
-138
lines changed

31 files changed

+218
-138
lines changed

.golangci.bck.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
run:
2+
timeout: 10m
3+
linters:
4+
enable:
5+
- asciicheck
6+
- bidichk
7+
- copyloopvar
8+
- dogsled
9+
- durationcheck
10+
- errcheck
11+
- errname
12+
- errorlint
13+
- forbidigo
14+
- gochecknoinits
15+
- goconst
16+
- gofmt
17+
- goheader
18+
- goprintffuncname
19+
- gosimple
20+
- govet
21+
- importas
22+
- ineffassign
23+
- misspell
24+
- nilerr
25+
- noctx
26+
- paralleltest
27+
- prealloc
28+
- predeclared
29+
- promlinter
30+
- staticcheck
31+
- thelper
32+
- typecheck
33+
- unconvert
34+
- unused
35+
# - depguard disable temporary until this issue is resolved: https://github.com/golangci/golangci-lint/issues/3906
36+
37+
linters-settings:
38+
govet:
39+
enable-all: true
40+
disable:
41+
- fieldalignment ## temporally disabled
42+
- shadow ## temporally disabled
43+
goheader:
44+
values:
45+
regexp:
46+
date: "20[1-2][0-9]"
47+
template: |-
48+
Copyright {{date}} The Swarm Authors. All rights reserved.
49+
Use of this source code is governed by a BSD-style
50+
license that can be found in the LICENSE file.
51+
paralleltest:
52+
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of `t.Parallel()`.
53+
ignore-missing: true
54+
issues:
55+
exclude-rules:
56+
- linters:
57+
- goheader
58+
text: "go-ethereum Authors" ## disable check for other authors
59+
- path: _test\.go
60+
linters:
61+
- goconst ## temporally disable goconst in test
62+
- linters:
63+
- forbidigo
64+
path: cmd/bee/cmd
65+
text: "use of `fmt.Print" ## allow fmt.Print in cmd directory
66+
- linters:
67+
- dogsled
68+
path: pkg/api/(.+)_test\.go # temporally disable dogsled in api test files
69+
- linters:
70+
- dogsled
71+
path: pkg/pushsync/(.+)_test\.go # temporally disable dogsled in pushsync test files
72+
# temporally disable paralleltest in following packages
73+
- linters:
74+
- paralleltest
75+
path: pkg/log

.golangci.yml

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,81 @@
1-
version: 2
2-
run:
3-
timeout: 10m
1+
version: "2"
42
linters:
53
enable:
64
- asciicheck
75
- bidichk
86
- copyloopvar
97
- dogsled
108
- durationcheck
11-
- errcheck
129
- errname
1310
- errorlint
1411
- forbidigo
1512
- gochecknoinits
1613
- goconst
1714
- goheader
1815
- goprintffuncname
19-
- govet
2016
- importas
21-
- ineffassign
2217
- misspell
2318
- nilerr
2419
- noctx
2520
- paralleltest
2621
- prealloc
2722
- predeclared
2823
- promlinter
29-
- staticcheck
3024
- thelper
3125
- unconvert
32-
- unused
33-
# - depguard disable temporary until this issue is resolved: https://github.com/golangci/golangci-lint/issues/3906
34-
26+
settings:
27+
goheader:
28+
values:
29+
regexp:
30+
date: 20[1-2][0-9]
31+
template: |-
32+
Copyright {{date}} The Swarm Authors. All rights reserved.
33+
Use of this source code is governed by a BSD-style
34+
license that can be found in the LICENSE file.
35+
govet:
36+
disable:
37+
- fieldalignment
38+
- shadow
39+
enable-all: true
40+
paralleltest:
41+
ignore-missing: true
42+
exclusions:
43+
generated: lax
44+
presets:
45+
- comments
46+
- common-false-positives
47+
- legacy
48+
- std-error-handling
49+
rules:
50+
- linters:
51+
- goheader
52+
text: go-ethereum Authors
53+
- linters:
54+
- goconst
55+
path: _test\.go
56+
- linters:
57+
- forbidigo
58+
path: cmd/bee/cmd
59+
text: use of `fmt.Print
60+
- linters:
61+
- dogsled
62+
path: pkg/api/(.+)_test\.go
63+
- linters:
64+
- dogsled
65+
path: pkg/pushsync/(.+)_test\.go
66+
- linters:
67+
- paralleltest
68+
path: pkg/log
69+
paths:
70+
- third_party$
71+
- builtin$
72+
- examples$
3573
formatters:
3674
enable:
3775
- gofmt
38-
39-
linters-settings:
40-
govet:
41-
enable-all: true
42-
disable:
43-
- fieldalignment ## temporally disabled
44-
- shadow ## temporally disabled
45-
goheader:
46-
values:
47-
regexp:
48-
date: "20[1-2][0-9]"
49-
template: |-
50-
Copyright {{date}} The Swarm Authors. All rights reserved.
51-
Use of this source code is governed by a BSD-style
52-
license that can be found in the LICENSE file.
53-
paralleltest:
54-
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of `t.Parallel()`.
55-
ignore-missing: true
56-
issues:
57-
exclude-rules:
58-
- linters:
59-
- goheader
60-
text: "go-ethereum Authors" ## disable check for other authors
61-
- path: _test\.go
62-
linters:
63-
- goconst ## temporally disable goconst in test
64-
- linters:
65-
- forbidigo
66-
path: cmd/bee/cmd
67-
text: "use of `fmt.Print" ## allow fmt.Print in cmd directory
68-
- linters:
69-
- dogsled
70-
path: pkg/api/(.+)_test\.go # temporally disable dogsled in api test files
71-
- linters:
72-
- dogsled
73-
path: pkg/pushsync/(.+)_test\.go # temporally disable dogsled in pushsync test files
74-
# temporally disable paralleltest in following packages
75-
- linters:
76-
- paralleltest
77-
path: pkg/log
76+
exclusions:
77+
generated: lax
78+
paths:
79+
- third_party$
80+
- builtin$
81+
- examples$

cmd/bee/cmd/split.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ func splitRefs(cmd *cobra.Command) {
116116
}
117117

118118
logger.Debug("write root", "hash", rootRef)
119-
_, err = writer.WriteString(fmt.Sprintf("%s\n", rootRef))
119+
_, err = fmt.Fprintf(writer, "%s\n", rootRef)
120120
if err != nil {
121121
return fmt.Errorf("write root hash: %w", err)
122122
}
123123
for _, ref := range refs {
124124
logger.Debug("write chunk", "hash", ref)
125-
_, err = writer.WriteString(fmt.Sprintf("%s\n", ref))
125+
_, err = fmt.Fprintf(writer, "%s\n", ref)
126126
if err != nil {
127127
return fmt.Errorf("write chunk address: %w", err)
128128
}

pkg/accesscontrol/access.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (al *ActLogic) getAccessKey(ctx context.Context, storage kvs.KeyValueStore,
129129
// Generate lookup key and access key decryption key for a given public key.
130130
func (al *ActLogic) getKeys(publicKey *ecdsa.PublicKey) ([]byte, []byte, error) {
131131
nonces := [][]byte{zeroByteArray, oneByteArray}
132-
keys, err := al.Session.Key(publicKey, nonces)
132+
keys, err := al.Key(publicKey, nonces)
133133
if len(keys) != len(nonces) {
134134
return nil, nil, err
135135
}

pkg/accesscontrol/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (c *ControllerStruct) getGranteeList(ctx context.Context, ls file.LoadSaver
261261
}
262262

263263
func (c *ControllerStruct) encryptRefForPublisher(publisherPubKey *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) {
264-
keys, err := c.access.Session.Key(publisherPubKey, [][]byte{oneByteArray})
264+
keys, err := c.access.Key(publisherPubKey, [][]byte{oneByteArray})
265265
if err != nil {
266266
return swarm.ZeroAddress, err
267267
}
@@ -275,7 +275,7 @@ func (c *ControllerStruct) encryptRefForPublisher(publisherPubKey *ecdsa.PublicK
275275
}
276276

277277
func (c *ControllerStruct) decryptRefForPublisher(publisherPubKey *ecdsa.PublicKey, encryptedRef swarm.Address) (swarm.Address, error) {
278-
keys, err := c.access.Session.Key(publisherPubKey, [][]byte{oneByteArray})
278+
keys, err := c.access.Key(publisherPubKey, [][]byte{oneByteArray})
279279
if err != nil {
280280
return swarm.ZeroAddress, err
281281
}

pkg/accesscontrol/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func TestController_UpdateHandler(t *testing.T) {
178178
publisher := getPrivKey(1)
179179
diffieHellman := accesscontrol.NewDefaultSession(publisher)
180180
al := accesscontrol.NewLogic(diffieHellman)
181-
keys, err := al.Session.Key(&publisher.PublicKey, [][]byte{{1}})
181+
keys, err := al.Key(&publisher.PublicKey, [][]byte{{1}})
182182
assertNoError(t, "Session key", err)
183183
refCipher := encryption.New(keys[0], 0, 0, sha3.NewLegacyKeccak256)
184184
ls := createLs()

pkg/accesscontrol/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s *SessionStruct) Key(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]by
3737
if publicKey == nil {
3838
return nil, ErrInvalidPublicKey
3939
}
40-
x, y := publicKey.Curve.ScalarMult(publicKey.X, publicKey.Y, s.key.D.Bytes())
40+
x, y := publicKey.ScalarMult(publicKey.X, publicKey.Y, s.key.D.Bytes())
4141
if x == nil || y == nil {
4242
return nil, ErrSecretKeyInfinity
4343
}

pkg/api/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.
266266
transport = transport.Clone()
267267
// always dial to the server address, regardless of the url host and port
268268
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
269-
return net.Dial(network, ts.Listener.Addr().String())
269+
return (&net.Dialer{}).DialContext(ctx, network, ts.Listener.Addr().String())
270270
}
271271
return transport.RoundTrip(r)
272272
}),

pkg/api/chequebook.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ func (s *Service) chequebookLastPeerHandler(w http.ResponseWriter, r *http.Reque
118118
}
119119
if err == nil {
120120
lastSentResponse = &chequebookLastChequePeerResponse{
121-
Beneficiary: lastSent.Cheque.Beneficiary.String(),
122-
Chequebook: lastSent.Cheque.Chequebook.String(),
123-
Payout: bigint.Wrap(lastSent.Cheque.CumulativePayout),
121+
Beneficiary: lastSent.Beneficiary.String(),
122+
Chequebook: lastSent.Chequebook.String(),
123+
Payout: bigint.Wrap(lastSent.CumulativePayout),
124124
}
125125
}
126126

@@ -134,9 +134,9 @@ func (s *Service) chequebookLastPeerHandler(w http.ResponseWriter, r *http.Reque
134134
}
135135
if err == nil {
136136
lastReceivedResponse = &chequebookLastChequePeerResponse{
137-
Beneficiary: lastReceived.Cheque.Beneficiary.String(),
138-
Chequebook: lastReceived.Cheque.Chequebook.String(),
139-
Payout: bigint.Wrap(lastReceived.Cheque.CumulativePayout),
137+
Beneficiary: lastReceived.Beneficiary.String(),
138+
Chequebook: lastReceived.Chequebook.String(),
139+
Payout: bigint.Wrap(lastReceived.CumulativePayout),
140140
}
141141
}
142142

@@ -179,9 +179,9 @@ func (s *Service) chequebookAllLastHandler(w http.ResponseWriter, _ *http.Reques
179179
lcr[i] = chequebookLastChequesPeerResponse{
180180
Peer: i,
181181
LastSent: &chequebookLastChequePeerResponse{
182-
Beneficiary: j.Cheque.Beneficiary.String(),
183-
Chequebook: j.Cheque.Chequebook.String(),
184-
Payout: bigint.Wrap(j.Cheque.CumulativePayout),
182+
Beneficiary: j.Beneficiary.String(),
183+
Chequebook: j.Chequebook.String(),
184+
Payout: bigint.Wrap(j.CumulativePayout),
185185
},
186186
LastReceived: nil,
187187
}
@@ -190,19 +190,19 @@ func (s *Service) chequebookAllLastHandler(w http.ResponseWriter, _ *http.Reques
190190
if _, ok := lcr[i]; ok {
191191
t := lcr[i]
192192
t.LastReceived = &chequebookLastChequePeerResponse{
193-
Beneficiary: j.Cheque.Beneficiary.String(),
194-
Chequebook: j.Cheque.Chequebook.String(),
195-
Payout: bigint.Wrap(j.Cheque.CumulativePayout),
193+
Beneficiary: j.Beneficiary.String(),
194+
Chequebook: j.Chequebook.String(),
195+
Payout: bigint.Wrap(j.CumulativePayout),
196196
}
197197
lcr[i] = t
198198
} else {
199199
lcr[i] = chequebookLastChequesPeerResponse{
200200
Peer: i,
201201
LastSent: nil,
202202
LastReceived: &chequebookLastChequePeerResponse{
203-
Beneficiary: j.Cheque.Beneficiary.String(),
204-
Chequebook: j.Cheque.Chequebook.String(),
205-
Payout: bigint.Wrap(j.Cheque.CumulativePayout),
203+
Beneficiary: j.Beneficiary.String(),
204+
Chequebook: j.Chequebook.String(),
205+
Payout: bigint.Wrap(j.CumulativePayout),
206206
},
207207
}
208208
}

pkg/bmt/proof.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Proof struct {
2020
// Hash overrides base hash function of Hasher to fill buffer with zeros until chunk length
2121
func (p Prover) Hash(b []byte) ([]byte, error) {
2222
for i := p.size; i < p.maxSize; i += len(zerosection) {
23-
_, err := p.Hasher.Write(zerosection)
23+
_, err := p.Write(zerosection)
2424
if err != nil {
2525
return nil, err
2626
}

0 commit comments

Comments
 (0)