Skip to content

Commit ac93a6f

Browse files
authored
Merge pull request #3525 from fjl/all-gosimple-cleanup
all: clean up lint issues, remove more dead code
2 parents 444fc89 + 13e3b2f commit ac93a6f

File tree

118 files changed

+444
-1976
lines changed

Some content is hidden

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

118 files changed

+444
-1976
lines changed

accounts/abi/abi_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ func TestTypeCheck(t *testing.T) {
6767
{"uint16[3]", [4]uint16{1, 2, 3}, "abi: cannot use [4]uint16 as type [3]uint16 as argument"},
6868
{"uint16[3]", []uint16{1, 2, 3}, ""},
6969
{"uint16[3]", []uint16{1, 2, 3, 4}, "abi: cannot use [4]uint16 as type [3]uint16 as argument"},
70-
{"address[]", []common.Address{common.Address{1}}, ""},
71-
{"address[1]", []common.Address{common.Address{1}}, ""},
72-
{"address[1]", [1]common.Address{common.Address{1}}, ""},
73-
{"address[2]", [1]common.Address{common.Address{1}}, "abi: cannot use [1]array as type [2]array as argument"},
70+
{"address[]", []common.Address{{1}}, ""},
71+
{"address[1]", []common.Address{{1}}, ""},
72+
{"address[1]", [1]common.Address{{1}}, ""},
73+
{"address[2]", [1]common.Address{{1}}, "abi: cannot use [1]array as type [2]array as argument"},
7474
{"bytes32", [32]byte{}, ""},
7575
{"bytes32", [33]byte{}, "abi: cannot use [33]uint8 as type [32]uint8 as argument"},
7676
{"bytes32", common.Hash{1}, ""},
@@ -80,7 +80,7 @@ func TestTypeCheck(t *testing.T) {
8080
{"bytes", [2]byte{0, 1}, ""},
8181
{"bytes", common.Hash{1}, ""},
8282
{"string", "hello world", ""},
83-
{"bytes32[]", [][32]byte{[32]byte{}}, ""},
83+
{"bytes32[]", [][32]byte{{}}, ""},
8484
{"function", [24]byte{}, ""},
8585
} {
8686
typ, err := NewType(test.typ)
@@ -343,8 +343,8 @@ func TestPack(t *testing.T) {
343343
{"uint16[]", []uint16{1, 2}, formatSliceOutput([]byte{1}, []byte{2})},
344344
{"bytes20", [20]byte{1}, pad([]byte{1}, 32, false)},
345345
{"uint256[]", []*big.Int{big.NewInt(1), big.NewInt(2)}, formatSliceOutput([]byte{1}, []byte{2})},
346-
{"address[]", []common.Address{common.Address{1}, common.Address{2}}, formatSliceOutput(pad([]byte{1}, 20, false), pad([]byte{2}, 20, false))},
347-
{"bytes32[]", []common.Hash{common.Hash{1}, common.Hash{2}}, formatSliceOutput(pad([]byte{1}, 32, false), pad([]byte{2}, 32, false))},
346+
{"address[]", []common.Address{{1}, {2}}, formatSliceOutput(pad([]byte{1}, 20, false), pad([]byte{2}, 20, false))},
347+
{"bytes32[]", []common.Hash{{1}, {2}}, formatSliceOutput(pad([]byte{1}, 32, false), pad([]byte{2}, 32, false))},
348348
{"function", [24]byte{1}, pad([]byte{1}, 32, false)},
349349
} {
350350
typ, err := NewType(test.typ)
@@ -458,12 +458,12 @@ func TestReader(t *testing.T) {
458458
Uint256, _ := NewType("uint256")
459459
exp := ABI{
460460
Methods: map[string]Method{
461-
"balance": Method{
461+
"balance": {
462462
"balance", true, nil, nil,
463463
},
464-
"send": Method{
464+
"send": {
465465
"send", false, []Argument{
466-
Argument{"amount", Uint256, false},
466+
{"amount", Uint256, false},
467467
}, nil,
468468
},
469469
},
@@ -562,7 +562,7 @@ func TestTestSlice(t *testing.T) {
562562

563563
func TestMethodSignature(t *testing.T) {
564564
String, _ := NewType("string")
565-
m := Method{"foo", false, []Argument{Argument{"bar", String, false}, Argument{"baz", String, false}}, nil}
565+
m := Method{"foo", false, []Argument{{"bar", String, false}, {"baz", String, false}}, nil}
566566
exp := "foo(string,string)"
567567
if m.Sig() != exp {
568568
t.Error("signature mismatch", exp, "!=", m.Sig())
@@ -574,7 +574,7 @@ func TestMethodSignature(t *testing.T) {
574574
}
575575

576576
uintt, _ := NewType("uint")
577-
m = Method{"foo", false, []Argument{Argument{"bar", uintt, false}}, nil}
577+
m = Method{"foo", false, []Argument{{"bar", uintt, false}}, nil}
578578
exp = "foo(uint256)"
579579
if m.Sig() != exp {
580580
t.Error("signature mismatch", exp, "!=", m.Sig())
@@ -779,8 +779,8 @@ func TestBareEvents(t *testing.T) {
779779
"balance": {false, nil},
780780
"anon": {true, nil},
781781
"args": {false, []Argument{
782-
Argument{Name: "arg0", Type: arg0, Indexed: false},
783-
Argument{Name: "arg1", Type: arg1, Indexed: true},
782+
{Name: "arg0", Type: arg0, Indexed: false},
783+
{Name: "arg1", Type: arg1, Indexed: true},
784784
}},
785785
}
786786

accounts/abi/bind/bind.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,21 @@ func bindTypeGo(kind abi.Type) string {
147147

148148
switch {
149149
case strings.HasPrefix(stringKind, "address"):
150-
parts := regexp.MustCompile("address(\\[[0-9]*\\])?").FindStringSubmatch(stringKind)
150+
parts := regexp.MustCompile(`address(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
151151
if len(parts) != 2 {
152152
return stringKind
153153
}
154154
return fmt.Sprintf("%scommon.Address", parts[1])
155155

156156
case strings.HasPrefix(stringKind, "bytes"):
157-
parts := regexp.MustCompile("bytes([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind)
157+
parts := regexp.MustCompile(`bytes([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
158158
if len(parts) != 3 {
159159
return stringKind
160160
}
161161
return fmt.Sprintf("%s[%s]byte", parts[2], parts[1])
162162

163163
case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"):
164-
parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind)
164+
parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
165165
if len(parts) != 4 {
166166
return stringKind
167167
}
@@ -172,7 +172,7 @@ func bindTypeGo(kind abi.Type) string {
172172
return fmt.Sprintf("%s*big.Int", parts[3])
173173

174174
case strings.HasPrefix(stringKind, "bool") || strings.HasPrefix(stringKind, "string"):
175-
parts := regexp.MustCompile("([a-z]+)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind)
175+
parts := regexp.MustCompile(`([a-z]+)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
176176
if len(parts) != 3 {
177177
return stringKind
178178
}
@@ -191,7 +191,7 @@ func bindTypeJava(kind abi.Type) string {
191191

192192
switch {
193193
case strings.HasPrefix(stringKind, "address"):
194-
parts := regexp.MustCompile("address(\\[[0-9]*\\])?").FindStringSubmatch(stringKind)
194+
parts := regexp.MustCompile(`address(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
195195
if len(parts) != 2 {
196196
return stringKind
197197
}
@@ -201,7 +201,7 @@ func bindTypeJava(kind abi.Type) string {
201201
return fmt.Sprintf("Addresses")
202202

203203
case strings.HasPrefix(stringKind, "bytes"):
204-
parts := regexp.MustCompile("bytes([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind)
204+
parts := regexp.MustCompile(`bytes([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
205205
if len(parts) != 3 {
206206
return stringKind
207207
}
@@ -211,7 +211,7 @@ func bindTypeJava(kind abi.Type) string {
211211
return "byte[]"
212212

213213
case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"):
214-
parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind)
214+
parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
215215
if len(parts) != 4 {
216216
return stringKind
217217
}
@@ -230,7 +230,7 @@ func bindTypeJava(kind abi.Type) string {
230230
return fmt.Sprintf("BigInts")
231231

232232
case strings.HasPrefix(stringKind, "bool"):
233-
parts := regexp.MustCompile("bool(\\[[0-9]*\\])?").FindStringSubmatch(stringKind)
233+
parts := regexp.MustCompile(`bool(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
234234
if len(parts) != 2 {
235235
return stringKind
236236
}
@@ -240,7 +240,7 @@ func bindTypeJava(kind abi.Type) string {
240240
return fmt.Sprintf("bool[]")
241241

242242
case strings.HasPrefix(stringKind, "string"):
243-
parts := regexp.MustCompile("string(\\[[0-9]*\\])?").FindStringSubmatch(stringKind)
243+
parts := regexp.MustCompile(`string(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
244244
if len(parts) != 2 {
245245
return stringKind
246246
}
@@ -278,7 +278,7 @@ func namedTypeJava(javaKind string, solKind abi.Type) string {
278278
case "bool[]":
279279
return "Bools"
280280
case "BigInt":
281-
parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(solKind.String())
281+
parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(solKind.String())
282282
if len(parts) != 4 {
283283
return javaKind
284284
}

accounts/abi/type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var (
6565
// string int uint fixed
6666
// string32 int8 uint8 uint[]
6767
// address int256 uint256 fixed128x128[2]
68-
fullTypeRegex = regexp.MustCompile("([a-zA-Z0-9]+)(\\[([0-9]*)\\])?")
68+
fullTypeRegex = regexp.MustCompile(`([a-zA-Z0-9]+)(\[([0-9]*)\])?`)
6969
// typeRegex parses the abi sub types
7070
typeRegex = regexp.MustCompile("([a-zA-Z]+)(([0-9]+)(x([0-9]+))?)?")
7171
)

build/ci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func doInstall(cmdline []string) {
195195
if err != nil {
196196
log.Fatal(err)
197197
}
198-
for name, _ := range pkgs {
198+
for name := range pkgs {
199199
if name == "main" {
200200
gobuild := goToolArch(*arch, "build", buildFlags(env)...)
201201
gobuild.Args = append(gobuild.Args, "-v")

cmd/ethtest/main.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ func runTestWithReader(test string, r io.Reader) error {
8888
default:
8989
err = fmt.Errorf("Invalid test type specified: %v", test)
9090
}
91-
92-
if err != nil {
93-
return err
94-
}
95-
96-
return nil
91+
return err
9792
}
9893

9994
func getFiles(path string) ([]string, error) {

cmd/geth/accountcmd_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Passphrase: {{.InputLine "foobar"}}
148148
"Unlocked account f466859ead1932d743d622cb74fc058882e8648a",
149149
}
150150
for _, m := range wantMessages {
151-
if strings.Index(geth.stderrText(), m) == -1 {
151+
if !strings.Contains(geth.stderrText(), m) {
152152
t.Errorf("stderr text does not contain %q", m)
153153
}
154154
}
@@ -193,7 +193,7 @@ Passphrase: {{.InputLine "foobar"}}
193193
"Unlocked account 289d485d9771714cce91d3393d764e1311907acc",
194194
}
195195
for _, m := range wantMessages {
196-
if strings.Index(geth.stderrText(), m) == -1 {
196+
if !strings.Contains(geth.stderrText(), m) {
197197
t.Errorf("stderr text does not contain %q", m)
198198
}
199199
}
@@ -212,7 +212,7 @@ func TestUnlockFlagPasswordFile(t *testing.T) {
212212
"Unlocked account 289d485d9771714cce91d3393d764e1311907acc",
213213
}
214214
for _, m := range wantMessages {
215-
if strings.Index(geth.stderrText(), m) == -1 {
215+
if !strings.Contains(geth.stderrText(), m) {
216216
t.Errorf("stderr text does not contain %q", m)
217217
}
218218
}
@@ -260,7 +260,7 @@ In order to avoid this warning, you need to remove the following duplicate key f
260260
"Unlocked account f466859ead1932d743d622cb74fc058882e8648a",
261261
}
262262
for _, m := range wantMessages {
263-
if strings.Index(geth.stderrText(), m) == -1 {
263+
if !strings.Contains(geth.stderrText(), m) {
264264
t.Errorf("stderr text does not contain %q", m)
265265
}
266266
}

cmd/geth/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ func init() {
168168
}
169169

170170
app.After = func(ctx *cli.Context) error {
171-
logger.Flush()
172171
debug.Exit()
173172
console.Stdin.Close() // Resets terminal mode.
174173
return nil

cmd/swarm/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func init() {
129129
app.HideVersion = true // we have a command to print the version
130130
app.Copyright = "Copyright 2013-2016 The go-ethereum Authors"
131131
app.Commands = []cli.Command{
132-
cli.Command{
132+
{
133133
Action: version,
134134
Name: "version",
135135
Usage: "Print version numbers",
@@ -138,7 +138,7 @@ func init() {
138138
The output of this command is supposed to be machine-readable.
139139
`,
140140
},
141-
cli.Command{
141+
{
142142
Action: upload,
143143
Name: "up",
144144
Usage: "upload a file or directory to swarm using the HTTP API",
@@ -147,7 +147,7 @@ The output of this command is supposed to be machine-readable.
147147
"upload a file or directory to swarm using the HTTP API and prints the root hash",
148148
`,
149149
},
150-
cli.Command{
150+
{
151151
Action: hash,
152152
Name: "hash",
153153
Usage: "print the swarm hash of a file or directory",

cmd/utils/cmd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func Fatalf(format string, args ...interface{}) {
6767
}
6868
}
6969
fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
70-
logger.Flush()
7170
os.Exit(1)
7271
}
7372

@@ -95,7 +94,7 @@ func StartNode(stack *node.Node) {
9594

9695
func FormatTransactionData(data string) []byte {
9796
d := common.StringToByteFunc(data, func(s string) (ret []byte) {
98-
slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000)
97+
slice := regexp.MustCompile(`\n|\s`).Split(s, 1000000000)
9998
for _, dataItem := range slice {
10099
d := common.FormatData(dataItem)
101100
ret = append(ret, d...)

common/big_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestMisc(t *testing.T) {
2727
c := []byte{1, 2, 3, 4}
2828
z := BitTest(a, 1)
2929

30-
if z != true {
30+
if !z {
3131
t.Error("Expected true got", z)
3232
}
3333

@@ -79,11 +79,11 @@ func TestBigCopy(t *testing.T) {
7979
z := BigToBytes(c, 16)
8080
zbytes := []byte{232, 212, 165, 16, 0}
8181

82-
if bytes.Compare(y, ybytes) != 0 {
82+
if !bytes.Equal(y, ybytes) {
8383
t.Error("Got", ybytes)
8484
}
8585

86-
if bytes.Compare(z, zbytes) != 0 {
86+
if !bytes.Equal(z, zbytes) {
8787
t.Error("Got", zbytes)
8888
}
8989
}

0 commit comments

Comments
 (0)