Skip to content

Commit

Permalink
Integrate staticcheck in CI
Browse files Browse the repository at this point in the history
Fix most violations, allow some
  • Loading branch information
fbiville authored Oct 12, 2022
1 parent cb7db9e commit 332277b
Show file tree
Hide file tree
Showing 46 changed files with 810 additions and 851 deletions.
1 change: 1 addition & 0 deletions neo4j/driver_with_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func NewDriverWithContext(target string, auth AuthToken, configurers ...func(*Co
d.connector.DialTimeout = d.config.SocketConnectTimeout
d.connector.SocketKeepAlive = d.config.SocketKeepalive
d.connector.UserAgent = d.config.UserAgent
//lint:ignore SA1019 RootCAs is still supported until 6.0
d.connector.RootCAs = d.config.RootCAs
d.connector.TlsConfig = d.config.TlsConfig
d.connector.Log = d.log
Expand Down
22 changes: 11 additions & 11 deletions neo4j/internal/bolt/bolt3.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (b *bolt3) receiveSuccess(ctx context.Context) *success {
}
// Unexpected message received
b.state = bolt3_dead
b.err = errors.New("Expected success or database error")
b.err = errors.New("expected success or database error")
b.log.Error(log.Bolt3, b.logId, b.err)
return nil
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func (b *bolt3) assertState(allowed ...int) error {
return nil
}
}
err := errors.New(fmt.Sprintf("Invalid state %d, expected: %+v", b.state, allowed))
err := fmt.Errorf("invalid state %d, expected: %+v", b.state, allowed)
b.log.Error(log.Bolt3, b.logId, err)
return err
}
Expand Down Expand Up @@ -478,7 +478,7 @@ func (b *bolt3) RunTx(ctx context.Context, txh idb.TxHandle, runCommand idb.Comm
func (b *bolt3) Keys(streamHandle idb.StreamHandle) ([]string, error) {
stream, ok := streamHandle.(*stream)
if !ok {
return nil, errors.New("Invalid stream handle")
return nil, errors.New("invalid stream handle")
}
// Don't care about if the stream is the current or even if it belongs to this connection.
return stream.keys, nil
Expand All @@ -489,7 +489,7 @@ func (b *bolt3) Next(ctx context.Context, streamHandle idb.StreamHandle) (
*db.Record, *db.Summary, error) {
stream, ok := streamHandle.(*stream)
if !ok {
return nil, nil, errors.New("Invalid stream handle")
return nil, nil, errors.New("invalid stream handle")
}

// Buffered stream or someone elses stream, doesn't matter...
Expand All @@ -501,7 +501,7 @@ func (b *bolt3) Next(ctx context.Context, streamHandle idb.StreamHandle) (
// Nothing in the stream buffer, the stream must be the current
// one to fetch on it otherwise something is wrong.
if stream != b.currStream {
return nil, nil, errors.New("Invalid stream handle")
return nil, nil, errors.New("invalid stream handle")
}

return b.receiveNext(ctx)
Expand All @@ -511,7 +511,7 @@ func (b *bolt3) Consume(ctx context.Context, streamHandle idb.StreamHandle) (
*db.Summary, error) {
stream, ok := streamHandle.(*stream)
if !ok {
return nil, errors.New("Invalid stream handle")
return nil, errors.New("invalid stream handle")
}

// If the stream isn't current, it should either already be complete
Expand All @@ -533,7 +533,7 @@ func (b *bolt3) Buffer(ctx context.Context,
streamHandle idb.StreamHandle) error {
stream, ok := streamHandle.(*stream)
if !ok {
return errors.New("Invalid stream handle")
return errors.New("invalid stream handle")
}

// If the stream isn't current, it should either already be complete
Expand Down Expand Up @@ -571,7 +571,7 @@ func (b *bolt3) receiveNext(ctx context.Context) (*db.Record, *db.Summary, error
sum := x.summary()
if sum == nil {
b.state = bolt3_dead
b.err = errors.New("Failed to parse summary")
b.err = errors.New("failed to parse summary")
b.currStream.err = b.err
b.currStream = nil
b.log.Error(log.Bolt3, b.logId, b.err)
Expand Down Expand Up @@ -609,7 +609,7 @@ func (b *bolt3) receiveNext(ctx context.Context) (*db.Record, *db.Summary, error
return nil, nil, x
default:
b.state = bolt3_dead
b.err = errors.New("Unknown response")
b.err = errors.New("unknown response")
b.currStream.err = b.err
b.currStream = nil
b.log.Error(log.Bolt3, b.logId, b.err)
Expand Down Expand Up @@ -737,14 +737,14 @@ func (b *bolt3) GetRoutingTable(ctx context.Context,
return nil, err
}
if rec == nil {
return nil, errors.New("No routing table record")
return nil, errors.New("no routing table record")
}
// Just empty the stream, ignore the summary should leave the connecion in ready state
b.Next(ctx, streamHandle)

table := parseRoutingTableRecord(rec)
if table == nil {
return nil, errors.New("Unable to parse routing table")
return nil, errors.New("unable to parse routing table")
}
// Just because
table.DatabaseName = idb.DefaultDatabase
Expand Down
9 changes: 1 addition & 8 deletions neo4j/internal/bolt/bolt3server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@ func (s *bolt3server) acceptVersion(ver byte) {
}
}

func (s *bolt3server) rejectVersions() {
_, err := s.conn.Write([]byte{0x00, 0x00, 0x00, 0x00})
if err != nil {
panic(err)
}
}

func (s *bolt3server) closeConnection() {
s.conn.Close()
}
Expand Down Expand Up @@ -227,7 +220,7 @@ func setupBolt3Pipe(t *testing.T) (net.Conn, *bolt3server, func()) {
}

addr := l.Addr()
clientConn, err := net.Dial(addr.Network(), addr.String())
clientConn, _ := net.Dial(addr.Network(), addr.String())

srvConn, err := l.Accept()
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions neo4j/internal/bolt/bolt4.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (b *bolt4) receiveSuccess(ctx context.Context) *success {
return nil
default:
// Unexpected message received
b.setError(errors.New("Expected success or database error"), true)
b.setError(errors.New("expected success or database error"), true)
return nil
}
}
Expand Down Expand Up @@ -356,7 +356,7 @@ func (b *bolt4) assertState(allowed ...int) error {
return nil
}
}
err := errors.New(fmt.Sprintf("Invalid state %d, expected: %+v", b.state, allowed))
err := fmt.Errorf("invalid state %d, expected: %+v", b.state, allowed)
b.log.Error(log.Bolt4, b.logId, err)
return err
}
Expand Down Expand Up @@ -818,7 +818,7 @@ func (b *bolt4) receiveNext(ctx context.Context) (*db.Record, bool, *db.Summary)
return nil, false, nil
default:
// Unknown territory
b.setError(errors.New("Unknown response"), true)
b.setError(errors.New("unknown response"), true)
return nil, false, nil
}
}
Expand Down Expand Up @@ -968,14 +968,14 @@ func (b *bolt4) callGetRoutingTable(ctx context.Context,
return nil, err
}
if rec == nil {
return nil, errors.New("No routing table record")
return nil, errors.New("no routing table record")
}
// Just empty the stream, ignore the summary should leave the connection in ready state
b.Next(ctx, streamHandle)

table := parseRoutingTableRecord(rec)
if table == nil {
return nil, errors.New("Unable to parse routing table")
return nil, errors.New("unable to parse routing table")
}
// On this version we will not receive the database name
table.DatabaseName = database
Expand Down
30 changes: 1 addition & 29 deletions neo4j/internal/bolt/bolt4server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,6 @@ func (s *bolt4server) waitForPullN(n int) {
}
}

func (s *bolt4server) waitForPullNandQid(n, qid int) {
msg := s.receiveMsg()
s.assertStructType(msg, msgPullN)
extra := msg.fields[0].(map[string]any)
sentN := int(extra["n"].(int64))
if sentN != n {
panic(fmt.Sprintf("Expected PULL n:%d but got PULL %d", n, sentN))
}
sentQid := int(extra["qid"].(int64))
if sentQid != qid {
panic(fmt.Sprintf("Expected PULL qid:%d but got PULL %d", qid, sentQid))
}
}

func (s *bolt4server) waitForDiscardNAndQid(n, qid int) {
msg := s.receiveMsg()
s.assertStructType(msg, msgDiscardN)
extra := msg.fields[0].(map[string]any)
sentN := int(extra["n"].(int64))
if sentN != n {
panic(fmt.Sprintf("Expected DISCARD n:%d but got DISCARD %d", n, sentN))
}
sentQid := int(extra["qid"].(int64))
if sentQid != qid {
panic(fmt.Sprintf("Expected DISCARD qid:%d but got DISCARD %d", qid, sentQid))
}
}

func (s *bolt4server) waitForDiscardN(n int) {
msg := s.receiveMsg()
s.assertStructType(msg, msgDiscardN)
Expand Down Expand Up @@ -323,7 +295,7 @@ func setupBolt4Pipe(t *testing.T) (net.Conn, *bolt4server, func()) {
}

addr := l.Addr()
clientConn, err := net.Dial(addr.Network(), addr.String())
clientConn, _ := net.Dial(addr.Network(), addr.String())

srvConn, err := l.Accept()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion neo4j/internal/bolt/bolt5.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (b *bolt5) assertState(allowed ...int) error {
return nil
}
}
err := errors.New(fmt.Sprintf("Invalid state %d, expected: %+v", b.state, allowed))
err := fmt.Errorf("invalid state %d, expected: %+v", b.state, allowed)
b.log.Error(log.Bolt5, b.logId, err)
return err
}
Expand Down
37 changes: 1 addition & 36 deletions neo4j/internal/bolt/bolt5server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,6 @@ func (s *bolt5server) waitForPullN(n int) {
}
}

func (s *bolt5server) waitForPullNandQid(n, qid int) {
msg := s.receiveMsg()
s.assertStructType(msg, msgPullN)
extra := msg.fields[0].(map[string]any)
sentN := int(extra["n"].(int64))
if sentN != n {
panic(fmt.Sprintf("Expected PULL n:%d but got PULL %d", n, sentN))
}
sentQid := int(extra["qid"].(int64))
if sentQid != qid {
panic(fmt.Sprintf("Expected PULL qid:%d but got PULL %d", qid, sentQid))
}
}

func (s *bolt5server) waitForDiscardNAndQid(n, qid int) {
msg := s.receiveMsg()
s.assertStructType(msg, msgDiscardN)
extra := msg.fields[0].(map[string]any)
sentN := int(extra["n"].(int64))
if sentN != n {
panic(fmt.Sprintf("Expected DISCARD n:%d but got DISCARD %d", n, sentN))
}
sentQid := int(extra["qid"].(int64))
if sentQid != qid {
panic(fmt.Sprintf("Expected DISCARD qid:%d but got DISCARD %d", qid, sentQid))
}
}

func (s *bolt5server) waitForDiscardN(n int) {
msg := s.receiveMsg()
s.assertStructType(msg, msgDiscardN)
Expand Down Expand Up @@ -213,13 +185,6 @@ func (s *bolt5server) acceptVersion(major, minor byte) {
}
}

func (s *bolt5server) rejectVersions() {
_, err := s.conn.Write([]byte{0x00, 0x00, 0x00, 0x00})
if err != nil {
panic(err)
}
}

func (s *bolt5server) closeConnection() {
_ = s.conn.Close()
}
Expand Down Expand Up @@ -305,7 +270,7 @@ func setupBolt5Pipe(t *testing.T) (net.Conn, *bolt5server, func()) {
}

addr := l.Addr()
clientConn, err := net.Dial(addr.Network(), addr.String())
clientConn, _ := net.Dial(addr.Network(), addr.String())

srvConn, err := l.Accept()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion neo4j/internal/bolt/bolt_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type loggedSuccess struct {
TFirst string `json:"t_first,omitempty"`
Bookmark string `json:"bookmark,omitempty"`
TLast string `json:"t_last,omitempty"`
HasMore bool `json:"has_more,omitempy"`
HasMore bool `json:"has_more,omitempty"`
Db string `json:"db,omitempty"`
Qid int64 `json:"qid,omitempty"`
ConfigHints loggableDictionary `json:"hints,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions neo4j/internal/bolt/chunker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ func TestChunker(ot *testing.T) {

assertBuf := func(t *testing.T, buf *bytes.Buffer, exp []byte) {
t.Helper()
if bytes.Compare(exp, buf.Bytes()) != 0 {
if !bytes.Equal(exp, buf.Bytes()) {
t.Errorf("Chunked output differs")
}
}

assertSlices := func(t *testing.T, inp, exp []byte) {
t.Helper()
if bytes.Compare(exp, inp) != 0 {
if !bytes.Equal(exp, inp) {
t.Errorf("Dechunked output differs")
}
}
Expand Down
5 changes: 2 additions & 3 deletions neo4j/internal/bolt/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package bolt

import (
"context"
"errors"
"fmt"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/internal/db"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/internal/racing"
Expand Down Expand Up @@ -88,9 +87,9 @@ func Connect(ctx context.Context, serverName string, conn net.Conn, auth map[str
case 5:
boltConn = NewBolt5(serverName, conn, logger, boltLog)
case 0:
return nil, errors.New(fmt.Sprintf("Server did not accept any of the requested Bolt versions (%#v)", versions))
return nil, fmt.Errorf("server did not accept any of the requested Bolt versions (%#v)", versions)
default:
return nil, errors.New(fmt.Sprintf("Server responded with unsupported version %d.%d", major, minor))
return nil, fmt.Errorf("server responded with unsupported version %d.%d", major, minor)
}
if err = boltConn.Connect(ctx, int(minor), auth, userAgent, routingContext); err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 332277b

Please sign in to comment.