Skip to content

Commit beba214

Browse files
committed
multi: update linter, fix issues
1 parent a4633ae commit beba214

36 files changed

+617
-1200
lines changed

.golangci.yml

+114-118
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
run:
22
# timeout for analysis
3-
deadline: 4m
4-
5-
skip-files:
6-
- "\\.pb\\.go$"
7-
- "\\.pb\\.gw\\.go$"
3+
timeout: 4m
4+
5+
go: "1.23"
86

97
linters-settings:
108
govet:
119
# Don't report about shadowed variables
12-
check-shadowing: false
10+
shadowing: false
1311

1412
gofmt:
1513
# simplify code: gofmt with `-s` option, true by default
@@ -28,126 +26,124 @@ linters-settings:
2826
excludes:
2927
- G402 # Look for bad TLS connection settings.
3028
- G306 # Poor file permissions used when writing to a new file.
29+
- G115 # Integer overflow conversion.
3130

32-
staticcheck:
33-
go: "1.18"
34-
checks: ["-SA1019"]
31+
staticcheck:
32+
checks: [ "-SA1019" ]
3533

3634
linters:
3735
enable-all: true
3836
disable:
39-
# Global variables are used in many places throughout the code base.
40-
- gochecknoglobals
41-
42-
# Some lines are over 80 characters on purpose and we don't want to make them
43-
# even longer by marking them as 'nolint'.
44-
- lll
45-
46-
# We want to allow short variable names.
47-
- varnamelen
48-
49-
# We want to allow TODOs.
50-
- godox
51-
52-
# We have long functions, especially in tests. Moving or renaming those would
53-
# trigger funlen problems that we may not want to solve at that time.
54-
- funlen
55-
56-
# Disable for now as we haven't yet tuned the sensitivity to our codebase
57-
# yet. Enabling by default for example, would also force new contributors to
58-
# potentially extensively refactor code, when they want to smaller change to
59-
# land.
60-
- gocyclo
61-
- gocognit
62-
- cyclop
63-
64-
# Instances of table driven tests that don't pre-allocate shouldn't trigger
65-
# the linter.
66-
- prealloc
67-
68-
# Init functions are used by loggers throughout the codebase.
69-
- gochecknoinits
70-
71-
# Causes stack overflow, see https://github.com/polyfloyd/go-errorlint/issues/19.
72-
- errorlint
73-
74-
# Deprecated linters. See https://golangci-lint.run/usage/linters/.
75-
- interfacer
76-
- golint
77-
- maligned
78-
- scopelint
79-
- varcheck
80-
- structcheck
81-
- deadcode
82-
83-
# New linters that need a code adjustment first.
84-
- wrapcheck
85-
- nolintlint
86-
- paralleltest
87-
- tparallel
88-
- testpackage
89-
- gofumpt
90-
- gomoddirectives
91-
- ireturn
92-
- maintidx
93-
- nlreturn
94-
- dogsled
95-
- gci
96-
- containedctx
97-
- contextcheck
98-
- errname
99-
- exhaustivestruct
100-
- goerr113
101-
- gomnd
102-
- ifshort
103-
- noctx
104-
- nestif
105-
- wsl
106-
- exhaustive
107-
- forcetypeassert
108-
- nilerr
109-
- nilnil
110-
- stylecheck
111-
- thelper
112-
- revive
113-
- tagalign
114-
- depguard
115-
- nosnakecase
116-
- interfacebloat
117-
118-
# Additions compared to LND
119-
- exhaustruct
37+
# Global variables are used in many places throughout the code base.
38+
- gochecknoglobals
39+
40+
# Some lines are over 80 characters on purpose and we don't want to make them
41+
# even longer by marking them as 'nolint'.
42+
- lll
43+
44+
# We want to allow short variable names.
45+
- varnamelen
46+
47+
# We want to allow TODOs.
48+
- godox
49+
50+
# We have long functions, especially in tests. Moving or renaming those would
51+
# trigger funlen problems that we may not want to solve at that time.
52+
- funlen
53+
54+
# Disable for now as we haven't yet tuned the sensitivity to our codebase
55+
# yet. Enabling by default for example, would also force new contributors to
56+
# potentially extensively refactor code, when they want to smaller change to
57+
# land.
58+
- gocyclo
59+
- gocognit
60+
- cyclop
61+
62+
# Instances of table driven tests that don't pre-allocate shouldn't trigger
63+
# the linter.
64+
- prealloc
65+
66+
# Init functions are used by loggers throughout the codebase.
67+
- gochecknoinits
68+
69+
# Causes stack overflow, see https://github.com/polyfloyd/go-errorlint/issues/19.
70+
- errorlint
71+
72+
# New linters that need a code adjustment first.
73+
- wrapcheck
74+
- nolintlint
75+
- paralleltest
76+
- tparallel
77+
- testpackage
78+
- gofumpt
79+
- gomoddirectives
80+
- ireturn
81+
- maintidx
82+
- nlreturn
83+
- dogsled
84+
- gci
85+
- containedctx
86+
- contextcheck
87+
- errname
88+
- err113
89+
- mnd
90+
- noctx
91+
- nestif
92+
- wsl
93+
- exhaustive
94+
- forcetypeassert
95+
- nilerr
96+
- nilnil
97+
- stylecheck
98+
- thelper
99+
- revive
100+
- tagalign
101+
- depguard
102+
- interfacebloat
103+
- inamedparam
104+
- intrange
105+
- perfsprint
106+
- protogetter
107+
- testifylint
108+
109+
# Additions compared to LND
110+
- exhaustruct
120111

121112
issues:
122113
# Only show newly introduced problems.
123114
new-from-rev: 36838cf7f464cf73b0201798063b2caffeae4250
124115

125-
exclude-rules:
126-
127-
# Allow fmt.Printf() in test files
128-
- path: _test\.go
129-
linters:
130-
- forbidigo
131-
- unparam
132-
- gosec
133-
- path: _mock\.go
134-
linters:
135-
- gosec
136-
137-
# Allow fmt.Printf() in loopd
138-
- path: cmd/loopd/*
139-
linters:
140-
- forbidigo
141-
- path: loopd/*
142-
linters:
143-
- forbidigo
144-
145-
# Allow fmt.Printf() in loop
146-
- path: cmd/loop/*
147-
linters:
148-
- forbidigo
116+
exclude-files:
117+
- "\\.pb\\.go$"
118+
- "\\.pb\\.gw\\.go$"
149119

150-
# Allow fmt.Printf() in stateparser
151-
- path: fsm/stateparser/*
152-
linters:
153-
- forbidigo
120+
exclude-rules:
121+
# Allow fmt.Printf() in test files
122+
- path: _test\.go
123+
linters:
124+
- forbidigo
125+
- unparam
126+
- gosec
127+
- path: _mock\.go
128+
linters:
129+
- gosec
130+
131+
# Allow fmt.Printf() in loopd
132+
- path: cmd/loopd/*
133+
linters:
134+
- forbidigo
135+
- errcheck
136+
- path: loopd/*
137+
linters:
138+
- forbidigo
139+
140+
# Allow fmt.Printf() in loop
141+
- path: cmd/loop/*
142+
linters:
143+
- forbidigo
144+
- errcheck
145+
146+
# Allow fmt.Printf() in stateparser
147+
- path: fsm/stateparser/*
148+
linters:
149+
- forbidigo

client.go

-4
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
321321
swaps := make([]*SwapInfo, 0, len(loopInSwaps)+len(loopOutSwaps))
322322

323323
for _, swp := range loopOutSwaps {
324-
swp := swp
325-
326324
swapInfo := &SwapInfo{
327325
SwapType: swap.TypeOut,
328326
SwapContract: swp.Contract.SwapContract,
@@ -358,8 +356,6 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
358356
}
359357

360358
for _, swp := range loopInSwaps {
361-
swp := swp
362-
363359
swapInfo := &SwapInfo{
364360
SwapType: swap.TypeIn,
365361
SwapContract: swp.Contract.SwapContract,

client_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ func TestLoopOutResume(t *testing.T) {
175175
}
176176

177177
for _, version := range storedVersion {
178-
version := version
179-
180178
t.Run(version.String(), func(t *testing.T) {
181179
t.Run("not expired", func(t *testing.T) {
182180
testLoopOutResume(
@@ -443,8 +441,6 @@ func TestWrapGrpcError(t *testing.T) {
443441
}
444442

445443
for _, testCase := range tests {
446-
testCase := testCase
447-
448444
t.Run(testCase.name, func(t *testing.T) {
449445
err := wrapGrpcError("", testCase.original)
450446
require.Error(t, err, "test only expects errors")

cmd/loop/terms.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func terms(ctx *cli.Context) error {
2222
}
2323
defer cleanup()
2424

25-
printAmountRange := func(min, max int64) {
25+
printAmountRange := func(minAmt, maxAmt int64) {
2626
fmt.Printf("Amount: %d - %d\n",
27-
btcutil.Amount(min), btcutil.Amount(max),
27+
btcutil.Amount(minAmt), btcutil.Amount(maxAmt),
2828
)
2929
}
3030

fsm/example_fsm_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ func TestExampleFSM(t *testing.T) {
7676
}
7777

7878
for _, tc := range testCases {
79-
tc := tc
80-
8179
t.Run(tc.name, func(t *testing.T) {
8280
ctxb := context.Background()
8381
respondChan := make(chan string, 1)
@@ -192,8 +190,6 @@ func TestExampleFSMFlow(t *testing.T) {
192190
}
193191

194192
for _, tc := range testCases {
195-
tc := tc
196-
197193
t.Run(tc.name, func(t *testing.T) {
198194
exampleContext, cachedObserver := getTestContext()
199195
ctxb := context.Background()
@@ -268,8 +264,6 @@ func TestObserverAsyncWait(t *testing.T) {
268264
}
269265

270266
for _, tc := range testCases {
271-
tc := tc
272-
273267
t.Run(tc.name, func(t *testing.T) {
274268
service := &mockService{
275269
respondChan: make(chan bool),

instantout/instantout.go

-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ func pubkeyTo33ByteSlice(pubkey *btcec.PublicKey) [33]byte {
463463
func toNonces(nonces [][]byte) ([][66]byte, error) {
464464
res := make([][66]byte, 0, len(nonces))
465465
for _, n := range nonces {
466-
n := n
467466
nonce, err := byteSliceTo66ByteSlice(n)
468467
if err != nil {
469468
return nil, err

instantout/reservation/actions_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ func TestInitReservationAction(t *testing.T) {
131131
}
132132

133133
for _, tc := range tests {
134-
tc := tc
135134
ctxb := context.Background()
136135
mockLnd := test.NewMockLnd()
137136
mockReservationClient := new(mockReservationClient)
@@ -232,7 +231,6 @@ func TestSubscribeToConfirmationAction(t *testing.T) {
232231
}
233232

234233
for _, tc := range tests {
235-
tc := tc
236234
t.Run(tc.name, func(t *testing.T) {
237235
chainNotifier := new(MockChainNotifier)
238236
ctxb := context.Background()
@@ -340,7 +338,6 @@ func TestAsyncWaitForExpiredOrSweptAction(t *testing.T) {
340338
}
341339

342340
for _, tc := range tests {
343-
tc := tc
344341
t.Run(tc.name, func(t *testing.T) { // Create a mock ChainNotifier and Reservation
345342
chainNotifier := new(MockChainNotifier)
346343
ctxb := context.Background()
@@ -418,7 +415,6 @@ func TestHandleSubcriptions(t *testing.T) {
418415
}
419416

420417
for _, tc := range tests {
421-
tc := tc
422418
t.Run(tc.name, func(t *testing.T) {
423419
chainNotifier := new(MockChainNotifier)
424420

instantout/reservation/store_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestSqlStore(t *testing.T) {
8585

8686
reservations, err := store.ListReservations(ctxb)
8787
require.NoError(t, err)
88-
require.Equal(t, 2, len(reservations))
88+
require.Len(t, reservations, 2)
8989
}
9090

9191
// getRandomReservationID generates a random reservation ID.

labels/labels_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ func TestValidate(t *testing.T) {
4343
}
4444

4545
for _, test := range tests {
46-
test := test
47-
4846
t.Run(test.name, func(t *testing.T) {
4947
t.Parallel()
5048
require.Equal(t, test.err, Validate(test.label))

0 commit comments

Comments
 (0)