Skip to content

Commit 9cf86bc

Browse files
authored
Merge pull request #92 from lightninglabs/updateLinterRUles
.golangci: update linter rules
2 parents a6dd981 + 97d93d2 commit 9cf86bc

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

.golangci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,42 @@ linters-settings:
1515
govet:
1616
# Don't report about shadowed variables
1717
check-shadowing: false
18+
1819
gofmt:
1920
# simplify code: gofmt with `-s` option, true by default
2021
simplify: true
22+
2123
funlen:
2224
# Checks the number of lines in a function.
2325
# If lower than 0, disable the check.
2426
lines: 200
2527
# Checks the number of statements in a function.
2628
statements: 80
29+
2730
gosec:
2831
excludes:
2932
- G402 # Look for bad TLS connection settings.
3033
- G306 # Poor file permissions used when writing to a new file.
3134

35+
whitespace:
36+
multi-func: true
37+
multi-if: true
38+
3239
linters:
3340
enable-all: true
3441
disable:
42+
# Allow dynamic errors.
43+
- goerr113
44+
45+
# We want to allow short variable names.
46+
- varnamelen
47+
48+
# Allow tests to be put in the same package.
49+
- testpackage
50+
51+
# We want to allow TODOs.
52+
- godox
53+
3554
# Init functions are used by loggers throughout the codebase.
3655
- gochecknoinits
3756

@@ -46,6 +65,17 @@ linters:
4665
# instances are created.
4766
- exhaustruct
4867

68+
# Disable gofumpt as it has weird behavior regarding formatting multiple
69+
# lines for a function which is in conflict with our contribution
70+
# guidelines. See https://github.com/mvdan/gofumpt/issues/235.
71+
- gofumpt
72+
73+
# Disable whitespace linter as it has conflict rules against our
74+
# contribution guidelines. See https://github.com/bombsimon/wsl/issues/109.
75+
#
76+
# TODO: bring it back when the above issue is fixed.
77+
- wsl
78+
4979
# Deprecated linters. See https://golangci-lint.run/usage/linters/.
5080
- interfacer
5181
- golint

gbn/gbn_client.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ func NewClientConn(ctx context.Context, n uint8, sendFunc sendBytesFunc,
4141

4242
// clientHandshake initiates the client side GBN handshake.
4343
// The handshake sequence from the client side is as follows:
44-
// 1. The client sends SYN to the server along with the N value that the
45-
// client wishes to use for the connection.
46-
// 2. The client then waits for the server to respond with SYN.
47-
// 3a. If the client receives SYN from the server then the client sends back
48-
// SYNACK.
44+
// 1. The client sends SYN to the server along with the N value that the
45+
// client wishes to use for the connection.
46+
// 2. The client then waits for the server to respond with SYN.
47+
// 3a. If the client receives SYN from the server, then the client sends back
48+
// SYNACK.
4949
// 3b. If the client does not receive SYN from the server within a given
50-
// timeout, then the client restarts the handshake from step 1.
50+
// timeout, then the client restarts the handshake from step 1.
5151
func (g *GoBackNConn) clientHandshake() error {
5252
// Spin off the recv function in a goroutine so that we can use
5353
// a select to choose to timeout waiting for data from the receive
@@ -94,7 +94,10 @@ func (g *GoBackNConn) clientHandshake() error {
9494
}
9595
}()
9696

97-
var resp Message
97+
var (
98+
resp Message
99+
respSYN *PacketSYN
100+
)
98101
handshake:
99102
for {
100103
// start Handshake
@@ -142,8 +145,10 @@ handshake:
142145
}
143146

144147
log.Debugf("Client got %T", resp)
145-
switch resp.(type) {
148+
switch r := resp.(type) {
146149
case *PacketSYN:
150+
respSYN = r
151+
147152
break handshake
148153
default:
149154
}
@@ -155,7 +160,8 @@ handshake:
155160
}
156161

157162
log.Debugf("Client got SYN")
158-
if resp.(*PacketSYN).N != g.n {
163+
164+
if respSYN.N != g.n {
159165
return io.EOF
160166
}
161167

gbn/gbn_conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type GoBackNConn struct {
9797
pongTicker *IntervalAwareForceTicker
9898
pongWait chan struct{}
9999

100-
ctx context.Context
100+
ctx context.Context //nolint:containedctx
101101
cancel func()
102102

103103
// remoteClosed is closed if the remote party initiated the FIN sequence.

mailbox/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Server struct {
2626

2727
sid [64]byte
2828

29-
ctx context.Context
29+
ctx context.Context //nolint:containedctx
3030

3131
quit chan struct{}
3232
cancel func()

0 commit comments

Comments
 (0)