Skip to content

Commit

Permalink
all: use gometalinter.v2, fix new gosimple issues (#15650)
Browse files Browse the repository at this point in the history
  • Loading branch information
zramsay authored and fjl committed Dec 12, 2017
1 parent bbea4b2 commit 3da1bf8
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 67 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func Bind(types []string, abis []string, bytecodes []string, pkg string, lang La
return string(code), nil
}
// For all others just return as is for now
return string(buffer.Bytes()), nil
return buffer.String(), nil
}

// bindType is a set of type binders that convert Solidity types to some supported
Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ func TestUnmarshal(t *testing.T) {
if err != nil {
t.Error(err)
} else {
if bytes.Compare(p0, p0Exp) != 0 {
if !bytes.Equal(p0, p0Exp) {
t.Errorf("unexpected value unpacked: want %x, got %x", p0Exp, p0)
}

if bytes.Compare(p1[:], p1Exp) != 0 {
if !bytes.Equal(p1[:], p1Exp) {
t.Errorf("unexpected value unpacked: want %x, got %x", p1Exp, p1)
}
}
Expand Down
3 changes: 1 addition & 2 deletions bmt/bmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ func NewTree(hasher BaseHasher, segmentSize, segmentCount int) *Tree {
for d := 1; d <= depth(segmentCount); d++ {
nodes := make([]*Node, count)
for i := 0; i < len(nodes); i++ {
var parent *Node
parent = prevlevel[i/2]
parent := prevlevel[i/2]
t := NewNode(level, i, parent)
nodes[i] = t
}
Expand Down
8 changes: 4 additions & 4 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ func doLint(cmdline []string) {
packages = flag.CommandLine.Args()
}
// Get metalinter and install all supported linters
build.MustRun(goTool("get", "gopkg.in/alecthomas/gometalinter.v1"))
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v1"), "--install")
build.MustRun(goTool("get", "gopkg.in/alecthomas/gometalinter.v2"))
build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v2"), "--install")

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

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

Expand Down
2 changes: 1 addition & 1 deletion cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {

// Send an error if too frequent funding, othewise a success
if !fund {
if err = sendError(conn, fmt.Errorf("%s left until next allowance", common.PrettyDuration(timeout.Sub(time.Now())))); err != nil {
if err = sendError(conn, fmt.Errorf("%s left until next allowance", common.PrettyDuration(timeout.Sub(time.Now())))); err != nil { // nolint: gosimple
log.Warn("Failed to send funding error to client", "err", err)
return
}
Expand Down
1 change: 1 addition & 0 deletions cmd/puppeth/module_dashboard.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/swarm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
}

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

Expand Down
8 changes: 4 additions & 4 deletions cmd/swarm/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestCmdLineOverrides(t *testing.T) {
t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkId)
}

if info.SyncEnabled != true {
if !info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false")
}

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

if info.SyncEnabled != true {
if !info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false")
}

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

if info.SyncEnabled != true {
if !info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false")
}

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

if info.SyncEnabled != true {
if !info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false")
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, stop <-ch
}
}
// Sweet, the protocol permits us to sign the block, wait for our time
delay := time.Unix(header.Time.Int64(), 0).Sub(time.Now())
delay := time.Unix(header.Time.Int64(), 0).Sub(time.Now()) // nolint: gosimple
if header.Difficulty.Cmp(diffNoTurn) == 0 {
// It's not our turn explicitly to sign, delay it a bit
wiggle := time.Duration(len(snap.Signers)/2+1) * wiggleTime
Expand Down
14 changes: 7 additions & 7 deletions console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestWelcome(t *testing.T) {

tester.console.Welcome()

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

tester.console.Evaluate("2 + 2")
if output := string(tester.output.Bytes()); !strings.Contains(output, "4") {
if output := tester.output.String(); !strings.Contains(output, "4") {
t.Fatalf("statement evaluation failed: have %s, want %s", output, "4")
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestInteractive(t *testing.T) {
case <-time.After(time.Second):
t.Fatalf("secondary prompt timeout")
}
if output := string(tester.output.Bytes()); !strings.Contains(output, "4") {
if output := tester.output.String(); !strings.Contains(output, "4") {
t.Fatalf("statement evaluation failed: have %s, want %s", output, "4")
}
}
Expand All @@ -230,7 +230,7 @@ func TestPreload(t *testing.T) {
defer tester.Close(t)

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

tester.console.Evaluate("execed")
if output := string(tester.output.Bytes()); !strings.Contains(output, "some-executed-string") {
if output := tester.output.String(); !strings.Contains(output, "some-executed-string") {
t.Fatalf("execed variable missing: have %s, want %s", output, "some-executed-string")
}
}
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestPrettyPrint(t *testing.T) {
string: ` + two + `
}
`
if output := string(tester.output.Bytes()); output != want {
if output := tester.output.String(); output != want {
t.Fatalf("pretty print mismatch: have %s, want %s", output, want)
}
}
Expand All @@ -287,7 +287,7 @@ func TestPrettyError(t *testing.T) {
tester.console.Evaluate("throw 'hello'")

want := jsre.ErrorColor("hello") + "\n"
if output := string(tester.output.Bytes()); output != want {
if output := tester.output.String(); output != want {
t.Fatalf("pretty error mismatch: have %s, want %s", output, want)
}
}
Expand Down
5 changes: 1 addition & 4 deletions core/asm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ func PrintDisassembled(code string) error {
fmt.Printf("%06v: %v\n", it.PC(), it.Op())
}
}
if err := it.Error(); err != nil {
return err
}
return nil
return it.Error()
}

// Return all disassembled EVM instructions in human-readable format.
Expand Down
5 changes: 1 addition & 4 deletions core/asm/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,7 @@ func (c *Compiler) pushBin(v interface{}) {
// isPush returns whether the string op is either any of
// push(N).
func isPush(op string) bool {
if op == "push" {
return true
}
return false
return op == "push"
}

// isJump returns whether the string op is jump(i)
Expand Down
1 change: 1 addition & 0 deletions core/genesis_alloc.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ethstats/ethstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func (s *Service) loop() {
}
}
close(quitCh)
return
}()
// Loop reporting until termination
for {
Expand Down
2 changes: 1 addition & 1 deletion p2p/discv5/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ func (net *Network) refresh(done chan<- struct{}) {
seeds = net.nursery
}
if len(seeds) == 0 {
log.Trace(fmt.Sprint("no seed nodes found"))
log.Trace("no seed nodes found")
close(done)
return
}
Expand Down
8 changes: 4 additions & 4 deletions p2p/discv5/ntp.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func checkClockDrift() {
howtofix := fmt.Sprintf("Please enable network time synchronisation in system settings")
separator := strings.Repeat("-", len(warning))

log.Warn(fmt.Sprint(separator))
log.Warn(fmt.Sprint(warning))
log.Warn(fmt.Sprint(howtofix))
log.Warn(fmt.Sprint(separator))
log.Warn(separator)
log.Warn(warning)
log.Warn(howtofix)
log.Warn(separator)
} else {
log.Debug(fmt.Sprintf("Sanity NTP check reported %v drift, all ok", drift))
}
Expand Down
12 changes: 6 additions & 6 deletions p2p/discv5/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,12 @@ func (s *ticketStore) nextRegisterableTicket() (t *ticketRef, wait time.Duration
//s.removeExcessTickets(topic)
if len(tickets.buckets) != 0 {
empty = false
if list := tickets.buckets[bucket]; list != nil {
for _, ref := range list {
//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)))
if nextTicket.t == nil || ref.topicRegTime() < nextTicket.topicRegTime() {
nextTicket = ref
}

list := tickets.buckets[bucket]
for _, ref := range list {
//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)))
if nextTicket.t == nil || ref.topicRegTime() < nextTicket.topicRegTime() {
nextTicket = ref
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions p2p/simulations/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,8 @@ func (self *Network) getNodeByName(name string) *Node {
func (self *Network) GetNodes() (nodes []*Node) {
self.lock.Lock()
defer self.lock.Unlock()
for _, node := range self.Nodes {
nodes = append(nodes, node)
}

nodes = append(nodes, self.Nodes...)
return nodes
}

Expand Down Expand Up @@ -477,7 +476,7 @@ func (self *Network) InitConn(oneID, otherID discover.NodeID) (*Conn, error) {
if err != nil {
return nil, err
}
if time.Now().Sub(conn.initiated) < dialBanTimeout {
if time.Since(conn.initiated) < dialBanTimeout {
return nil, fmt.Errorf("connection between %v and %v recently attempted", oneID, otherID)
}
if conn.Up {
Expand Down
2 changes: 1 addition & 1 deletion rpc/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestHTTPErrorResponseWithPut(t *testing.T) {
}

func TestHTTPErrorResponseWithMaxContentLength(t *testing.T) {
body := make([]rune, maxHTTPRequestContentLength+1, maxHTTPRequestContentLength+1)
body := make([]rune, maxHTTPRequestContentLength+1)
testHTTPErrorResponse(t,
"POST", contentType, string(body), http.StatusRequestEntityTooLarge)
}
Expand Down
2 changes: 1 addition & 1 deletion swarm/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestConfig(t *testing.T) {
one := NewDefaultConfig()
two := NewDefaultConfig()

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

Expand Down
10 changes: 4 additions & 6 deletions swarm/fuse/swarmfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func mountDir(t *testing.T, api *api.Api, files map[string]fileInfo, bzzHash str
}

// Test listMounts
if found == false {
if !found {
t.Fatalf("Error getting mounts information for %v: %v", mountDir, err)
}

Expand Down Expand Up @@ -185,10 +185,8 @@ func isDirEmpty(name string) bool {
defer f.Close()

_, err = f.Readdirnames(1)
if err == io.EOF {
return true
}
return false

return err == io.EOF
}

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

if bytes.Compare(finfo.contents[:6024][5000:], contents) != 0 {
if !bytes.Equal(finfo.contents[:6024][5000:], contents) {
t.Fatalf("File seek contents mismatch")
}
d.Close()
Expand Down
4 changes: 2 additions & 2 deletions swarm/storage/chunker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (self *chunkerTester) Split(chunker Splitter, data io.Reader, size int64, c

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

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

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

if chunkC != nil {
Expand Down
Loading

0 comments on commit 3da1bf8

Please sign in to comment.