Skip to content

Commit e5e1d20

Browse files
authored
Merge pull request #1609 from antonydenyer/fixLint
all: more linters (#24783)
2 parents 28721bf + a520323 commit e5e1d20

File tree

335 files changed

+1094
-1915
lines changed

Some content is hidden

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

335 files changed

+1094
-1915
lines changed

.golangci.yml

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file configures github.com/golangci/golangci-lint.
22

33
run:
4-
timeout: 5m
4+
timeout: 20m
55
tests: true
66
# default is true. Enables skipping of directories:
77
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
@@ -12,19 +12,29 @@ run:
1212
linters:
1313
disable-all: true
1414
enable:
15-
- deadcode
1615
- goconst
1716
- goimports
1817
- gosimple
1918
- govet
2019
- ineffassign
2120
- misspell
22-
# - staticcheck
2321
- unconvert
24-
# - unused
25-
- varcheck
2622
- typecheck
23+
- unused
24+
- staticcheck
25+
- bidichk
26+
- durationcheck
27+
- exportloopref
28+
- whitespace
2729

30+
# - structcheck # lots of false positives
31+
# - errcheck #lot of false positives
32+
# - contextcheck
33+
# - errchkjson # lots of false positives
34+
# - errorlint # this check crashes
35+
# - exhaustive # silly check
36+
# - makezero # false positives
37+
# - nilerr # several intentional
2838

2939
linters-settings:
3040
gofmt:
@@ -34,20 +44,27 @@ linters-settings:
3444
min-occurrences: 6 # minimum number of occurrences
3545

3646
issues:
37-
new-from-rev: c4e9657
3847
exclude-rules:
39-
- path: crypto/blake2b/
40-
linters:
41-
- deadcode
42-
- path: crypto/bn256/cloudflare
43-
linters:
44-
- deadcode
45-
- path: p2p/discv5/
46-
linters:
47-
- deadcode
48-
- path: core/vm/instructions_test.go
49-
linters:
50-
- goconst
51-
- path: cmd/faucet/
48+
- path: crypto/bn256/cloudflare/optate.go
5249
linters:
5350
- deadcode
51+
- staticcheck
52+
- path: internal/build/pgp.go
53+
text: 'SA1019: "golang.org/x/crypto/openpgp" is deprecated: this package is unmaintained except for security fixes.'
54+
- path: core/vm/contracts.go
55+
text: 'SA1019: "golang.org/x/crypto/ripemd160" is deprecated: RIPEMD-160 is a legacy hash and should not be used for new applications.'
56+
- path: accounts/usbwallet/trezor.go
57+
text: 'SA1019: "github.com/golang/protobuf/proto" is deprecated: Use the "google.golang.org/protobuf/proto" package instead.'
58+
- path: accounts/usbwallet/trezor/
59+
text: 'SA1019: "github.com/golang/protobuf/proto" is deprecated: Use the "google.golang.org/protobuf/proto" package instead.'
60+
- path: plugin/account/internal/testutils/matchers.go
61+
text: 'SA1019: "github.com/golang/protobuf/proto" is deprecated: Use the "google.golang.org/protobuf/proto" package instead.'
62+
- path: rpc/
63+
text: 'SA1019: "github.com/golang/protobuf/proto" is deprecated: Use the "google.golang.org/protobuf/proto" package instead.'
64+
- path: rpc/
65+
text: 'SA1019: "github.com/golang/protobuf/ptypes" is deprecated: Well-known types have specialized functionality directly injected into the generated packages for each message type. See the deprecation notice for each function for the suggested alternative'
66+
exclude:
67+
- 'SA1019: event.TypeMux is deprecated: use Feed'
68+
- 'SA1019: strings.Title is deprecated'
69+
- '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.'
70+
- 'SA1029: should not use built-in type string as key for value'

accounts/abi/abi_test.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ func TestInvalidABI(t *testing.T) {
165165

166166
// TestConstructor tests a constructor function.
167167
// The test is based on the following contract:
168-
// contract TestConstructor {
169-
// constructor(uint256 a, uint256 b) public{}
168+
//
169+
// contract TestConstructor {
170+
// constructor(uint256 a, uint256 b) public{}
170171
// }
171172
func TestConstructor(t *testing.T) {
172173
json := `[{ "inputs": [{"internalType": "uint256","name": "a","type": "uint256" },{ "internalType": "uint256","name": "b","type": "uint256"}],"stateMutability": "nonpayable","type": "constructor"}]`
@@ -710,16 +711,19 @@ func TestBareEvents(t *testing.T) {
710711
}
711712

712713
// TestUnpackEvent is based on this contract:
713-
// contract T {
714-
// event received(address sender, uint amount, bytes memo);
715-
// event receivedAddr(address sender);
716-
// function receive(bytes memo) external payable {
717-
// received(msg.sender, msg.value, memo);
718-
// receivedAddr(msg.sender);
719-
// }
720-
// }
714+
//
715+
// contract T {
716+
// event received(address sender, uint amount, bytes memo);
717+
// event receivedAddr(address sender);
718+
// function receive(bytes memo) external payable {
719+
// received(msg.sender, msg.value, memo);
720+
// receivedAddr(msg.sender);
721+
// }
722+
// }
723+
//
721724
// When receive("X") is called with sender 0x00... and value 1, it produces this tx receipt:
722-
// receipt{status=1 cgas=23949 bloom=00000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000040200000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 logs=[log: b6818c8064f645cd82d99b59a1a267d6d61117ef [75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed] 000000000000000000000000376c47978271565f56deb45495afa69e59c16ab200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158 9ae378b6d4409eada347a5dc0c180f186cb62dc68fcc0f043425eb917335aa28 0 95d429d309bb9d753954195fe2d69bd140b4ae731b9b5b605c34323de162cf00 0]}
725+
//
726+
// receipt{status=1 cgas=23949 bloom=00000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000040200000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 logs=[log: b6818c8064f645cd82d99b59a1a267d6d61117ef [75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed] 000000000000000000000000376c47978271565f56deb45495afa69e59c16ab200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158 9ae378b6d4409eada347a5dc0c180f186cb62dc68fcc0f043425eb917335aa28 0 95d429d309bb9d753954195fe2d69bd140b4ae731b9b5b605c34323de162cf00 0]}
723727
func TestUnpackEvent(t *testing.T) {
724728
const abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"receive","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"memo","type":"bytes"}],"name":"received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"}],"name":"receivedAddr","type":"event"}]`
725729
abi, err := JSON(strings.NewReader(abiJSON))
@@ -1024,9 +1028,7 @@ func TestABI_EventById(t *testing.T) {
10241028
}
10251029
if event == nil {
10261030
t.Errorf("We should find a event for topic %s, test #%d", topicID.Hex(), testnum)
1027-
}
1028-
1029-
if event.ID != topicID {
1031+
} else if event.ID != topicID {
10301032
t.Errorf("Event id %s does not match topic %s, test #%d", event.ID.Hex(), topicID.Hex(), testnum)
10311033
}
10321034

@@ -1066,8 +1068,9 @@ func TestDoubleDuplicateMethodNames(t *testing.T) {
10661068
// TestDoubleDuplicateEventNames checks that if send0 already exists, there won't be a name
10671069
// conflict and that the second send event will be renamed send1.
10681070
// The test runs the abi of the following contract.
1069-
// contract DuplicateEvent {
1070-
// event send(uint256 a);
1071+
//
1072+
// contract DuplicateEvent {
1073+
// event send(uint256 a);
10711074
// event send0();
10721075
// event send();
10731076
// }
@@ -1094,7 +1097,8 @@ func TestDoubleDuplicateEventNames(t *testing.T) {
10941097
// TestUnnamedEventParam checks that an event with unnamed parameters is
10951098
// correctly handled.
10961099
// The test runs the abi of the following contract.
1097-
// contract TestEvent {
1100+
//
1101+
// contract TestEvent {
10981102
// event send(uint256, uint256);
10991103
// }
11001104
func TestUnnamedEventParam(t *testing.T) {

accounts/abi/bind/backends/simulated.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ func (b *SimulatedBackend) CodeAt(ctx context.Context, contract common.Address,
165165
b.mu.Lock()
166166
defer b.mu.Unlock()
167167

168-
stateDB, err := b.stateByBlockNumber(ctx, blockNumber)
168+
_, err := b.stateByBlockNumber(ctx, blockNumber)
169169
if err != nil {
170170
return nil, err
171171
}
172-
stateDB, _, _ = b.blockchain.State()
172+
stateDB, _, _ := b.blockchain.State()
173173
return stateDB.GetCode(contract), nil
174174
}
175175

@@ -178,11 +178,11 @@ func (b *SimulatedBackend) BalanceAt(ctx context.Context, contract common.Addres
178178
b.mu.Lock()
179179
defer b.mu.Unlock()
180180

181-
stateDB, err := b.stateByBlockNumber(ctx, blockNumber)
181+
_, err := b.stateByBlockNumber(ctx, blockNumber)
182182
if err != nil {
183183
return nil, err
184184
}
185-
stateDB, _, _ = b.blockchain.State()
185+
stateDB, _, _ := b.blockchain.State()
186186
return stateDB.GetBalance(contract), nil
187187
}
188188

@@ -191,11 +191,11 @@ func (b *SimulatedBackend) NonceAt(ctx context.Context, contract common.Address,
191191
b.mu.Lock()
192192
defer b.mu.Unlock()
193193

194-
stateDB, err := b.stateByBlockNumber(ctx, blockNumber)
194+
_, err := b.stateByBlockNumber(ctx, blockNumber)
195195
if err != nil {
196196
return 0, err
197197
}
198-
stateDB, _, _ = b.blockchain.State()
198+
stateDB, _, _ := b.blockchain.State()
199199
return stateDB.GetNonce(contract), nil
200200
}
201201

@@ -204,11 +204,11 @@ func (b *SimulatedBackend) StorageAt(ctx context.Context, contract common.Addres
204204
b.mu.Lock()
205205
defer b.mu.Unlock()
206206

207-
stateDB, err := b.stateByBlockNumber(ctx, blockNumber)
207+
_, err := b.stateByBlockNumber(ctx, blockNumber)
208208
if err != nil {
209209
return nil, err
210210
}
211-
stateDB, _, _ = b.blockchain.State()
211+
stateDB, _, _ := b.blockchain.State()
212212
val := stateDB.GetState(contract, key)
213213
return val[:], nil
214214
}

accounts/abi/bind/backends/simulated_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestSimulatedBackend(t *testing.T) {
7878
}
7979

8080
sim.Commit()
81-
tx, isPending, err = sim.TransactionByHash(context.Background(), txHash)
81+
_, isPending, err = sim.TransactionByHash(context.Background(), txHash)
8282
if err != nil {
8383
t.Fatalf("error getting transaction with hash: %v", txHash.String())
8484
}
@@ -89,17 +89,17 @@ func TestSimulatedBackend(t *testing.T) {
8989

9090
var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
9191

92-
// the following is based on this contract:
93-
// contract T {
94-
// event received(address sender, uint amount, bytes memo);
95-
// event receivedAddr(address sender);
92+
// the following is based on this contract:
93+
// contract T {
94+
// event received(address sender, uint amount, bytes memo);
95+
// event receivedAddr(address sender);
9696
//
97-
// function receive(bytes calldata memo) external payable returns (string memory res) {
98-
// emit received(msg.sender, msg.value, memo);
99-
// emit receivedAddr(msg.sender);
100-
// return "hello world";
101-
// }
102-
// }
97+
// function receive(bytes calldata memo) external payable returns (string memory res) {
98+
// emit received(msg.sender, msg.value, memo);
99+
// emit receivedAddr(msg.sender);
100+
// return "hello world";
101+
// }
102+
// }
103103
const abiJSON = `[ { "constant": false, "inputs": [ { "name": "memo", "type": "bytes" } ], "name": "receive", "outputs": [ { "name": "res", "type": "string" } ], "payable": true, "stateMutability": "payable", "type": "function" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "sender", "type": "address" }, { "indexed": false, "name": "amount", "type": "uint256" }, { "indexed": false, "name": "memo", "type": "bytes" } ], "name": "received", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "sender", "type": "address" } ], "name": "receivedAddr", "type": "event" } ]`
104104
const abiBin = `0x608060405234801561001057600080fd5b506102a0806100206000396000f3fe60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063a69b6ed014610040575b600080fd5b6100b76004803603602081101561005657600080fd5b810190808035906020019064010000000081111561007357600080fd5b82018360208201111561008557600080fd5b803590602001918460018302840111640100000000831117156100a757600080fd5b9091929391929390505050610132565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f75780820151818401526020810190506100dc565b50505050905090810190601f1680156101245780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60607f75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed33348585604051808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509550505050505060405180910390a17f46923992397eac56cf13058aced2a1871933622717e27b24eabc13bf9dd329c833604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a16040805190810160405280600b81526020017f68656c6c6f20776f726c6400000000000000000000000000000000000000000081525090509291505056fea165627a7a72305820ff0c57dad254cfeda48c9cfb47f1353a558bccb4d1bc31da1dae69315772d29e0029`
105105
const deployedCode = `60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063a69b6ed014610040575b600080fd5b6100b76004803603602081101561005657600080fd5b810190808035906020019064010000000081111561007357600080fd5b82018360208201111561008557600080fd5b803590602001918460018302840111640100000000831117156100a757600080fd5b9091929391929390505050610132565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f75780820151818401526020810190506100dc565b50505050905090810190601f1680156101245780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60607f75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed33348585604051808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509550505050505060405180910390a17f46923992397eac56cf13058aced2a1871933622717e27b24eabc13bf9dd329c833604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a16040805190810160405280600b81526020017f68656c6c6f20776f726c6400000000000000000000000000000000000000000081525090509291505056fea165627a7a72305820ff0c57dad254cfeda48c9cfb47f1353a558bccb4d1bc31da1dae69315772d29e0029`
@@ -621,8 +621,7 @@ func TestSimulatedBackend_HeaderByNumber(t *testing.T) {
621621
}
622622
if latestBlockHeader == nil {
623623
t.Errorf("received a nil block header")
624-
}
625-
if latestBlockHeader.Number.Uint64() != uint64(0) {
624+
} else if latestBlockHeader.Number.Uint64() != uint64(0) {
626625
t.Errorf("expected block header number 0, instead got %v", latestBlockHeader.Number.Uint64())
627626
}
628627

@@ -951,7 +950,8 @@ func TestSimulatedBackend_CodeAt(t *testing.T) {
951950
}
952951

953952
// When receive("X") is called with sender 0x00... and value 1, it produces this tx receipt:
954-
// receipt{status=1 cgas=23949 bloom=00000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000040200000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 logs=[log: b6818c8064f645cd82d99b59a1a267d6d61117ef [75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed] 000000000000000000000000376c47978271565f56deb45495afa69e59c16ab200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158 9ae378b6d4409eada347a5dc0c180f186cb62dc68fcc0f043425eb917335aa28 0 95d429d309bb9d753954195fe2d69bd140b4ae731b9b5b605c34323de162cf00 0]}
953+
//
954+
// receipt{status=1 cgas=23949 bloom=00000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000040200000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 logs=[log: b6818c8064f645cd82d99b59a1a267d6d61117ef [75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed] 000000000000000000000000376c47978271565f56deb45495afa69e59c16ab200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158 9ae378b6d4409eada347a5dc0c180f186cb62dc68fcc0f043425eb917335aa28 0 95d429d309bb9d753954195fe2d69bd140b4ae731b9b5b605c34323de162cf00 0]}
955955
func TestSimulatedBackend_PendingAndCallContract(t *testing.T) {
956956
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
957957
sim := simTestBackend(testAddr)

accounts/abi/bind/base_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func (mc *mockCaller) PendingCallContract(ctx context.Context, call ethereum.Cal
6060
return nil, nil
6161
}
6262
func TestPassingBlockNumber(t *testing.T) {
63-
6463
mc := &mockCaller{}
6564

6665
bc := bind.NewBoundContract(common.HexToAddress("0x0"), abi.ABI{

accounts/abi/error.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ func typeCheck(t Type, value reflect.Value) error {
7373
} else {
7474
return nil
7575
}
76-
7776
}
7877

7978
// typeErr returns a formatted type casting error.

accounts/abi/event_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ func TestEventMultiValueWithArrayUnpack(t *testing.T) {
161161
}
162162

163163
func TestEventTupleUnpack(t *testing.T) {
164-
165164
type EventTransfer struct {
166165
Value *big.Int
167166
}

accounts/abi/reflect.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ import (
2828
// given type
2929
// e.g. turn
3030
// var fields []reflect.StructField
31-
// fields = append(fields, reflect.StructField{
32-
// Name: "X",
33-
// Type: reflect.TypeOf(new(big.Int)),
34-
// Tag: reflect.StructTag("json:\"" + "x" + "\""),
35-
// }
31+
//
32+
// fields = append(fields, reflect.StructField{
33+
// Name: "X",
34+
// Type: reflect.TypeOf(new(big.Int)),
35+
// Tag: reflect.StructTag("json:\"" + "x" + "\""),
36+
// }
37+
//
3638
// into
3739
// type TupleT struct { X *big.Int }
3840
func ConvertType(in interface{}, proto interface{}) interface{} {
@@ -178,10 +180,14 @@ func setStruct(dst, src reflect.Value) error {
178180

179181
// mapArgNamesToStructFields maps a slice of argument names to struct fields.
180182
// first round: for each Exportable field that contains a `abi:""` tag
181-
// and this field name exists in the given argument name list, pair them together.
183+
//
184+
// and this field name exists in the given argument name list, pair them together.
185+
//
182186
// second round: for each argument name that has not been already linked,
183-
// find what variable is expected to be mapped into, if it exists and has not been
184-
// used, pair them.
187+
//
188+
// find what variable is expected to be mapped into, if it exists and has not been
189+
// used, pair them.
190+
//
185191
// Note this function assumes the given value is a struct value.
186192
func mapArgNamesToStructFields(argNames []string, value reflect.Value) (map[string]string, error) {
187193
typ := value.Type()
@@ -227,7 +233,6 @@ func mapArgNamesToStructFields(argNames []string, value reflect.Value) (map[stri
227233

228234
// second round ~~~
229235
for _, argName := range argNames {
230-
231236
structFieldName := ToCamelCase(argName)
232237

233238
if structFieldName == "" {

accounts/abi/unpack.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ func ReadFixedBytes(t Type, word []byte) (interface{}, error) {
115115

116116
reflect.Copy(array, reflect.ValueOf(word[0:t.Size]))
117117
return array.Interface(), nil
118-
119118
}
120119

121120
// forEachUnpack iteratively unpack elements.

0 commit comments

Comments
 (0)