all: simplify nested complexity and if blocks ending with a return statement (#21854)

Changes:

    Simplify nested complexity
    If an if blocks ends with a return statement then remove the else nesting.

Most of the changes has also been reported in golint https://goreportcard.com/report/github.com/ethereum/go-ethereum#golint
This commit is contained in:
Alex Prut
2020-11-25 09:24:50 +01:00
committed by GitHub
parent 29efe1fc7e
commit c92faee66e
19 changed files with 58 additions and 85 deletions

View File

@ -219,9 +219,8 @@ func (n *autodisc) String() string {
defer n.mu.Unlock()
if n.found == nil {
return n.what
} else {
return n.found.String()
}
return n.found.String()
}
// wait blocks until auto-discovery has been performed.

View File

@ -240,9 +240,8 @@ func uint64FieldEnc(field interface{}) ([]byte, error) {
if u, ok := field.(uint64); ok {
enc, err := rlp.EncodeToBytes(&u)
return enc, err
} else {
return nil, errors.New("invalid field type")
}
return nil, errors.New("invalid field type")
}
func uint64FieldDec(enc []byte) (interface{}, error) {
@ -254,9 +253,8 @@ func uint64FieldDec(enc []byte) (interface{}, error) {
func stringFieldEnc(field interface{}) ([]byte, error) {
if s, ok := field.(string); ok {
return []byte(s), nil
} else {
return nil, errors.New("invalid field type")
}
return nil, errors.New("invalid field type")
}
func stringFieldDec(enc []byte) (interface{}, error) {

View File

@ -454,9 +454,8 @@ func (net *Network) getNodeIDs(excludeIDs []enode.ID) []enode.ID {
if len(excludeIDs) > 0 {
// Return the difference of nodeIDs and excludeIDs
return filterIDs(nodeIDs, excludeIDs)
} else {
return nodeIDs
}
return nodeIDs
}
// GetNodes returns the existing nodes.
@ -472,9 +471,8 @@ func (net *Network) getNodes(excludeIDs []enode.ID) []*Node {
if len(excludeIDs) > 0 {
nodeIDs := net.getNodeIDs(excludeIDs)
return net.getNodesByID(nodeIDs)
} else {
return net.Nodes
}
return net.Nodes
}
// GetNodesByID returns existing nodes with the given enode.IDs.
@ -1098,7 +1096,6 @@ func (net *Network) executeNodeEvent(e *Event) error {
func (net *Network) executeConnEvent(e *Event) error {
if e.Conn.Up {
return net.Connect(e.Conn.One, e.Conn.Other)
} else {
return net.Disconnect(e.Conn.One, e.Conn.Other)
}
return net.Disconnect(e.Conn.One, e.Conn.Other)
}