Skip to content

Commit 12b9926

Browse files
committed
Add golangci-lint
1 parent fb777d1 commit 12b9926

File tree

239 files changed

+831
-978
lines changed

Some content is hidden

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

239 files changed

+831
-978
lines changed

.golangci.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This file configures github.com/golangci/golangci-lint.
2+
3+
run:
4+
timeout: 20m
5+
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
11+
12+
linters:
13+
disable-all: true
14+
enable:
15+
- goconst
16+
- goimports
17+
- gosimple
18+
- govet
19+
- ineffassign
20+
- misspell
21+
- unconvert
22+
- typecheck
23+
- unused
24+
- staticcheck
25+
- bidichk
26+
- durationcheck
27+
- exportloopref
28+
- whitespace
29+
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
38+
39+
linters-settings:
40+
gofmt:
41+
simplify: true
42+
goconst:
43+
min-len: 3 # minimum length of string constant
44+
min-occurrences: 6 # minimum number of occurrences
45+
46+
issues:
47+
exclude-rules:
48+
- path: crypto/bn256/cloudflare/optate.go
49+
linters:
50+
- 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

+20-14
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))
@@ -1066,8 +1070,9 @@ func TestDoubleDuplicateMethodNames(t *testing.T) {
10661070
// TestDoubleDuplicateEventNames checks that if send0 already exists, there won't be a name
10671071
// conflict and that the second send event will be renamed send1.
10681072
// The test runs the abi of the following contract.
1069-
// contract DuplicateEvent {
1070-
// event send(uint256 a);
1073+
//
1074+
// contract DuplicateEvent {
1075+
// event send(uint256 a);
10711076
// event send0();
10721077
// event send();
10731078
// }
@@ -1094,7 +1099,8 @@ func TestDoubleDuplicateEventNames(t *testing.T) {
10941099
// TestUnnamedEventParam checks that an event with unnamed parameters is
10951100
// correctly handled.
10961101
// The test runs the abi of the following contract.
1097-
// contract TestEvent {
1102+
//
1103+
// contract TestEvent {
10981104
// event send(uint256, uint256);
10991105
// }
11001106
func TestUnnamedEventParam(t *testing.T) {

accounts/abi/bind/backends/simulated_test.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -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`
@@ -951,7 +951,8 @@ func TestSimulatedBackend_CodeAt(t *testing.T) {
951951
}
952952

953953
// 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]}
954+
//
955+
// receipt{status=1 cgas=23949 bloom=00000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000040200000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 logs=[log: b6818c8064f645cd82d99b59a1a267d6d61117ef [75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed] 000000000000000000000000376c47978271565f56deb45495afa69e59c16ab200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158 9ae378b6d4409eada347a5dc0c180f186cb62dc68fcc0f043425eb917335aa28 0 95d429d309bb9d753954195fe2d69bd140b4ae731b9b5b605c34323de162cf00 0]}
955956
func TestSimulatedBackend_PendingAndCallContract(t *testing.T) {
956957
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
957958
sim := simTestBackend(testAddr)

accounts/abi/bind/base_test.go

-1
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/bind/bind.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
235235
// bindType is a set of type binders that convert Solidity types to some supported
236236
// programming language types.
237237
var bindType = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct) string{
238-
LangGo: bindTypeGo,
238+
LangGo: bindTypeGo,
239239
}
240240

241241
// bindBasicTypeGo converts basic solidity types(except array, slice and tuple) to Go ones.
@@ -281,7 +281,7 @@ func bindTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
281281
// bindTopicType is a set of type binders that convert Solidity types to some
282282
// supported programming language topic types.
283283
var bindTopicType = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct) string{
284-
LangGo: bindTopicTypeGo,
284+
LangGo: bindTopicTypeGo,
285285
}
286286

287287
// bindTopicTypeGo converts a Solidity topic type to a Go one. It is almost the same
@@ -304,7 +304,7 @@ func bindTopicTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
304304
// bindStructType is a set of type binders that convert Solidity tuple types to some supported
305305
// programming language struct definition.
306306
var bindStructType = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct) string{
307-
LangGo: bindStructTypeGo,
307+
LangGo: bindStructTypeGo,
308308
}
309309

310310
// bindStructTypeGo converts a Solidity tuple type to a Go one and records the mapping
@@ -349,7 +349,7 @@ func bindStructTypeGo(kind abi.Type, structs map[string]*tmplStruct) string {
349349
// namedType is a set of functions that transform language specific types to
350350
// named versions that may be used inside method names.
351351
var namedType = map[Lang]func(string, abi.Type) string{
352-
LangGo: func(string, abi.Type) string { panic("this shouldn't be needed") },
352+
LangGo: func(string, abi.Type) string { panic("this shouldn't be needed") },
353353
}
354354

355355
// alias returns an alias of the given string based on the aliasing rules
@@ -364,7 +364,7 @@ func alias(aliases map[string]string, n string) string {
364364
// methodNormalizer is a name transformer that modifies Solidity method names to
365365
// conform to target language naming conventions.
366366
var methodNormalizer = map[Lang]func(string) string{
367-
LangGo: abi.ToCamelCase,
367+
LangGo: abi.ToCamelCase,
368368
}
369369

370370
// capitalise makes a camel-case string which starts with an upper case character.

accounts/abi/bind/template.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type tmplStruct struct {
7575
// tmplSource is language to template mapping containing all the supported
7676
// programming languages the package can generate to.
7777
var tmplSource = map[Lang]string{
78-
LangGo: tmplSourceGo,
78+
LangGo: tmplSourceGo,
7979
}
8080

8181
// tmplSourceGo is the Go source template that the generated Go contract binding

accounts/abi/error.go

-1
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

-1
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

+14-9
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

-1
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)