Skip to content

Commit 04543ea

Browse files
authored
chore: golangci-lint CI workflow (ethereum#16)
* chore: `golangci-lint` CI workflow * fix: make `golangci-lint` happy * chore: bump `actions/{checkout,setup-go}` versions * chore: overhaul `.golanci.yml` config * fix: all linter issues * chore: exclude non-libevm linters + change deprecated option * fix: add overflow check in example * fix: try again; different local version? * chore: this is trying my patience * chore: enable `gci` and fix ordering * chore: mark `ethclient/gethclient` test as flaky * chore: mark `eth/catalyst` test as flaky
1 parent 2d3894f commit 04543ea

File tree

16 files changed

+163
-65
lines changed

16 files changed

+163
-65
lines changed

.github/workflows/go.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ jobs:
1111
go_test_short:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1515
- name: Set up Go
16-
uses: actions/setup-go@v2
16+
uses: actions/setup-go@v5
1717
with:
1818
go-version: 1.21.4
1919
- name: Run tests
2020
run: | # Upstream flakes are race conditions exacerbated by concurrent tests
21-
FLAKY_REGEX='go-ethereum/(eth|accounts/keystore|eth/downloader|miner)$';
21+
FLAKY_REGEX='go-ethereum/(eth|accounts/keystore|eth/downloader|miner|ethclient/gethclient|eth/catalyst)$';
2222
go list ./... | grep -P "${FLAKY_REGEX}" | xargs -n 1 go test -short;
2323
go test -short $(go list ./... | grep -Pv "${FLAKY_REGEX}");
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: golangci-lint
2+
3+
on:
4+
push:
5+
branches: [ libevm ]
6+
pull_request:
7+
branches: [ libevm ]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
golangci:
15+
name: lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-go@v5
20+
with:
21+
go-version: stable
22+
- name: golangci-lint
23+
uses: golangci/golangci-lint-action@v6
24+
with:
25+
version: v1.60

.golangci.yml

Lines changed: 93 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,112 @@
33
run:
44
timeout: 20m
55
tests: true
6-
# default is true. Enables skipping of directories:
7-
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
8-
skip-dirs-use-default: true
9-
skip-files:
10-
- core/genesis_alloc.go
116

127
linters:
13-
disable-all: true
148
enable:
9+
# Every available linter at the time of writing was considered (quickly) and
10+
# inclusion was liberal. Linters are good at detecting code smells, but if
11+
# we find that a particular one causes too many false positives then we can
12+
# configure it better or, as a last resort, remove it.
13+
- containedctx
14+
- errcheck
15+
- forcetypeassert
16+
- gci
17+
- gocheckcompilerdirectives
18+
- gofmt
1519
- goimports
16-
- gosimple
20+
- gomodguard
21+
- gosec
1722
- govet
1823
- ineffassign
24+
# TODO(arr4n): investigate ireturn
1925
- misspell
26+
- nakedret
27+
- nestif
28+
- nilerr
29+
- nolintlint
30+
- reassign
31+
- revive
32+
- sloglint
33+
- staticcheck
34+
- tagliatelle
35+
- testableexamples
36+
- testifylint
37+
- thelper
38+
- tparallel
2039
- unconvert
21-
- typecheck
40+
- usestdlibvars
2241
- unused
23-
- staticcheck
24-
- bidichk
25-
- durationcheck
26-
- exportloopref
2742
- whitespace
2843

29-
# - structcheck # lots of false positives
30-
# - errcheck #lot of false positives
31-
# - contextcheck
32-
# - errchkjson # lots of false positives
33-
# - errorlint # this check crashes
34-
# - exhaustive # silly check
35-
# - makezero # false positives
36-
# - nilerr # several intentional
37-
3844
linters-settings:
39-
gofmt:
40-
simplify: true
45+
gci:
46+
custom-order: true
47+
sections:
48+
- standard
49+
- default
50+
- localmodule
51+
# The rest of these break developer expections, in increasing order of
52+
# divergence, so are at the end to increase the chance of being seen.
53+
- alias
54+
- dot
55+
- blank
56+
gomodguard:
57+
blocked:
58+
modules:
59+
- github.com/ava-labs/avalanchego:
60+
- github.com/ava-labs/coreth:
61+
- github.com/ava-labs/subnet-evm:
62+
revive:
63+
rules:
64+
- name: unused-parameter
65+
# Method parameters may be equired by interfaces and forcing them to be
66+
# named _ is of questionable benefit.
67+
disabled: true
4168

4269
issues:
43-
exclude-rules:
44-
- path: crypto/bn256/cloudflare/optate.go
70+
exclude-dirs-use-default: false
71+
exclude-rules:
72+
- path-except: libevm
4573
linters:
46-
- deadcode
74+
# If any issue is flagged in a non-libevm file, add the linter here
75+
# because the problem isn't under our control.
76+
- containedctx
77+
- forcetypeassert
78+
- errcheck
79+
- gci
80+
- gofmt
81+
- gosec
82+
- gosimple
83+
- govet
84+
- nakedret
85+
- nestif
86+
- nilerr
87+
- nolintlint
88+
- revive
4789
- staticcheck
48-
- path: internal/build/pgp.go
49-
text: 'SA1019: "golang.org/x/crypto/openpgp" is deprecated: this package is unmaintained except for security fixes.'
50-
- path: core/vm/contracts.go
51-
text: 'SA1019: "golang.org/x/crypto/ripemd160" is deprecated: RIPEMD-160 is a legacy hash and should not be used for new applications.'
52-
- path: accounts/usbwallet/trezor.go
53-
text: 'SA1019: "github.com/golang/protobuf/proto" is deprecated: Use the "google.golang.org/protobuf/proto" package instead.'
54-
- path: accounts/usbwallet/trezor/
55-
text: 'SA1019: "github.com/golang/protobuf/proto" is deprecated: Use the "google.golang.org/protobuf/proto" package instead.'
56-
exclude:
57-
- 'SA1019: event.TypeMux is deprecated: use Feed'
58-
- 'SA1019: strings.Title is deprecated'
59-
- 'SA1019: strings.Title has been deprecated since Go 1.18 and an alternative has been available since Go 1.0: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead.'
60-
- 'SA1029: should not use built-in type string as key for value'
90+
- tagliatelle
91+
- testableexamples
92+
- testifylint
93+
- thelper
94+
- tparallel
95+
- usestdlibvars
96+
- varnamelen
97+
- wastedassign
98+
- whitespace
99+
include:
100+
# Many of the default exclusions are because, verbatim "Annoying issue",
101+
# which defeats the point of a linter.
102+
- EXC0002
103+
- EXC0004
104+
- EXC0005
105+
- EXC0006
106+
- EXC0007
107+
- EXC0008
108+
- EXC0009
109+
- EXC0010
110+
- EXC0011
111+
- EXC0012
112+
- EXC0013
113+
- EXC0014
114+
- EXC0015

core/state_transition.libevm_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/stretchr/testify/require"
8+
79
"github.com/ethereum/go-ethereum/common"
810
"github.com/ethereum/go-ethereum/core"
911
"github.com/ethereum/go-ethereum/libevm"
1012
"github.com/ethereum/go-ethereum/libevm/ethtest"
1113
"github.com/ethereum/go-ethereum/libevm/hookstest"
12-
"github.com/stretchr/testify/require"
1314
)
1415

1516
func TestCanExecuteTransaction(t *testing.T) {

core/vm/contracts.libevm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package vm
33
import (
44
"fmt"
55

6+
"github.com/holiman/uint256"
7+
68
"github.com/ethereum/go-ethereum/common"
79
"github.com/ethereum/go-ethereum/params"
8-
"github.com/holiman/uint256"
910
)
1011

1112
// evmCallArgs mirrors the parameters of the [EVM] methods Call(), CallCode(),

core/vm/contracts.libevm_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/holiman/uint256"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
"golang.org/x/exp/rand"
11+
712
"github.com/ethereum/go-ethereum/common"
813
"github.com/ethereum/go-ethereum/core/vm"
914
"github.com/ethereum/go-ethereum/crypto"
1015
"github.com/ethereum/go-ethereum/libevm"
1116
"github.com/ethereum/go-ethereum/libevm/ethtest"
1217
"github.com/ethereum/go-ethereum/libevm/hookstest"
1318
"github.com/ethereum/go-ethereum/params"
14-
"github.com/holiman/uint256"
15-
"github.com/stretchr/testify/assert"
16-
"github.com/stretchr/testify/require"
17-
"golang.org/x/exp/rand"
1819
)
1920

2021
type precompileStub struct {

libevm/ethtest/evm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ package ethtest
55
import (
66
"testing"
77

8+
"github.com/stretchr/testify/require"
9+
810
"github.com/ethereum/go-ethereum/common"
911
"github.com/ethereum/go-ethereum/core"
1012
"github.com/ethereum/go-ethereum/core/rawdb"
1113
"github.com/ethereum/go-ethereum/core/state"
1214
"github.com/ethereum/go-ethereum/core/vm"
1315
"github.com/ethereum/go-ethereum/params"
14-
"github.com/stretchr/testify/require"
1516
)
1617

1718
// NewZeroEVM returns a new EVM backed by a [rawdb.NewMemoryDatabase]; all other

libevm/ethtest/rand.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package ethtest
22

33
import (
4-
"github.com/ethereum/go-ethereum/common"
54
"golang.org/x/exp/rand"
5+
6+
"github.com/ethereum/go-ethereum/common"
67
)
78

89
// PseudoRand extends [rand.Rand] (*not* crypto/rand).
@@ -17,7 +18,7 @@ func NewPseudoRand(seed uint64) *PseudoRand {
1718

1819
// Address returns a pseudorandom address.
1920
func (r *PseudoRand) Address() (a common.Address) {
20-
r.Read(a[:])
21+
r.Read(a[:]) //nolint:gosec,errcheck // Guaranteed nil error
2122
return a
2223
}
2324

@@ -29,13 +30,13 @@ func (r *PseudoRand) AddressPtr() *common.Address {
2930

3031
// Hash returns a pseudorandom hash.
3132
func (r *PseudoRand) Hash() (h common.Hash) {
32-
r.Read(h[:])
33+
r.Read(h[:]) //nolint:gosec,errcheck // Guaranteed nil error
3334
return h
3435
}
3536

3637
// Bytes returns `n` pseudorandom bytes.
3738
func (r *PseudoRand) Bytes(n uint) []byte {
3839
b := make([]byte, n)
39-
r.Read(b)
40+
r.Read(b) //nolint:gosec,errcheck // Guaranteed nil error
4041
return b
4142
}

libevm/hookstest/stub.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
)
1313

1414
// Register clears any registered [params.Extras] and then registers `extras`
15-
// for the liftime of the current test, clearing them via tb's
15+
// for the lifetime of the current test, clearing them via tb's
1616
// [testing.TB.Cleanup].
1717
func Register[C params.ChainConfigHooks, R params.RulesHooks](tb testing.TB, extras params.Extras[C, R]) {
18+
tb.Helper()
1819
params.TestOnlyClearRegisteredExtras()
1920
tb.Cleanup(params.TestOnlyClearRegisteredExtras)
2021
params.RegisterExtras(extras)
@@ -32,13 +33,17 @@ type Stub struct {
3233
// Register is a convenience wrapper for registering s as both the
3334
// [params.ChainConfigHooks] and [params.RulesHooks] via [Register].
3435
func (s *Stub) Register(tb testing.TB) {
36+
tb.Helper()
3537
Register(tb, params.Extras[*Stub, *Stub]{
3638
NewRules: func(_ *params.ChainConfig, _ *params.Rules, _ *Stub, blockNum *big.Int, isMerge bool, timestamp uint64) *Stub {
3739
return s
3840
},
3941
})
4042
}
4143

44+
// PrecompileOverride uses the s.PrecompileOverrides map, if non-empty, as the
45+
// canonical source of all overrides. If the map is empty then no precompiles
46+
// are overridden.
4247
func (s Stub) PrecompileOverride(a common.Address) (libevm.PrecompiledContract, bool) {
4348
if len(s.PrecompileOverrides) == 0 {
4449
return nil, false
@@ -47,13 +52,17 @@ func (s Stub) PrecompileOverride(a common.Address) (libevm.PrecompiledContract,
4752
return p, ok
4853
}
4954

55+
// CanExecuteTransaction proxies arguments to the s.CanExecuteTransactionFn
56+
// function if non-nil, otherwise it acts as a noop.
5057
func (s Stub) CanExecuteTransaction(from common.Address, to *common.Address, sr libevm.StateReader) error {
5158
if f := s.CanExecuteTransactionFn; f != nil {
5259
return f(from, to, sr)
5360
}
5461
return nil
5562
}
5663

64+
// CanCreateContract proxies arguments to the s.CanCreateContractFn function if
65+
// non-nil, otherwise it acts as a noop.
5766
func (s Stub) CanCreateContract(cc *libevm.AddressContext, sr libevm.StateReader) error {
5867
if f := s.CanCreateContractFn; f != nil {
5968
return f(cc, sr)

libevm/libevm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package libevm
22

33
import (
4-
"github.com/ethereum/go-ethereum/common"
54
"github.com/holiman/uint256"
5+
6+
"github.com/ethereum/go-ethereum/common"
67
)
78

89
// PrecompiledContract is an exact copy of vm.PrecompiledContract, mirrored here

0 commit comments

Comments
 (0)