Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update golangci-lint to v1.56.1 #2714

Merged
merged 12 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 32 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ linters:
- errorlint
- exportloopref
- forbidigo
- gci
- goconst
- gocritic
# - goerr113
- gofmt
- gofumpt
- goimports
# - gomnd
- goprintffuncname
- gosec
Expand All @@ -69,9 +69,11 @@ linters:
- prealloc
- predeclared
- revive
- spancheck
- staticcheck
- stylecheck
- tagalign
- testifylint
- typecheck
- unconvert
- unparam
Expand Down Expand Up @@ -105,8 +107,16 @@ linters-settings:
- '^(t|b|tb|f)\.(Fatal|Fatalf|Error|Errorf)$(# the require library should be used instead)?'
# Exclude godoc examples from forbidigo checks.
exclude_godoc_examples: false
goimports:
local-prefixes: github.com/ava-labs/avalanchego
gci:
sections:
- standard
- default
- blank
- dot
- prefix(github.com/ava-labs/avalanchego)
- alias
skip-generated: true
custom-order: true
gosec:
excludes:
- G107 # Url provided to HTTP request as taint input https://securego.io/docs/rules/g107
Expand All @@ -119,6 +129,8 @@ linters-settings:
alias:
- pkg: github.com/ava-labs/avalanchego/utils/math
alias: safemath
- pkg: github.com/ava-labs/avalanchego/utils/json
alias: avajson
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr
Expand Down Expand Up @@ -161,6 +173,12 @@ linters-settings:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break
- name: useless-break
disabled: false
spancheck:
# https://github.com/jjti/go-spancheck#checks
checks:
- end
# - record-error # check that `span.RecordError(err)` is called when an error is returned
# - set-status # check that `span.SetStatus(codes.Error, msg)` is called when an error is returned
staticcheck:
# https://staticcheck.io/docs/options#checks
checks:
Expand All @@ -173,3 +191,14 @@ linters-settings:
strict: true
order:
- serialize
testifylint:
# Enable all checkers (https://github.com/Antonboom/testifylint#checkers).
# Default: false
enable-all: true
# Disable checkers by name
# (in addition to default
# suite-thelper
# ).
disable:
- go-require
- float-compare
1 change: 0 additions & 1 deletion api/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sync"

"github.com/gorilla/rpc/v2"

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/api"
Expand Down
1 change: 0 additions & 1 deletion api/admin/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/stretchr/testify/require"

"go.uber.org/mock/gomock"

"github.com/ava-labs/avalanchego/database/memdb"
Expand Down
4 changes: 2 additions & 2 deletions api/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
"sync"
"time"

jwt "github.com/golang-jwt/jwt/v4"

"github.com/gorilla/rpc/v2"

"github.com/ava-labs/avalanchego/utils/json"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/password"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/timer/mockable"

jwt "github.com/golang-jwt/jwt/v4"
)

const (
Expand Down
8 changes: 4 additions & 4 deletions api/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"testing"
"time"

jwt "github.com/golang-jwt/jwt/v4"

"github.com/stretchr/testify/require"

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

jwt "github.com/golang-jwt/jwt/v4"
)

var (
Expand All @@ -37,7 +37,7 @@ func init() {
}

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

func TestNewTokenWrongPassword(t *testing.T) {
require := require.New(t)
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestWrapHandlerNoAuthToken(t *testing.T) {
endpoints := []string{"/ext/info", "/ext/bc/X", "/ext/metrics"}
wrappedHandler := auth.WrapHandler(dummyHandler)
for _, endpoint := range endpoints {
req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://127.0.0.1:9650%s", endpoint), strings.NewReader(""))
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader(""))
rr := httptest.NewRecorder()
wrappedHandler.ServeHTTP(rr, req)
require.Equal(http.StatusUnauthorized, rr.Code)
Expand Down
17 changes: 9 additions & 8 deletions api/common_args_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
package api

import (
stdjson "encoding/json"
"encoding/json"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/avalanchego/utils/json"

avajson "github.com/ava-labs/avalanchego/utils/json"
)

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

// GetBlockByHeightArgs is the parameters supplied to the GetBlockByHeight API
type GetBlockByHeightArgs struct {
Height json.Uint64 `json:"height"`
Height avajson.Uint64 `json:"height"`
Encoding formatting.Encoding `json:"encoding"`
}

// GetBlockResponse is the response object for the GetBlock API.
type GetBlockResponse struct {
Block stdjson.RawMessage `json:"block"`
Block json.RawMessage `json:"block"`
// If GetBlockResponse.Encoding is formatting.Hex, GetBlockResponse.Block is
// the string representation of the block under hex encoding.
// If GetBlockResponse.Encoding is formatting.JSON, GetBlockResponse.Block
Expand All @@ -86,7 +87,7 @@ type GetBlockResponse struct {
}

type GetHeightResponse struct {
Height json.Uint64 `json:"height"`
Height avajson.Uint64 `json:"height"`
}

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

Expand Down Expand Up @@ -139,15 +140,15 @@ type Index struct {
type GetUTXOsArgs struct {
Addresses []string `json:"addresses"`
SourceChain string `json:"sourceChain"`
Limit json.Uint32 `json:"limit"`
Limit avajson.Uint32 `json:"limit"`
StartIndex Index `json:"startIndex"`
Encoding formatting.Encoding `json:"encoding"`
}

// GetUTXOsReply defines the GetUTXOs replies returned from the API
type GetUTXOsReply struct {
// Number of UTXOs returned
NumFetched json.Uint64 `json:"numFetched"`
NumFetched avajson.Uint64 `json:"numFetched"`
// The UTXOs
UTXOs []string `json:"utxos"`
// The last UTXO that was returned, and the address it corresponds to.
Expand Down
10 changes: 5 additions & 5 deletions api/health/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
package health

import (
"encoding/json"
"net/http"

stdjson "encoding/json"

"github.com/gorilla/rpc/v2"

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

avajson "github.com/ava-labs/avalanchego/utils/json"
)

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

Expand Down Expand Up @@ -60,7 +60,7 @@ func NewGetHandler(reporter func(tags ...string) (map[string]Result, bool)) http
}
// The encoder will call write on the writer, which will write the
// header with a 200.
_ = stdjson.NewEncoder(w).Encode(APIReply{
_ = json.NewEncoder(w).Encode(APIReply{
Checks: checks,
Healthy: healthy,
})
Expand Down
1 change: 0 additions & 1 deletion api/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/utils/logging"
Expand Down
1 change: 0 additions & 1 deletion api/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/utils"
Expand Down
1 change: 0 additions & 1 deletion api/health/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

"github.com/prometheus/client_golang/prometheus"

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
Expand Down
1 change: 0 additions & 1 deletion api/health/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/utils"
Expand Down
1 change: 0 additions & 1 deletion api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"

"github.com/gorilla/rpc/v2"

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/chains"
Expand Down
1 change: 0 additions & 1 deletion api/info/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/stretchr/testify/require"

"go.uber.org/mock/gomock"

"github.com/ava-labs/avalanchego/ids"
Expand Down
1 change: 0 additions & 1 deletion api/ipcs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sync"

"github.com/gorilla/rpc/v2"

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/api"
Expand Down
4 changes: 2 additions & 2 deletions api/metrics/multi_gatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

"github.com/prometheus/client_golang/prometheus"

dto "github.com/prometheus/client_model/go"

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

dto "github.com/prometheus/client_model/go"
)

var (
Expand Down
4 changes: 0 additions & 4 deletions api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ import (
"time"

"github.com/NYTimes/gziphandler"

"github.com/prometheus/client_golang/prometheus"

"github.com/rs/cors"

"go.uber.org/zap"

"golang.org/x/net/http2"

"github.com/ava-labs/avalanchego/api"
Expand Down
7 changes: 3 additions & 4 deletions api/traced_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
package api

import (
"fmt"
"net/http"

"go.opentelemetry.io/otel/attribute"

oteltrace "go.opentelemetry.io/otel/trace"

"github.com/ava-labs/avalanchego/trace"

oteltrace "go.opentelemetry.io/otel/trace"
)

var _ http.Handler = (*tracedHandler)(nil)
Expand All @@ -25,7 +24,7 @@ type tracedHandler struct {
func TraceHandler(h http.Handler, name string, tracer trace.Tracer) http.Handler {
return &tracedHandler{
h: h,
serveHTTPTag: fmt.Sprintf("%s.ServeHTTP", name),
serveHTTPTag: name + ".ServeHTTP",
tracer: tracer,
}
}
Expand Down
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"syscall"

"go.uber.org/zap"

"golang.org/x/sync/errgroup"

"github.com/ava-labs/avalanchego/node"
Expand Down
1 change: 0 additions & 1 deletion cache/metercacher/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"

"github.com/prometheus/client_golang/prometheus"

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/cache"
Expand Down
2 changes: 1 addition & 1 deletion cache/metercacher/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newAveragerMetric(namespace, name string, reg prometheus.Registerer, errs *
return metric.NewAveragerWithErrs(
namespace,
name,
fmt.Sprintf("time (in ns) of a %s", name),
"time (in ns) of a "+name,
reg,
errs,
)
Expand Down
Loading
Loading