Skip to content

GODRIVER-2156 Enable unparam linter. #802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ linters:
- typecheck
- unused
- unconvert
# - unparam
- unparam
- varcheck

linters-settings:
Expand Down
42 changes: 21 additions & 21 deletions benchmark/bson_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"go.mongodb.org/mongo-driver/x/bsonx"
)

func bsonDocumentEncoding(ctx context.Context, tm TimerManager, iters int, source string) error {
func bsonDocumentEncoding(tm TimerManager, iters int, source string) error {
doc, err := loadSourceDocument(getProjectRoot(), perfDataDir, bsonDataDir, source)
if err != nil {
return err
Expand All @@ -34,7 +34,7 @@ func bsonDocumentEncoding(ctx context.Context, tm TimerManager, iters int, sourc
return nil
}

func bsonDocumentDecodingLazy(ctx context.Context, tm TimerManager, iters int, source string) error {
func bsonDocumentDecodingLazy(tm TimerManager, iters int, source string) error {
doc, err := loadSourceDocument(getProjectRoot(), perfDataDir, bsonDataDir, source)
if err != nil {
return err
Expand All @@ -59,7 +59,7 @@ func bsonDocumentDecodingLazy(ctx context.Context, tm TimerManager, iters int, s
return nil
}

func bsonDocumentDecoding(ctx context.Context, tm TimerManager, iters, numKeys int, source string) error {
func bsonDocumentDecoding(tm TimerManager, iters, numKeys int, source string) error {
doc, err := loadSourceDocument(getProjectRoot(), perfDataDir, bsonDataDir, source)
if err != nil {
return err
Expand All @@ -86,38 +86,38 @@ func bsonDocumentDecoding(ctx context.Context, tm TimerManager, iters, numKeys i

}

func BSONFlatDocumentEncoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonDocumentEncoding(ctx, tm, iters, flatBSONData)
func BSONFlatDocumentEncoding(_ context.Context, tm TimerManager, iters int) error {
return bsonDocumentEncoding(tm, iters, flatBSONData)
}

func BSONFlatDocumentDecodingLazy(ctx context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecodingLazy(ctx, tm, iters, flatBSONData)
func BSONFlatDocumentDecodingLazy(_ context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecodingLazy(tm, iters, flatBSONData)
}

func BSONFlatDocumentDecoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecoding(ctx, tm, iters, 145, flatBSONData)
func BSONFlatDocumentDecoding(_ context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecoding(tm, iters, 145, flatBSONData)
}

func BSONDeepDocumentEncoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonDocumentEncoding(ctx, tm, iters, deepBSONData)
func BSONDeepDocumentEncoding(_ context.Context, tm TimerManager, iters int) error {
return bsonDocumentEncoding(tm, iters, deepBSONData)
}

func BSONDeepDocumentDecodingLazy(ctx context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecodingLazy(ctx, tm, iters, deepBSONData)
func BSONDeepDocumentDecodingLazy(_ context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecodingLazy(tm, iters, deepBSONData)
}

func BSONDeepDocumentDecoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecoding(ctx, tm, iters, 126, deepBSONData)
func BSONDeepDocumentDecoding(_ context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecoding(tm, iters, 126, deepBSONData)
}

func BSONFullDocumentEncoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonDocumentEncoding(ctx, tm, iters, fullBSONData)
func BSONFullDocumentEncoding(_ context.Context, tm TimerManager, iters int) error {
return bsonDocumentEncoding(tm, iters, fullBSONData)
}

func BSONFullDocumentDecodingLazy(ctx context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecodingLazy(ctx, tm, iters, fullBSONData)
func BSONFullDocumentDecodingLazy(_ context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecodingLazy(tm, iters, fullBSONData)
}

func BSONFullDocumentDecoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecoding(ctx, tm, iters, 145, fullBSONData)
func BSONFullDocumentDecoding(_ context.Context, tm TimerManager, iters int) error {
return bsonDocumentDecoding(tm, iters, 145, fullBSONData)
}
28 changes: 14 additions & 14 deletions benchmark/bson_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
)

func bsonMapDecoding(ctx context.Context, tm TimerManager, iters int, dataSet string) error {
func bsonMapDecoding(tm TimerManager, iters int, dataSet string) error {
r, err := loadSourceRaw(getProjectRoot(), perfDataDir, bsonDataDir, dataSet)
if err != nil {
return err
Expand All @@ -35,7 +35,7 @@ func bsonMapDecoding(ctx context.Context, tm TimerManager, iters int, dataSet st
return nil
}

func bsonMapEncoding(ctx context.Context, tm TimerManager, iters int, dataSet string) error {
func bsonMapEncoding(tm TimerManager, iters int, dataSet string) error {
r, err := loadSourceRaw(getProjectRoot(), perfDataDir, bsonDataDir, dataSet)
if err != nil {
return err
Expand Down Expand Up @@ -63,26 +63,26 @@ func bsonMapEncoding(ctx context.Context, tm TimerManager, iters int, dataSet st
return nil
}

func BSONFlatMapDecoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonMapDecoding(ctx, tm, iters, flatBSONData)
func BSONFlatMapDecoding(_ context.Context, tm TimerManager, iters int) error {
return bsonMapDecoding(tm, iters, flatBSONData)
}

func BSONFlatMapEncoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonMapEncoding(ctx, tm, iters, flatBSONData)
func BSONFlatMapEncoding(_ context.Context, tm TimerManager, iters int) error {
return bsonMapEncoding(tm, iters, flatBSONData)
}

func BSONDeepMapDecoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonMapDecoding(ctx, tm, iters, deepBSONData)
func BSONDeepMapDecoding(_ context.Context, tm TimerManager, iters int) error {
return bsonMapDecoding(tm, iters, deepBSONData)
}

func BSONDeepMapEncoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonMapEncoding(ctx, tm, iters, deepBSONData)
func BSONDeepMapEncoding(_ context.Context, tm TimerManager, iters int) error {
return bsonMapEncoding(tm, iters, deepBSONData)
}

func BSONFullMapDecoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonMapDecoding(ctx, tm, iters, fullBSONData)
func BSONFullMapDecoding(_ context.Context, tm TimerManager, iters int) error {
return bsonMapDecoding(tm, iters, fullBSONData)
}

func BSONFullMapEncoding(ctx context.Context, tm TimerManager, iters int) error {
return bsonMapEncoding(ctx, tm, iters, fullBSONData)
func BSONFullMapEncoding(_ context.Context, tm TimerManager, iters int) error {
return bsonMapEncoding(tm, iters, fullBSONData)
}
24 changes: 12 additions & 12 deletions bson/bsoncodec/cond_addr_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func TestCondAddrCodec(t *testing.T) {

t.Run("addressEncode", func(t *testing.T) {
invoked := 0
encode1 := func(EncodeContext, bsonrw.ValueWriter, reflect.Value) error {
encode1 := ValueEncoderFunc(func(EncodeContext, bsonrw.ValueWriter, reflect.Value) error {
invoked = 1
return nil
}
encode2 := func(EncodeContext, bsonrw.ValueWriter, reflect.Value) error {
})
encode2 := ValueEncoderFunc(func(EncodeContext, bsonrw.ValueWriter, reflect.Value) error {
invoked = 2
return nil
}
condEncoder := newCondAddrEncoder(ValueEncoderFunc(encode1), ValueEncoderFunc(encode2))
})
condEncoder := newCondAddrEncoder(encode1, encode2)

testCases := []struct {
name string
Expand All @@ -52,23 +52,23 @@ func TestCondAddrCodec(t *testing.T) {
}

t.Run("error", func(t *testing.T) {
errEncoder := newCondAddrEncoder(ValueEncoderFunc(encode1), nil)
errEncoder := newCondAddrEncoder(encode1, nil)
err := errEncoder.EncodeValue(EncodeContext{}, rw, unaddressable)
want := ErrNoEncoder{Type: unaddressable.Type()}
assert.Equal(t, err, want, "expected error %v, got %v", want, err)
})
})
t.Run("addressDecode", func(t *testing.T) {
invoked := 0
decode1 := func(dctx DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
decode1 := ValueDecoderFunc(func(DecodeContext, bsonrw.ValueReader, reflect.Value) error {
invoked = 1
return nil
}
decode2 := func(dctx DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
})
decode2 := ValueDecoderFunc(func(DecodeContext, bsonrw.ValueReader, reflect.Value) error {
invoked = 2
return nil
}
condDecoder := newCondAddrDecoder(ValueDecoderFunc(decode1), ValueDecoderFunc(decode2))
})
condDecoder := newCondAddrDecoder(decode1, decode2)

testCases := []struct {
name string
Expand All @@ -88,7 +88,7 @@ func TestCondAddrCodec(t *testing.T) {
}

t.Run("error", func(t *testing.T) {
errDecoder := newCondAddrDecoder(ValueDecoderFunc(decode1), nil)
errDecoder := newCondAddrDecoder(decode1, nil)
err := errDecoder.DecodeValue(DecodeContext{}, rw, unaddressable)
want := ErrNoDecoder{Type: unaddressable.Type()}
assert.Equal(t, err, want, "expected error %v, got %v", want, err)
Expand Down
26 changes: 7 additions & 19 deletions bson/bsoncodec/default_value_decoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3040,15 +3040,15 @@ func TestDefaultValueDecoders(t *testing.T) {
doc = appendArrayElement(doc, "e", bsoncore.AppendInt64Element(nil, "0", 101112))
doc = appendArrayElement(doc, "f", bsoncore.AppendDoubleElement(nil, "0", 3.14159))
doc = appendArrayElement(doc, "g", bsoncore.AppendStringElement(nil, "0", "Hello, world"))
doc = appendArrayElement(doc, "h", buildDocumentElement("0", bsoncore.AppendStringElement(nil, "foo", "bar")))
doc = appendArrayElement(doc, "h", bsoncore.BuildDocumentElement(nil, "0", bsoncore.AppendStringElement(nil, "foo", "bar")))
doc = appendArrayElement(doc, "i", bsoncore.AppendBinaryElement(nil, "0", 0x00, []byte{0x01, 0x02, 0x03}))
doc = appendArrayElement(doc, "k",
buildArrayElement("0",
appendArrayElement(nil, "0",
bsoncore.AppendStringElement(bsoncore.AppendStringElement(nil, "0", "baz"), "1", "qux")),
)
doc = appendArrayElement(doc, "l", buildDocumentElement("0", bsoncore.AppendStringElement(nil, "m", "foobar")))
doc = appendArrayElement(doc, "l", bsoncore.BuildDocumentElement(nil, "0", bsoncore.AppendStringElement(nil, "m", "foobar")))
doc = appendArrayElement(doc, "n",
buildArrayElement("0",
appendArrayElement(nil, "0",
bsoncore.AppendStringElement(bsoncore.AppendStringElement(nil, "0", "foo"), "1", "bar")),
)
doc = appendArrayElement(doc, "r",
Expand All @@ -3062,7 +3062,7 @@ func TestDefaultValueDecoders(t *testing.T) {
doc = bsoncore.AppendNullElement(doc, "t")
doc = bsoncore.AppendNullElement(doc, "w")
doc = appendArrayElement(doc, "x", nil)
doc = appendArrayElement(doc, "y", buildDocumentElement("0", nil))
doc = appendArrayElement(doc, "y", bsoncore.BuildDocumentElement(nil, "0", nil))
doc = appendArrayElement(doc, "z",
bsoncore.AppendDateTimeElement(
bsoncore.AppendDateTimeElement(
Expand Down Expand Up @@ -3103,15 +3103,14 @@ func TestDefaultValueDecoders(t *testing.T) {
)
doc = appendArrayElement(doc, "ak",
bsoncore.AppendNullElement(
buildArrayElement("0",
appendArrayElement(nil, "0",
bsoncore.AppendStringElement(bsoncore.AppendStringElement(nil, "0", "foo"), "1", "bar"),
),
"1",
),
)
doc = appendArrayElement(doc, "al",
buildDocumentElement(
"0",
bsoncore.BuildDocumentElement(nil, "0",
bsoncore.AppendDoubleElement(bsoncore.AppendStringElement(nil, "hello", "world"), "pi", 3.14159),
),
)
Expand Down Expand Up @@ -3779,10 +3778,6 @@ func buildArray(vals []byte) []byte {
return doc
}

func buildArrayElement(key string, vals []byte) []byte {
return appendArrayElement(nil, key, vals)
}

func appendArrayElement(dst []byte, key string, vals []byte) []byte {
aix, doc := bsoncore.AppendArrayElementStart(dst, key)
doc = append(doc, vals...)
Expand All @@ -3797,10 +3792,3 @@ func buildDocument(elems []byte) []byte {
doc, _ = bsoncore.AppendDocumentEnd(doc, idx)
return doc
}

func buildDocumentElement(key string, elems []byte) []byte {
idx, doc := bsoncore.AppendDocumentElementStart(nil, key)
doc = append(doc, elems...)
doc, _ = bsoncore.AppendDocumentEnd(doc, idx)
return doc
}
10 changes: 5 additions & 5 deletions bson/bsoncodec/default_value_encoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1712,15 +1712,15 @@ func TestDefaultValueEncoders(t *testing.T) {
doc = appendArrayElement(doc, "e", bsoncore.AppendInt64Element(nil, "0", 101112))
doc = appendArrayElement(doc, "f", bsoncore.AppendDoubleElement(nil, "0", 3.14159))
doc = appendArrayElement(doc, "g", bsoncore.AppendStringElement(nil, "0", "Hello, world"))
doc = appendArrayElement(doc, "h", buildDocumentElement("0", bsoncore.AppendStringElement(nil, "foo", "bar")))
doc = appendArrayElement(doc, "h", bsoncore.BuildDocumentElement(nil, "0", bsoncore.AppendStringElement(nil, "foo", "bar")))
doc = appendArrayElement(doc, "i", bsoncore.AppendBinaryElement(nil, "0", 0x00, []byte{0x01, 0x02, 0x03}))
doc = appendArrayElement(doc, "k",
buildArrayElement("0",
appendArrayElement(nil, "0",
bsoncore.AppendStringElement(bsoncore.AppendStringElement(nil, "0", "baz"), "1", "qux")),
)
doc = appendArrayElement(doc, "l", buildDocumentElement("0", bsoncore.AppendStringElement(nil, "m", "foobar")))
doc = appendArrayElement(doc, "l", bsoncore.BuildDocumentElement(nil, "0", bsoncore.AppendStringElement(nil, "m", "foobar")))
doc = appendArrayElement(doc, "n",
buildArrayElement("0",
appendArrayElement(nil, "0",
bsoncore.AppendStringElement(bsoncore.AppendStringElement(nil, "0", "foo"), "1", "bar")),
)
doc = appendArrayElement(doc, "r",
Expand All @@ -1734,7 +1734,7 @@ func TestDefaultValueEncoders(t *testing.T) {
doc = bsoncore.AppendNullElement(doc, "t")
doc = bsoncore.AppendNullElement(doc, "w")
doc = appendArrayElement(doc, "x", nil)
doc = appendArrayElement(doc, "y", buildDocumentElement("0", nil))
doc = appendArrayElement(doc, "y", bsoncore.BuildDocumentElement(nil, "0", nil))
doc = appendArrayElement(doc, "z",
bsoncore.AppendDateTimeElement(
bsoncore.AppendDateTimeElement(
Expand Down
4 changes: 2 additions & 2 deletions mongo/change_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (cs *ChangeStream) executeOperation(ctx context.Context, resuming bool) err
cs.aggregate.Deployment(cs.createOperationDeployment(server, conn))

if resuming {
cs.replaceOptions(ctx, cs.wireVersion)
cs.replaceOptions(cs.wireVersion)

csOptDoc := cs.createPipelineOptionsDoc()
pipIdx, pipDoc := bsoncore.AppendDocumentStart(nil)
Expand Down Expand Up @@ -408,7 +408,7 @@ func (cs *ChangeStream) pipelineToBSON() (bsoncore.Document, error) {
return pipelineArr, cs.err
}

func (cs *ChangeStream) replaceOptions(ctx context.Context, wireVersion *description.VersionRange) {
func (cs *ChangeStream) replaceOptions(wireVersion *description.VersionRange) {
// Cached resume token: use the resume token as the resumeAfter option and set no other resume options
if cs.resumeToken != nil {
cs.options.SetResumeAfter(cs.resumeToken)
Expand Down
2 changes: 1 addition & 1 deletion mongo/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestClient(t *testing.T) {

serverVersion, err := getServerVersion(client.Database("admin"))
assert.Nil(t, err, "getServerVersion error: %v", err)
if compareVersions(t, serverVersion, "3.6.0") < 1 {
if compareVersions(serverVersion, "3.6.0") < 1 {
t.Skip("skipping server version < 3.6")
}

Expand Down
2 changes: 1 addition & 1 deletion mongo/integration/change_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func TestChangeStream_ReplicaSet(t *testing.T) {
for i := 0; i < 2; i++ {
assert.False(mt, cs.TryNext(mtest.Background), "TryNext returned true on iteration %v", i)
}
verifyOneGetmoreSent(mt, cs)
verifyOneGetmoreSent(mt)
})
mt.RunOpts("getMore error", mtest.NewOptions().ClientType(mtest.Mock), func(mt *mtest.T) {
// If the getMore attempt errors with a non-resumable error, TryNext returns false
Expand Down
2 changes: 1 addition & 1 deletion mongo/integration/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ func TestCollection(t *testing.T) {
testAggregateWithOptions(mt, true, options.Aggregate().SetHint(hint))
})
mt.RunOpts("multikey map hint", mtest.NewOptions().MinServerVersion("3.6"), func(mt *mtest.T) {
pipeline := mongo.Pipeline{{{"$out", mt.Coll.Name()}}}
pipeline := mongo.Pipeline{bson.D{{"$out", mt.Coll.Name()}}}
cursor, err := mt.Coll.Aggregate(mtest.Background, pipeline, options.Aggregate().SetHint(bson.M{"x": 1, "y": 1}))
assert.Nil(mt, cursor, "expected cursor nil, got %v", cursor)
assert.Equal(mt, mongo.ErrMapForOrderedArgument{"hint"}, err, "expected error %v, got %v", mongo.ErrMapForOrderedArgument{"hint"}, err)
Expand Down
8 changes: 4 additions & 4 deletions mongo/integration/crud_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func killSessions(mt *mtest.T) {

// killAllSessions has to be run against each mongos in a sharded cluster, so we use the runCommandOnAllServers
// helper.
err := runCommandOnAllServers(mt, func(client *mongo.Client) error {
err := runCommandOnAllServers(func(client *mongo.Client) error {
return client.Database("admin").RunCommand(mtest.Background, cmd, runCmdOpts).Err()
})

Expand All @@ -118,7 +118,7 @@ func killSessions(mt *mtest.T) {

// Utility function to run a command on all servers. For standalones, the command is run against the one server. For
// replica sets, the command is run against the primary. sharded clusters, the command is run against each mongos.
func runCommandOnAllServers(mt *mtest.T, commandFn func(client *mongo.Client) error) error {
func runCommandOnAllServers(commandFn func(client *mongo.Client) error) error {
opts := options.Client().ApplyURI(mtest.ClusterURI())
testutil.AddTestServerAPIVersion(opts)

Expand Down Expand Up @@ -337,7 +337,7 @@ func executeInsertMany(mt *mtest.T, sess mongo.Session, args bson.Raw) (*mongo.I
return mt.Coll.InsertMany(mtest.Background, docs, opts)
}

func setFindModifiers(mt *mtest.T, modifiersDoc bson.Raw, opts *options.FindOptions) {
func setFindModifiers(modifiersDoc bson.Raw, opts *options.FindOptions) {
elems, _ := modifiersDoc.Elements()
for _, elem := range elems {
key := elem.Key()
Expand Down Expand Up @@ -387,7 +387,7 @@ func executeFind(mt *mtest.T, sess mongo.Session, args bson.Raw) (*mongo.Cursor,
case "collation":
opts = opts.SetCollation(createCollation(mt, val.Document()))
case "modifiers":
setFindModifiers(mt, val.Document(), opts)
setFindModifiers(val.Document(), opts)
case "allowDiskUse":
opts = opts.SetAllowDiskUse(val.Boolean())
case "projection":
Expand Down
Loading