Skip to content

Commit c8a5d0b

Browse files
authored
Update golangci-lint to v1.56.1 (#2714)
1 parent ac2d9bf commit c8a5d0b

File tree

303 files changed

+611
-938
lines changed

Some content is hidden

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

303 files changed

+611
-938
lines changed

.golangci.yml

+32-3
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ linters:
4747
- errorlint
4848
- exportloopref
4949
- forbidigo
50+
- gci
5051
- goconst
5152
- gocritic
5253
# - goerr113
5354
- gofmt
5455
- gofumpt
55-
- goimports
5656
# - gomnd
5757
- goprintffuncname
5858
- gosec
@@ -69,9 +69,11 @@ linters:
6969
- prealloc
7070
- predeclared
7171
- revive
72+
- spancheck
7273
- staticcheck
7374
- stylecheck
7475
- tagalign
76+
- testifylint
7577
- typecheck
7678
- unconvert
7779
- unparam
@@ -105,8 +107,16 @@ linters-settings:
105107
- '^(t|b|tb|f)\.(Fatal|Fatalf|Error|Errorf)$(# the require library should be used instead)?'
106108
# Exclude godoc examples from forbidigo checks.
107109
exclude_godoc_examples: false
108-
goimports:
109-
local-prefixes: github.com/ava-labs/avalanchego
110+
gci:
111+
sections:
112+
- standard
113+
- default
114+
- blank
115+
- dot
116+
- prefix(github.com/ava-labs/avalanchego)
117+
- alias
118+
skip-generated: true
119+
custom-order: true
110120
gosec:
111121
excludes:
112122
- G107 # Url provided to HTTP request as taint input https://securego.io/docs/rules/g107
@@ -119,6 +129,8 @@ linters-settings:
119129
alias:
120130
- pkg: github.com/ava-labs/avalanchego/utils/math
121131
alias: safemath
132+
- pkg: github.com/ava-labs/avalanchego/utils/json
133+
alias: avajson
122134
revive:
123135
rules:
124136
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr
@@ -161,6 +173,12 @@ linters-settings:
161173
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break
162174
- name: useless-break
163175
disabled: false
176+
spancheck:
177+
# https://github.com/jjti/go-spancheck#checks
178+
checks:
179+
- end
180+
# - record-error # check that `span.RecordError(err)` is called when an error is returned
181+
# - set-status # check that `span.SetStatus(codes.Error, msg)` is called when an error is returned
164182
staticcheck:
165183
# https://staticcheck.io/docs/options#checks
166184
checks:
@@ -173,3 +191,14 @@ linters-settings:
173191
strict: true
174192
order:
175193
- serialize
194+
testifylint:
195+
# Enable all checkers (https://github.com/Antonboom/testifylint#checkers).
196+
# Default: false
197+
enable-all: true
198+
# Disable checkers by name
199+
# (in addition to default
200+
# suite-thelper
201+
# ).
202+
disable:
203+
- go-require
204+
- float-compare

api/admin/service.go

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"sync"
1111

1212
"github.com/gorilla/rpc/v2"
13-
1413
"go.uber.org/zap"
1514

1615
"github.com/ava-labs/avalanchego/api"

api/admin/service_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"testing"
99

1010
"github.com/stretchr/testify/require"
11-
1211
"go.uber.org/mock/gomock"
1312

1413
"github.com/ava-labs/avalanchego/database/memdb"

api/auth/auth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import (
1414
"sync"
1515
"time"
1616

17-
jwt "github.com/golang-jwt/jwt/v4"
18-
1917
"github.com/gorilla/rpc/v2"
2018

2119
"github.com/ava-labs/avalanchego/utils/json"
2220
"github.com/ava-labs/avalanchego/utils/logging"
2321
"github.com/ava-labs/avalanchego/utils/password"
2422
"github.com/ava-labs/avalanchego/utils/set"
2523
"github.com/ava-labs/avalanchego/utils/timer/mockable"
24+
25+
jwt "github.com/golang-jwt/jwt/v4"
2626
)
2727

2828
const (

api/auth/auth_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"testing"
1515
"time"
1616

17-
jwt "github.com/golang-jwt/jwt/v4"
18-
1917
"github.com/stretchr/testify/require"
2018

2119
"github.com/ava-labs/avalanchego/utils/logging"
2220
"github.com/ava-labs/avalanchego/utils/password"
21+
22+
jwt "github.com/golang-jwt/jwt/v4"
2323
)
2424

2525
var (
@@ -37,7 +37,7 @@ func init() {
3737
}
3838

3939
// Always returns 200 (http.StatusOK)
40-
var dummyHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
40+
var dummyHandler = http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
4141

4242
func TestNewTokenWrongPassword(t *testing.T) {
4343
require := require.New(t)
@@ -228,7 +228,7 @@ func TestWrapHandlerNoAuthToken(t *testing.T) {
228228
endpoints := []string{"/ext/info", "/ext/bc/X", "/ext/metrics"}
229229
wrappedHandler := auth.WrapHandler(dummyHandler)
230230
for _, endpoint := range endpoints {
231-
req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://127.0.0.1:9650%s", endpoint), strings.NewReader(""))
231+
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader(""))
232232
rr := httptest.NewRecorder()
233233
wrappedHandler.ServeHTTP(rr, req)
234234
require.Equal(http.StatusUnauthorized, rr.Code)

api/common_args_responses.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
package api
55

66
import (
7-
stdjson "encoding/json"
7+
"encoding/json"
88

99
"github.com/ava-labs/avalanchego/ids"
1010
"github.com/ava-labs/avalanchego/utils/formatting"
11-
"github.com/ava-labs/avalanchego/utils/json"
11+
12+
avajson "github.com/ava-labs/avalanchego/utils/json"
1213
)
1314

1415
// This file contains structs used in arguments and responses in services
@@ -71,13 +72,13 @@ type GetBlockArgs struct {
7172

7273
// GetBlockByHeightArgs is the parameters supplied to the GetBlockByHeight API
7374
type GetBlockByHeightArgs struct {
74-
Height json.Uint64 `json:"height"`
75+
Height avajson.Uint64 `json:"height"`
7576
Encoding formatting.Encoding `json:"encoding"`
7677
}
7778

7879
// GetBlockResponse is the response object for the GetBlock API.
7980
type GetBlockResponse struct {
80-
Block stdjson.RawMessage `json:"block"`
81+
Block json.RawMessage `json:"block"`
8182
// If GetBlockResponse.Encoding is formatting.Hex, GetBlockResponse.Block is
8283
// the string representation of the block under hex encoding.
8384
// If GetBlockResponse.Encoding is formatting.JSON, GetBlockResponse.Block
@@ -86,7 +87,7 @@ type GetBlockResponse struct {
8687
}
8788

8889
type GetHeightResponse struct {
89-
Height json.Uint64 `json:"height"`
90+
Height avajson.Uint64 `json:"height"`
9091
}
9192

9293
// FormattedBlock defines a JSON formatted struct containing a block in Hex
@@ -107,7 +108,7 @@ type GetTxReply struct {
107108
// the tx under hex encoding.
108109
// If [GetTxArgs.Encoding] is [JSON], [Tx] is the actual tx, which will be
109110
// returned as JSON to the caller.
110-
Tx stdjson.RawMessage `json:"tx"`
111+
Tx json.RawMessage `json:"tx"`
111112
Encoding formatting.Encoding `json:"encoding"`
112113
}
113114

@@ -139,15 +140,15 @@ type Index struct {
139140
type GetUTXOsArgs struct {
140141
Addresses []string `json:"addresses"`
141142
SourceChain string `json:"sourceChain"`
142-
Limit json.Uint32 `json:"limit"`
143+
Limit avajson.Uint32 `json:"limit"`
143144
StartIndex Index `json:"startIndex"`
144145
Encoding formatting.Encoding `json:"encoding"`
145146
}
146147

147148
// GetUTXOsReply defines the GetUTXOs replies returned from the API
148149
type GetUTXOsReply struct {
149150
// Number of UTXOs returned
150-
NumFetched json.Uint64 `json:"numFetched"`
151+
NumFetched avajson.Uint64 `json:"numFetched"`
151152
// The UTXOs
152153
UTXOs []string `json:"utxos"`
153154
// The last UTXO that was returned, and the address it corresponds to.

api/health/handler.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
package health
55

66
import (
7+
"encoding/json"
78
"net/http"
89

9-
stdjson "encoding/json"
10-
1110
"github.com/gorilla/rpc/v2"
1211

13-
"github.com/ava-labs/avalanchego/utils/json"
1412
"github.com/ava-labs/avalanchego/utils/logging"
13+
14+
avajson "github.com/ava-labs/avalanchego/utils/json"
1515
)
1616

1717
// NewGetAndPostHandler returns a health handler that supports GET and jsonrpc
1818
// POST requests.
1919
func NewGetAndPostHandler(log logging.Logger, reporter Reporter) (http.Handler, error) {
2020
newServer := rpc.NewServer()
21-
codec := json.NewCodec()
21+
codec := avajson.NewCodec()
2222
newServer.RegisterCodec(codec, "application/json")
2323
newServer.RegisterCodec(codec, "application/json;charset=UTF-8")
2424

@@ -60,7 +60,7 @@ func NewGetHandler(reporter func(tags ...string) (map[string]Result, bool)) http
6060
}
6161
// The encoder will call write on the writer, which will write the
6262
// header with a 200.
63-
_ = stdjson.NewEncoder(w).Encode(APIReply{
63+
_ = json.NewEncoder(w).Encode(APIReply{
6464
Checks: checks,
6565
Healthy: healthy,
6666
})

api/health/health.go

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"time"
99

1010
"github.com/prometheus/client_golang/prometheus"
11-
1211
"go.uber.org/zap"
1312

1413
"github.com/ava-labs/avalanchego/utils/logging"

api/health/health_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"time"
1313

1414
"github.com/prometheus/client_golang/prometheus"
15-
1615
"github.com/stretchr/testify/require"
1716

1817
"github.com/ava-labs/avalanchego/utils"

api/health/service_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"testing"
1010

1111
"github.com/prometheus/client_golang/prometheus"
12-
1312
"github.com/stretchr/testify/require"
1413

1514
"github.com/ava-labs/avalanchego/ids"

api/health/worker.go

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"time"
1414

1515
"github.com/prometheus/client_golang/prometheus"
16-
1716
"go.uber.org/zap"
1817

1918
"github.com/ava-labs/avalanchego/utils"

api/info/service.go

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/http"
1010

1111
"github.com/gorilla/rpc/v2"
12-
1312
"go.uber.org/zap"
1413

1514
"github.com/ava-labs/avalanchego/chains"

api/info/service_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"testing"
99

1010
"github.com/stretchr/testify/require"
11-
1211
"go.uber.org/mock/gomock"
1312

1413
"github.com/ava-labs/avalanchego/ids"

api/ipcs/service.go

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"sync"
99

1010
"github.com/gorilla/rpc/v2"
11-
1211
"go.uber.org/zap"
1312

1413
"github.com/ava-labs/avalanchego/api"

api/metrics/multi_gatherer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212

1313
"github.com/prometheus/client_golang/prometheus"
1414

15-
dto "github.com/prometheus/client_model/go"
16-
1715
"github.com/ava-labs/avalanchego/utils/metric"
16+
17+
dto "github.com/prometheus/client_model/go"
1818
)
1919

2020
var (

api/server/server.go

-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@ import (
1313
"time"
1414

1515
"github.com/NYTimes/gziphandler"
16-
1716
"github.com/prometheus/client_golang/prometheus"
18-
1917
"github.com/rs/cors"
20-
2118
"go.uber.org/zap"
22-
2319
"golang.org/x/net/http2"
2420

2521
"github.com/ava-labs/avalanchego/api"

api/traced_handler.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
package api
55

66
import (
7-
"fmt"
87
"net/http"
98

109
"go.opentelemetry.io/otel/attribute"
1110

12-
oteltrace "go.opentelemetry.io/otel/trace"
13-
1411
"github.com/ava-labs/avalanchego/trace"
12+
13+
oteltrace "go.opentelemetry.io/otel/trace"
1514
)
1615

1716
var _ http.Handler = (*tracedHandler)(nil)
@@ -25,7 +24,7 @@ type tracedHandler struct {
2524
func TraceHandler(h http.Handler, name string, tracer trace.Tracer) http.Handler {
2625
return &tracedHandler{
2726
h: h,
28-
serveHTTPTag: fmt.Sprintf("%s.ServeHTTP", name),
27+
serveHTTPTag: name + ".ServeHTTP",
2928
tracer: tracer,
3029
}
3130
}

app/app.go

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"syscall"
1212

1313
"go.uber.org/zap"
14-
1514
"golang.org/x/sync/errgroup"
1615

1716
"github.com/ava-labs/avalanchego/node"

cache/metercacher/cache_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
"github.com/prometheus/client_golang/prometheus"
10-
1110
"github.com/stretchr/testify/require"
1211

1312
"github.com/ava-labs/avalanchego/cache"

cache/metercacher/metrics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func newAveragerMetric(namespace, name string, reg prometheus.Registerer, errs *
1616
return metric.NewAveragerWithErrs(
1717
namespace,
1818
name,
19-
fmt.Sprintf("time (in ns) of a %s", name),
19+
"time (in ns) of a "+name,
2020
reg,
2121
errs,
2222
)

0 commit comments

Comments
 (0)