Skip to content

Commit

Permalink
[ci] Update golangci (#716)
Browse files Browse the repository at this point in the history
* update golangci

* update version of golangci

* passing

* nit

* tidy

* nit

* nits

* nit

* fix UTs

---------

Co-authored-by: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com>
  • Loading branch information
patrick-ogrady and dhrubabasu authored Feb 9, 2024
1 parent 10bd43e commit 7e6426d
Show file tree
Hide file tree
Showing 95 changed files with 594 additions and 548 deletions.
179 changes: 137 additions & 42 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,144 @@
# Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
# See the file LICENSE for licensing terms.

# https://golangci-lint.run/usage/configuration/
run:
timeout: 10m
# skip auto-generated files.
skip-files:
- ".*\\.pb\\.go$"
- ".*mock.*"

# Enables skipping of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
# Default: true
skip-dirs-use-default: false

# If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
#
# Allowed values: readonly|vendor|mod
# By default, it isn't set.
modules-download-mode: readonly

output:
# Make issues output unique by line.
# Default: true
uniq-by-line: false

issues:
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0

# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 0

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asciicheck
- bodyclose
- depguard
- dupword
- errcheck
- errorlint
- exportloopref
- forbidigo
- gci
- goconst
- gocritic
# - goerr113
- gofmt
- gofumpt
- goimports
- revive
# - gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
# - lll
- misspell
- nakedret
- noctx
- nolintlint
- perfsprint
- prealloc
- predeclared
- revive
- spancheck
- staticcheck
- stylecheck
- tagalign
- testifylint
- typecheck
- unconvert
- unparam
- unused
- unconvert
- usestdlibvars
- whitespace
- staticcheck
- bodyclose
- structcheck
# - lll
# - gomnd
- goprintffuncname
- interfacer
- typecheck
# - goerr113
- noctx

linters-settings:
depguard:
rules:
packages:
deny:
- pkg: "io/ioutil"
desc: io/ioutil is deprecated. Use package io or os instead.
- pkg: "github.com/stretchr/testify/assert"
desc: github.com/stretchr/testify/require should be used instead.
- pkg: "github.com/golang/mock/gomock"
desc: go.uber.org/mock/gomock should be used instead.
errorlint:
# Check for plain type assertions and type switches.
asserts: false
# Check for plain error comparisons.
comparison: false
forbidigo:
# Forbid the following identifiers (list of regexp).
forbid:
- 'require\.Error$(# ErrorIs should be used instead)?'
- 'require\.ErrorContains$(# ErrorIs should be used instead)?'
- 'require\.EqualValues$(# Equal should be used instead)?'
- 'require\.NotEqualValues$(# NotEqual should be used instead)?'
- '^(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
gci:
sections:
- standard
- default
- blank
- dot
- prefix(github.com/ava-labs/hypersdk)
- alias
skip-generated: true
custom-order: true
gosec:
excludes:
- G107 # Url provided to HTTP request as taint input https://securego.io/docs/rules/g107
importas:
# Do not allow unaliased imports of aliased packages.
no-unaliased: false
# Do not allow non-required aliases.
no-extra-aliases: false
# List of aliases
alias:
- pkg: github.com/ava-labs/avalanchego/utils/math
alias: safemath
- pkg: github.com/ava-labs/avalanchego/utils
alias: avautils
- pkg: github.com/ava-labs/avalanchego/trace
alias: avatrace
- pkg: github.com/ava-labs/avalanchego/api/metrics
alias: avametrics
- pkg: github.com/ava-labs/avalanchego/cache
alias: avacache
- pkg: github.com/ava-labs/avalanchego/x/sync
alias: avasync
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr
Expand All @@ -71,6 +150,11 @@ linters-settings:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
- name: empty-lines
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format
- name: string-format
disabled: false
arguments:
- ["fmt.Errorf[0]", "/.*%.*/", "no format directive, use errors.New instead"]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
- name: struct-tag
disabled: false
Expand All @@ -81,13 +165,13 @@ linters-settings:
- name: unhandled-error
disabled: false
arguments:
- "fmt.Fprint"
- "fmt.Fprintf"
- "fmt.Print"
- "fmt.Printf"
- "fmt.Println"
- "rand.Read"
- "sb.WriteString"
- "fmt\\.Fprint"
- "fmt\\.Fprintf"
- "fmt\\.Print"
- "fmt\\.Printf"
- "fmt\\.Println"
- "math/rand\\.Read"
- "strings\\.Builder\\.WriteString"
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
disabled: false
Expand All @@ -97,19 +181,30 @@ 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:
- "all"
- "-SA6002" # argument should be pointer-like to avoid allocation, for sync.Pool
- "-SA1019" # deprecated packages e.g., golang.org/x/crypto/ripemd160
# https://golangci-lint.run/usage/linters#gosec
gosec:
excludes:
- G107 # https://securego.io/docs/rules/g107.html
depguard:
list-type: blacklist
packages-with-error-message:
- io/ioutil: 'io/ioutil is deprecated. Use package io or os instead.'
- github.com/stretchr/testify/assert: 'github.com/stretchr/testify/require should be used instead.'
include-go-root: true
- "-SA6002" # Storing non-pointer values in sync.Pool allocates memory
- "-SA1019" # Using a deprecated function, variable, constant or field
tagalign:
align: true
sort: true
strict: true
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: 1 addition & 0 deletions builder/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/logging"

"github.com/ava-labs/hypersdk/chain"
)

Expand Down
1 change: 1 addition & 0 deletions chain/auth_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"

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

"github.com/ava-labs/hypersdk/workers"
)

Expand Down
1 change: 1 addition & 0 deletions chain/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

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

"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/consts"
)
Expand Down
16 changes: 8 additions & 8 deletions chain/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/avalanchego/x/merkledb"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"

"github.com/ava-labs/hypersdk/codec"
Expand Down Expand Up @@ -161,10 +161,10 @@ func (b *StatelessBlock) populateTxs(ctx context.Context) error {
defer span.End()

// Setup signature verification job
_, sigVerifySpan := b.vm.Tracer().Start(ctx, "StatelessBlock.verifySignatures")
_, sigVerifySpan := b.vm.Tracer().Start(ctx, "StatelessBlock.verifySignatures") //nolint:spancheck
job, err := b.vm.AuthVerifiers().NewJob(len(b.Txs))
if err != nil {
return err
return err //nolint:spancheck
}
b.sigJob = job
batchVerifier := NewAuthBatch(b.vm, b.sigJob, b.authCounts)
Expand Down Expand Up @@ -312,7 +312,7 @@ func (b *StatelessBlock) VerifyWithContext(ctx context.Context, bctx *block.Cont
stateReady := b.vm.StateReady()
ctx, span := b.vm.Tracer().Start(
ctx, "StatelessBlock.VerifyWithContext",
oteltrace.WithAttributes(
trace.WithAttributes(
attribute.Int("txs", len(b.Txs)),
attribute.Int64("height", int64(b.Hght)),
attribute.Bool("stateReady", stateReady),
Expand All @@ -339,7 +339,7 @@ func (b *StatelessBlock) Verify(ctx context.Context) error {
stateReady := b.vm.StateReady()
ctx, span := b.vm.Tracer().Start(
ctx, "StatelessBlock.Verify",
oteltrace.WithAttributes(
trace.WithAttributes(
attribute.Int("txs", len(b.Txs)),
attribute.Int64("height", int64(b.Hght)),
attribute.Bool("stateReady", stateReady),
Expand Down Expand Up @@ -526,7 +526,7 @@ func (b *StatelessBlock) innerVerify(ctx context.Context, vctx VerifyContext) er
)
return ErrMissingBlockContext
}
_, warpVerifySpan := b.vm.Tracer().Start(ctx, "StatelessBlock.verifyWarpMessages")
_, warpVerifySpan := b.vm.Tracer().Start(ctx, "StatelessBlock.verifyWarpMessages") //nolint:spancheck
b.vdrState = b.vm.ValidatorState()
go func() {
defer warpVerifySpan.End()
Expand Down Expand Up @@ -572,7 +572,7 @@ func (b *StatelessBlock) innerVerify(ctx context.Context, vctx VerifyContext) er
feeKey := FeeKey(b.vm.StateManager().FeeKey())
feeRaw, err := parentView.GetValue(ctx, feeKey)
if err != nil {
return err
return err //nolint:spancheck
}
parentFeeManager := fees.NewManager(feeRaw)
feeManager, err := parentFeeManager.ComputeNext(parentTimestamp, b.Tmstmp, r)
Expand Down Expand Up @@ -804,7 +804,7 @@ func (b *StatelessBlock) Processed() bool {
// it will result in undefined behavior.
func (b *StatelessBlock) View(ctx context.Context, verify bool) (state.View, error) {
ctx, span := b.vm.Tracer().Start(ctx, "StatelessBlock.View",
oteltrace.WithAttributes(
trace.WithAttributes(
attribute.Bool("processed", b.Processed()),
attribute.Bool("verify", verify),
),
Expand Down
8 changes: 4 additions & 4 deletions chain/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
smblock "github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -64,7 +64,7 @@ func BuildBlock(
ctx context.Context,
vm VM,
parent *StatelessBlock,
blockContext *smblock.Context,
blockContext *block.Context,
) (*StatelessBlock, error) {
ctx, span := vm.Tracer().Start(ctx, "chain.BuildBlock")
defer span.End()
Expand Down Expand Up @@ -148,7 +148,7 @@ func BuildBlock(
b.vm.RecordClearedMempool()
break
}
ctx, executeSpan := vm.Tracer().Start(ctx, "chain.BuildBlock.Execute")
ctx, executeSpan := vm.Tracer().Start(ctx, "chain.BuildBlock.Execute") //nolint:spancheck

// Perform a batch repeat check
dup, err := parent.IsRepeat(ctx, oldestAllowed, txs, set.NewBits(), false)
Expand Down Expand Up @@ -434,7 +434,7 @@ func BuildBlock(
// Perform basic validity checks to make sure the block is well-formatted
if len(b.Txs) == 0 {
if nextTime < parent.Tmstmp+r.GetMinEmptyBlockGap() {
return nil, fmt.Errorf("%w: allowed in %d ms", ErrNoTxs, parent.Tmstmp+r.GetMinEmptyBlockGap()-nextTime)
return nil, fmt.Errorf("%w: allowed in %d ms", ErrNoTxs, parent.Tmstmp+r.GetMinEmptyBlockGap()-nextTime) //nolint:spancheck
}
vm.RecordEmptyBlockBuilt()
}
Expand Down
1 change: 1 addition & 0 deletions chain/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

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

"github.com/ava-labs/hypersdk/keys"
)

Expand Down
1 change: 1 addition & 0 deletions chain/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package chain

import (
"github.com/ava-labs/avalanchego/vms/platformvm/warp"

"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/consts"
"github.com/ava-labs/hypersdk/fees"
Expand Down
Loading

0 comments on commit 7e6426d

Please sign in to comment.