Skip to content

Commit

Permalink
Add more robust .golangci.yml (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Feb 8, 2024
1 parent a50e553 commit 267a4d7
Show file tree
Hide file tree
Showing 55 changed files with 1,328 additions and 1,106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
with:
version: latest
version: v1.56.1
check_mockgen:
name: Up-to-date mocks
runs-on: ubuntu-latest
Expand Down
203 changes: 173 additions & 30 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,210 @@
# https://golangci-lint.run/usage/configuration/
run:
timeout: 10m
# skip auto-generated files.
skip-files:
- ".*\\.pb\\.go$"

# 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
exclude:
- "G114: Use of net/http serve function that has no support for setting timeouts"
exclude-rules:
# ref: https://github.com/dominikh/go-tools/issues/1365
- path: client/pchainclient.go
linters:
- unused

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
- deadcode
- 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
- varcheck
- unconvert
- usestdlibvars
- whitespace
- staticcheck
# - 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/avalanche-rosetta)
- 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/coreth/core/types
alias: ethtypes
- pkg: github.com/ethereum/go-ethereum/common
alias: ethcommon
- pkg: github.com/ava-labs/avalanche-rosetta/mapper/pchain
alias: pmapper
- pkg: github.com/ava-labs/avalanche-rosetta/mapper/cchainatomictx
alias: cmapper
- pkg: github.com/ava-labs/avalanchego/utils/constants
alias: avaconstants
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr
- name: bool-literal-in-expr
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return
- name: early-return
disabled: false
# 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
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-naming
- name: unexported-naming
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error
- name: unhandled-error
disabled: false
arguments:
- "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
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
- name: unused-receiver
disabled: false
# 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:
go: "1.21"
# 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
- "-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
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
27 changes: 14 additions & 13 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"math/big"
"strings"

"github.com/ava-labs/avalanche-rosetta/constants"
"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/rpc"
ethtypes "github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/interfaces"
"github.com/ava-labs/coreth/plugin/evm"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"

"github.com/ava-labs/avalanche-rosetta/constants"
)

// Interface compliance
Expand All @@ -23,21 +24,21 @@ type Client interface {
InfoClient

ChainID(context.Context) (*big.Int, error)
BlockByHash(context.Context, ethcommon.Hash) (*ethtypes.Block, error)
BlockByNumber(context.Context, *big.Int) (*ethtypes.Block, error)
HeaderByHash(context.Context, ethcommon.Hash) (*ethtypes.Header, error)
HeaderByNumber(context.Context, *big.Int) (*ethtypes.Header, error)
TransactionByHash(context.Context, ethcommon.Hash) (*ethtypes.Transaction, bool, error)
TransactionReceipt(context.Context, ethcommon.Hash) (*ethtypes.Receipt, error)
BlockByHash(context.Context, common.Hash) (*types.Block, error)
BlockByNumber(context.Context, *big.Int) (*types.Block, error)
HeaderByHash(context.Context, common.Hash) (*types.Header, error)
HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
TransactionByHash(context.Context, common.Hash) (*types.Transaction, bool, error)
TransactionReceipt(context.Context, common.Hash) (*types.Receipt, error)
TraceTransaction(context.Context, string) (*Call, []*FlatCall, error)
TraceBlockByHash(context.Context, string) ([]*Call, [][]*FlatCall, error)
SendTransaction(context.Context, *ethtypes.Transaction) error
BalanceAt(context.Context, ethcommon.Address, *big.Int) (*big.Int, error)
NonceAt(context.Context, ethcommon.Address, *big.Int) (uint64, error)
SendTransaction(context.Context, *types.Transaction) error
BalanceAt(context.Context, common.Address, *big.Int) (*big.Int, error)
NonceAt(context.Context, common.Address, *big.Int) (uint64, error)
SuggestGasPrice(context.Context) (*big.Int, error)
EstimateGas(context.Context, interfaces.CallMsg) (uint64, error)
TxPoolContent(context.Context) (*TxPoolContent, error)
GetContractInfo(ethcommon.Address, bool) (string, uint8, error)
GetContractInfo(common.Address, bool) (string, uint8, error)
CallContract(context.Context, interfaces.CallMsg, *big.Int) ([]byte, error)
IssueTx(ctx context.Context, txBytes []byte, options ...rpc.Option) (ids.ID, error)
GetAtomicUTXOs(ctx context.Context, addrs []ids.ShortID, sourceChain string, limit uint32, startAddress ids.ShortID, startUTXOID ids.ID, options ...rpc.Option) ([][]byte, ids.ShortID, ids.ID, error)
Expand Down
3 changes: 1 addition & 2 deletions client/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package client

import (
"context"
"fmt"

"github.com/ava-labs/coreth/eth/tracers"
"github.com/ava-labs/coreth/ethclient"
Expand All @@ -24,7 +23,7 @@ type EthClient struct {

// NewEthClient returns a new EVM client
func NewEthClient(ctx context.Context, endpoint string) (*EthClient, error) {
endpointURL := fmt.Sprintf("%s%s", endpoint, prefixEth)
endpointURL := endpoint + prefixEth

c, err := rpc.DialContext(ctx, endpointURL)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"errors"
"os"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ethereum/go-ethereum/common"

"github.com/ava-labs/avalanche-rosetta/client"
"github.com/ava-labs/avalanche-rosetta/mapper"
"github.com/ava-labs/avalanche-rosetta/service"
"github.com/ava-labs/avalanchego/utils/constants"
)

var (
Expand Down Expand Up @@ -97,15 +97,15 @@ func (c *config) validate() error {

if len(c.TokenWhiteList) != 0 {
for _, token := range c.TokenWhiteList {
if !ethcommon.IsHexAddress(token) {
if !common.IsHexAddress(token) {
return errInvalidTokenAddress
}
}
}

if len(c.BridgeTokenList) != 0 {
for _, token := range c.BridgeTokenList {
if !ethcommon.IsHexAddress(token) {
if !common.IsHexAddress(token) {
return errInvalidTokenAddress
}

Expand All @@ -128,7 +128,7 @@ func (c *config) validate() error {

func (c *config) validateWhitelistOnlyValidErc20s(cli client.Client) error {
for _, token := range c.TokenWhiteList {
ethAddress := ethcommon.HexToAddress(token)
ethAddress := common.HexToAddress(token)
symbol, decimals, err := cli.GetContractInfo(ethAddress, true)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 267a4d7

Please sign in to comment.