mirror of https://github.com/status-im/op-geth.git
all: use gometalinter.v2, fix new gosimple issues (#15650)
This commit is contained in:
parent
bbea4b2b53
commit
3da1bf8ca1
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
@ -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...)...)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -193,7 +193,6 @@ func (s *Service) loop() {
|
|||
}
|
||||
}
|
||||
close(quitCh)
|
||||
return
|
||||
}()
|
||||
// Loop reporting until termination
|
||||
for {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -391,7 +391,7 @@ func (self *PyramidChunker) prepareChunks(isAppend bool, chunkLevel [][]*TreeEnt
|
|||
parent := NewTreeEntry(self)
|
||||
var unFinishedChunk *Chunk
|
||||
|
||||
if isAppend == true && len(chunkLevel[0]) != 0 {
|
||||
if isAppend && len(chunkLevel[0]) != 0 {
|
||||
|
||||
lastIndex := len(chunkLevel[0]) - 1
|
||||
ent := chunkLevel[0][lastIndex]
|
||||
|
@ -512,7 +512,7 @@ func (self *PyramidChunker) buildTree(isAppend bool, chunkLevel [][]*TreeEntry,
|
|||
}
|
||||
}
|
||||
|
||||
if compress == false && last == false {
|
||||
if !compress && !last {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -522,7 +522,7 @@ func (self *PyramidChunker) buildTree(isAppend bool, chunkLevel [][]*TreeEntry,
|
|||
for lvl := int64(ent.level); lvl < endLvl; lvl++ {
|
||||
|
||||
lvlCount := int64(len(chunkLevel[lvl]))
|
||||
if lvlCount == 1 && last == true {
|
||||
if lvlCount == 1 && last {
|
||||
copy(rootKey, chunkLevel[lvl][0].key)
|
||||
return
|
||||
}
|
||||
|
@ -540,7 +540,7 @@ func (self *PyramidChunker) buildTree(isAppend bool, chunkLevel [][]*TreeEntry,
|
|||
nextLvlCount = int64(len(chunkLevel[lvl+1]) - 1)
|
||||
tempEntry = chunkLevel[lvl+1][nextLvlCount]
|
||||
}
|
||||
if isAppend == true && tempEntry != nil && tempEntry.updatePending == true {
|
||||
if isAppend && tempEntry != nil && tempEntry.updatePending {
|
||||
updateEntry := &TreeEntry{
|
||||
level: int(lvl + 1),
|
||||
branchCount: 0,
|
||||
|
@ -585,9 +585,9 @@ func (self *PyramidChunker) buildTree(isAppend bool, chunkLevel [][]*TreeEntry,
|
|||
|
||||
}
|
||||
|
||||
if isAppend == false {
|
||||
if !isAppend {
|
||||
chunkWG.Wait()
|
||||
if compress == true {
|
||||
if compress {
|
||||
chunkLevel[lvl] = nil
|
||||
}
|
||||
}
|
||||
|
@ -599,7 +599,7 @@ func (self *PyramidChunker) enqueueTreeChunk(chunkLevel [][]*TreeEntry, ent *Tre
|
|||
if ent != nil {
|
||||
|
||||
// wait for data chunks to get over before processing the tree chunk
|
||||
if last == true {
|
||||
if last {
|
||||
chunkWG.Wait()
|
||||
}
|
||||
|
||||
|
@ -612,7 +612,7 @@ func (self *PyramidChunker) enqueueTreeChunk(chunkLevel [][]*TreeEntry, ent *Tre
|
|||
}
|
||||
|
||||
// Update or append based on weather it is a new entry or being reused
|
||||
if ent.updatePending == true {
|
||||
if ent.updatePending {
|
||||
chunkWG.Wait()
|
||||
chunkLevel[ent.level][ent.index] = ent
|
||||
} else {
|
||||
|
|
|
@ -80,8 +80,7 @@ func TestWhisperBasic(t *testing.T) {
|
|||
t.Fatalf("failed w.Messages.")
|
||||
}
|
||||
|
||||
var derived []byte
|
||||
derived = pbkdf2.Key([]byte(peerID), nil, 65356, aesKeyLength, sha256.New)
|
||||
derived := pbkdf2.Key([]byte(peerID), nil, 65356, aesKeyLength, sha256.New)
|
||||
if !validateSymmetricKey(derived) {
|
||||
t.Fatalf("failed validateSymmetricKey with param = %v.", derived)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue