Skip to content

Commit 3da1bf8

Browse files
zramsayfjl
authored andcommitted
all: use gometalinter.v2, fix new gosimple issues (ethereum#15650)
1 parent bbea4b2 commit 3da1bf8

File tree

24 files changed

+57
-67
lines changed

24 files changed

+57
-67
lines changed

accounts/abi/bind/bind.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func Bind(types []string, abis []string, bytecodes []string, pkg string, lang La
129129
return string(code), nil
130130
}
131131
// For all others just return as is for now
132-
return string(buffer.Bytes()), nil
132+
return buffer.String(), nil
133133
}
134134

135135
// bindType is a set of type binders that convert Solidity types to some supported

accounts/abi/unpack_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ func TestUnmarshal(t *testing.T) {
368368
if err != nil {
369369
t.Error(err)
370370
} else {
371-
if bytes.Compare(p0, p0Exp) != 0 {
371+
if !bytes.Equal(p0, p0Exp) {
372372
t.Errorf("unexpected value unpacked: want %x, got %x", p0Exp, p0)
373373
}
374374

375-
if bytes.Compare(p1[:], p1Exp) != 0 {
375+
if !bytes.Equal(p1[:], p1Exp) {
376376
t.Errorf("unexpected value unpacked: want %x, got %x", p1Exp, p1)
377377
}
378378
}

bmt/bmt.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ func NewTree(hasher BaseHasher, segmentSize, segmentCount int) *Tree {
260260
for d := 1; d <= depth(segmentCount); d++ {
261261
nodes := make([]*Node, count)
262262
for i := 0; i < len(nodes); i++ {
263-
var parent *Node
264-
parent = prevlevel[i/2]
263+
parent := prevlevel[i/2]
265264
t := NewNode(level, i, parent)
266265
nodes[i] = t
267266
}

build/ci.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ func doLint(cmdline []string) {
319319
packages = flag.CommandLine.Args()
320320
}
321321
// Get metalinter and install all supported linters
322-
build.MustRun(goTool("get", "gopkg.in/alecthomas/gometalinter.v1"))
323-
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v1"), "--install")
322+
build.MustRun(goTool("get", "gopkg.in/alecthomas/gometalinter.v2"))
323+
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), "--install")
324324

325325
// Run fast linters batched together
326326
configs := []string{
@@ -332,12 +332,12 @@ func doLint(cmdline []string) {
332332
"--enable=goconst",
333333
"--min-occurrences=6", // for goconst
334334
}
335-
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v1"), append(configs, packages...)...)
335+
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), append(configs, packages...)...)
336336

337337
// Run slow linters one by one
338338
for _, linter := range []string{"unconvert", "gosimple"} {
339339
configs = []string{"--vendor", "--deadline=10m", "--disable-all", "--enable=" + linter}
340-
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v1"), append(configs, packages...)...)
340+
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), append(configs, packages...)...)
341341
}
342342
}
343343

cmd/faucet/faucet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
506506

507507
// Send an error if too frequent funding, othewise a success
508508
if !fund {
509-
if err = sendError(conn, fmt.Errorf("%s left until next allowance", common.PrettyDuration(timeout.Sub(time.Now())))); err != nil {
509+
if err = sendError(conn, fmt.Errorf("%s left until next allowance", common.PrettyDuration(timeout.Sub(time.Now())))); err != nil { // nolint: gosimple
510510
log.Warn("Failed to send funding error to client", "err", err)
511511
return
512512
}

cmd/puppeth/module_dashboard.go

+1
Large diffs are not rendered by default.

cmd/swarm/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
267267
}
268268

269269
//EnsApi can be set to "", so can't check for empty string, as it is allowed
270-
if ensapi, exists := os.LookupEnv(SWARM_ENV_ENS_API); exists == true {
270+
if ensapi, exists := os.LookupEnv(SWARM_ENV_ENS_API); exists {
271271
currentConfig.EnsApi = ensapi
272272
}
273273

cmd/swarm/config_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestCmdLineOverrides(t *testing.T) {
124124
t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkId)
125125
}
126126

127-
if info.SyncEnabled != true {
127+
if !info.SyncEnabled {
128128
t.Fatal("Expected Sync to be enabled, but is false")
129129
}
130130

@@ -219,7 +219,7 @@ func TestFileOverrides(t *testing.T) {
219219
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId)
220220
}
221221

222-
if info.SyncEnabled != true {
222+
if !info.SyncEnabled {
223223
t.Fatal("Expected Sync to be enabled, but is false")
224224
}
225225

@@ -334,7 +334,7 @@ func TestEnvVars(t *testing.T) {
334334
t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors)
335335
}
336336

337-
if info.SyncEnabled != true {
337+
if !info.SyncEnabled {
338338
t.Fatal("Expected Sync to be enabled, but is false")
339339
}
340340

@@ -431,7 +431,7 @@ func TestCmdLineOverridesFile(t *testing.T) {
431431
t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkId)
432432
}
433433

434-
if info.SyncEnabled != true {
434+
if !info.SyncEnabled {
435435
t.Fatal("Expected Sync to be enabled, but is false")
436436
}
437437

consensus/clique/clique.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, stop <-ch
630630
}
631631
}
632632
// Sweet, the protocol permits us to sign the block, wait for our time
633-
delay := time.Unix(header.Time.Int64(), 0).Sub(time.Now())
633+
delay := time.Unix(header.Time.Int64(), 0).Sub(time.Now()) // nolint: gosimple
634634
if header.Difficulty.Cmp(diffNoTurn) == 0 {
635635
// It's not our turn explicitly to sign, delay it a bit
636636
wiggle := time.Duration(len(snap.Signers)/2+1) * wiggleTime

console/console_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestWelcome(t *testing.T) {
164164

165165
tester.console.Welcome()
166166

167-
output := string(tester.output.Bytes())
167+
output := tester.output.String()
168168
if want := "Welcome"; !strings.Contains(output, want) {
169169
t.Fatalf("console output missing welcome message: have\n%s\nwant also %s", output, want)
170170
}
@@ -188,7 +188,7 @@ func TestEvaluate(t *testing.T) {
188188
defer tester.Close(t)
189189

190190
tester.console.Evaluate("2 + 2")
191-
if output := string(tester.output.Bytes()); !strings.Contains(output, "4") {
191+
if output := tester.output.String(); !strings.Contains(output, "4") {
192192
t.Fatalf("statement evaluation failed: have %s, want %s", output, "4")
193193
}
194194
}
@@ -218,7 +218,7 @@ func TestInteractive(t *testing.T) {
218218
case <-time.After(time.Second):
219219
t.Fatalf("secondary prompt timeout")
220220
}
221-
if output := string(tester.output.Bytes()); !strings.Contains(output, "4") {
221+
if output := tester.output.String(); !strings.Contains(output, "4") {
222222
t.Fatalf("statement evaluation failed: have %s, want %s", output, "4")
223223
}
224224
}
@@ -230,7 +230,7 @@ func TestPreload(t *testing.T) {
230230
defer tester.Close(t)
231231

232232
tester.console.Evaluate("preloaded")
233-
if output := string(tester.output.Bytes()); !strings.Contains(output, "some-preloaded-string") {
233+
if output := tester.output.String(); !strings.Contains(output, "some-preloaded-string") {
234234
t.Fatalf("preloaded variable missing: have %s, want %s", output, "some-preloaded-string")
235235
}
236236
}
@@ -243,7 +243,7 @@ func TestExecute(t *testing.T) {
243243
tester.console.Execute("exec.js")
244244

245245
tester.console.Evaluate("execed")
246-
if output := string(tester.output.Bytes()); !strings.Contains(output, "some-executed-string") {
246+
if output := tester.output.String(); !strings.Contains(output, "some-executed-string") {
247247
t.Fatalf("execed variable missing: have %s, want %s", output, "some-executed-string")
248248
}
249249
}
@@ -275,7 +275,7 @@ func TestPrettyPrint(t *testing.T) {
275275
string: ` + two + `
276276
}
277277
`
278-
if output := string(tester.output.Bytes()); output != want {
278+
if output := tester.output.String(); output != want {
279279
t.Fatalf("pretty print mismatch: have %s, want %s", output, want)
280280
}
281281
}
@@ -287,7 +287,7 @@ func TestPrettyError(t *testing.T) {
287287
tester.console.Evaluate("throw 'hello'")
288288

289289
want := jsre.ErrorColor("hello") + "\n"
290-
if output := string(tester.output.Bytes()); output != want {
290+
if output := tester.output.String(); output != want {
291291
t.Fatalf("pretty error mismatch: have %s, want %s", output, want)
292292
}
293293
}

core/asm/asm.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ func PrintDisassembled(code string) error {
114114
fmt.Printf("%06v: %v\n", it.PC(), it.Op())
115115
}
116116
}
117-
if err := it.Error(); err != nil {
118-
return err
119-
}
120-
return nil
117+
return it.Error()
121118
}
122119

123120
// Return all disassembled EVM instructions in human-readable format.

core/asm/compiler.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,7 @@ func (c *Compiler) pushBin(v interface{}) {
237237
// isPush returns whether the string op is either any of
238238
// push(N).
239239
func isPush(op string) bool {
240-
if op == "push" {
241-
return true
242-
}
243-
return false
240+
return op == "push"
244241
}
245242

246243
// isJump returns whether the string op is jump(i)

core/genesis_alloc.go

+1
Large diffs are not rendered by default.

ethstats/ethstats.go

-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ func (s *Service) loop() {
193193
}
194194
}
195195
close(quitCh)
196-
return
197196
}()
198197
// Loop reporting until termination
199198
for {

p2p/discv5/net.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ func (net *Network) refresh(done chan<- struct{}) {
684684
seeds = net.nursery
685685
}
686686
if len(seeds) == 0 {
687-
log.Trace(fmt.Sprint("no seed nodes found"))
687+
log.Trace("no seed nodes found")
688688
close(done)
689689
return
690690
}

p2p/discv5/ntp.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ func checkClockDrift() {
5454
howtofix := fmt.Sprintf("Please enable network time synchronisation in system settings")
5555
separator := strings.Repeat("-", len(warning))
5656

57-
log.Warn(fmt.Sprint(separator))
58-
log.Warn(fmt.Sprint(warning))
59-
log.Warn(fmt.Sprint(howtofix))
60-
log.Warn(fmt.Sprint(separator))
57+
log.Warn(separator)
58+
log.Warn(warning)
59+
log.Warn(howtofix)
60+
log.Warn(separator)
6161
} else {
6262
log.Debug(fmt.Sprintf("Sanity NTP check reported %v drift, all ok", drift))
6363
}

p2p/discv5/ticket.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,12 @@ func (s *ticketStore) nextRegisterableTicket() (t *ticketRef, wait time.Duration
398398
//s.removeExcessTickets(topic)
399399
if len(tickets.buckets) != 0 {
400400
empty = false
401-
if list := tickets.buckets[bucket]; list != nil {
402-
for _, ref := range list {
403-
//debugLog(fmt.Sprintf(" nrt bucket = %d node = %x sn = %v wait = %v", bucket, ref.t.node.ID[:8], ref.t.serial, time.Duration(ref.topicRegTime()-now)))
404-
if nextTicket.t == nil || ref.topicRegTime() < nextTicket.topicRegTime() {
405-
nextTicket = ref
406-
}
401+
402+
list := tickets.buckets[bucket]
403+
for _, ref := range list {
404+
//debugLog(fmt.Sprintf(" nrt bucket = %d node = %x sn = %v wait = %v", bucket, ref.t.node.ID[:8], ref.t.serial, time.Duration(ref.topicRegTime()-now)))
405+
if nextTicket.t == nil || ref.topicRegTime() < nextTicket.topicRegTime() {
406+
nextTicket = ref
407407
}
408408
}
409409
}

p2p/simulations/network.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,8 @@ func (self *Network) getNodeByName(name string) *Node {
403403
func (self *Network) GetNodes() (nodes []*Node) {
404404
self.lock.Lock()
405405
defer self.lock.Unlock()
406-
for _, node := range self.Nodes {
407-
nodes = append(nodes, node)
408-
}
406+
407+
nodes = append(nodes, self.Nodes...)
409408
return nodes
410409
}
411410

@@ -477,7 +476,7 @@ func (self *Network) InitConn(oneID, otherID discover.NodeID) (*Conn, error) {
477476
if err != nil {
478477
return nil, err
479478
}
480-
if time.Now().Sub(conn.initiated) < dialBanTimeout {
479+
if time.Since(conn.initiated) < dialBanTimeout {
481480
return nil, fmt.Errorf("connection between %v and %v recently attempted", oneID, otherID)
482481
}
483482
if conn.Up {

rpc/http_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestHTTPErrorResponseWithPut(t *testing.T) {
3232
}
3333

3434
func TestHTTPErrorResponseWithMaxContentLength(t *testing.T) {
35-
body := make([]rune, maxHTTPRequestContentLength+1, maxHTTPRequestContentLength+1)
35+
body := make([]rune, maxHTTPRequestContentLength+1)
3636
testHTTPErrorResponse(t,
3737
"POST", contentType, string(body), http.StatusRequestEntityTooLarge)
3838
}

swarm/api/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestConfig(t *testing.T) {
3636
one := NewDefaultConfig()
3737
two := NewDefaultConfig()
3838

39-
if equal := reflect.DeepEqual(one, two); equal == false {
39+
if equal := reflect.DeepEqual(one, two); !equal {
4040
t.Fatal("Two default configs are not equal")
4141
}
4242

swarm/fuse/swarmfs_test.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func mountDir(t *testing.T, api *api.Api, files map[string]fileInfo, bzzHash str
9595
}
9696

9797
// Test listMounts
98-
if found == false {
98+
if !found {
9999
t.Fatalf("Error getting mounts information for %v: %v", mountDir, err)
100100
}
101101

@@ -185,10 +185,8 @@ func isDirEmpty(name string) bool {
185185
defer f.Close()
186186

187187
_, err = f.Readdirnames(1)
188-
if err == io.EOF {
189-
return true
190-
}
191-
return false
188+
189+
return err == io.EOF
192190
}
193191

194192
type testAPI struct {
@@ -388,7 +386,7 @@ func (ta *testAPI) seekInMultiChunkFile(t *testing.T) {
388386
d.Read(contents)
389387
finfo := files["1.txt"]
390388

391-
if bytes.Compare(finfo.contents[:6024][5000:], contents) != 0 {
389+
if !bytes.Equal(finfo.contents[:6024][5000:], contents) {
392390
t.Fatalf("File seek contents mismatch")
393391
}
394392
d.Close()

swarm/storage/chunker_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (self *chunkerTester) Split(chunker Splitter, data io.Reader, size int64, c
7777

7878
key, err = chunker.Split(data, size, chunkC, swg, nil)
7979
if err != nil && expectedError == nil {
80-
err = errors.New(fmt.Sprintf("Split error: %v", err))
80+
err = fmt.Errorf("Split error: %v", err)
8181
}
8282

8383
if chunkC != nil {
@@ -123,7 +123,7 @@ func (self *chunkerTester) Append(chunker Splitter, rootKey Key, data io.Reader,
123123

124124
key, err = chunker.Append(rootKey, data, chunkC, swg, nil)
125125
if err != nil && expectedError == nil {
126-
err = errors.New(fmt.Sprintf("Append error: %v", err))
126+
err = fmt.Errorf("Append error: %v", err)
127127
}
128128

129129
if chunkC != nil {

0 commit comments

Comments
 (0)