Skip to content

GODRIVER-2156 Enable deadcode linter. #770

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 @@ -5,7 +5,7 @@ linters:
disable-all: true
# TODO(GODRIVER-2156): Enable all commented-out linters.
enable:
# - deadcode
- deadcode
- errcheck
# - errorlint
- goimports
Expand Down
18 changes: 0 additions & 18 deletions benchmark/bson.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,3 @@ func loadSourceRaw(pathParts ...string) (bson.Raw, error) {

return bson.Raw(raw), nil
}

func loadSourceD(pathParts ...string) (bson.D, error) {
data, err := ioutil.ReadFile(filepath.Join(pathParts...))
if err != nil {
return nil, err
}
doc := bson.D{}
err = bson.UnmarshalExtJSON(data, true, &doc)
if err != nil {
return nil, err
}

if len(doc) == 0 {
return nil, errors.New("empty bson document")
}

return doc, nil
}
1 change: 0 additions & 1 deletion benchmark/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const (
tenThousand = ten * thousand
hundredThousand = hundred * thousand
million = hundred * hundredThousand
halfMillion = five * hundredThousand

ExecutionTimeout = five * time.Minute
StandardRuntime = time.Minute
Expand Down
7 changes: 0 additions & 7 deletions bson/bson_corpus_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"github.com/tidwall/pretty"
"go.mongodb.org/mongo-driver/bson/bsoncodec"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/internal/testutil/assert"
)
Expand Down Expand Up @@ -61,12 +60,6 @@ type parseErrorTestCase struct {

const dataDir = "../data/bson-corpus/"

var dvd bsoncodec.DefaultValueDecoders
var dve bsoncodec.DefaultValueEncoders

var dc = bsoncodec.DecodeContext{Registry: NewRegistryBuilder().Build()}
var ec = bsoncodec.EncodeContext{Registry: NewRegistryBuilder().Build()}

func findJSONFilesInDir(t *testing.T, dir string) []string {
files := make([]string, 0)

Expand Down
5 changes: 0 additions & 5 deletions bson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson/bsoncodec"
"go.mongodb.org/mongo-driver/bson/bsonoptions"
"go.mongodb.org/mongo-driver/bson/bsontype"
Expand All @@ -31,10 +30,6 @@ func noerr(t *testing.T, err error) {
}
}

func requireErrEqual(t *testing.T, err1 error, err2 error) {
require.True(t, compareErrors(err1, err2))
}

func TestTimeRoundTrip(t *testing.T) {
val := struct {
Value time.Time
Expand Down
2 changes: 0 additions & 2 deletions bson/bsoncodec/bsoncodec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ func compareDecimal128(d1, d2 primitive.Decimal128) bool {
return true
}

func compareStrings(s1, s2 string) bool { return s1 == s2 }

type noPrivateFields struct {
a string
}
Expand Down
1 change: 0 additions & 1 deletion bson/bsoncodec/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ func TestRegistry(t *testing.T) {

type fakeType1 struct{ b bool }
type fakeType2 struct{ b bool }
type fakeType3 struct{ b bool }
type fakeType4 struct{ b bool }
type fakeType5 func(string, string) string
type fakeStructCodec struct{ fakeCodec }
Expand Down
25 changes: 0 additions & 25 deletions bson/bsoncodec/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,12 @@ import (
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)

var ptBool = reflect.TypeOf((*bool)(nil))
var ptInt8 = reflect.TypeOf((*int8)(nil))
var ptInt16 = reflect.TypeOf((*int16)(nil))
var ptInt32 = reflect.TypeOf((*int32)(nil))
var ptInt64 = reflect.TypeOf((*int64)(nil))
var ptInt = reflect.TypeOf((*int)(nil))
var ptUint8 = reflect.TypeOf((*uint8)(nil))
var ptUint16 = reflect.TypeOf((*uint16)(nil))
var ptUint32 = reflect.TypeOf((*uint32)(nil))
var ptUint64 = reflect.TypeOf((*uint64)(nil))
var ptUint = reflect.TypeOf((*uint)(nil))
var ptFloat32 = reflect.TypeOf((*float32)(nil))
var ptFloat64 = reflect.TypeOf((*float64)(nil))
var ptString = reflect.TypeOf((*string)(nil))

var tBool = reflect.TypeOf(false)
var tFloat32 = reflect.TypeOf(float32(0))
var tFloat64 = reflect.TypeOf(float64(0))
var tInt = reflect.TypeOf(int(0))
var tInt8 = reflect.TypeOf(int8(0))
var tInt16 = reflect.TypeOf(int16(0))
var tInt32 = reflect.TypeOf(int32(0))
var tInt64 = reflect.TypeOf(int64(0))
var tString = reflect.TypeOf("")
var tTime = reflect.TypeOf(time.Time{})
var tUint = reflect.TypeOf(uint(0))
var tUint8 = reflect.TypeOf(uint8(0))
var tUint16 = reflect.TypeOf(uint16(0))
var tUint32 = reflect.TypeOf(uint32(0))
var tUint64 = reflect.TypeOf(uint64(0))

var tEmpty = reflect.TypeOf((*interface{})(nil)).Elem()
var tByteSlice = reflect.TypeOf([]byte(nil))
Expand Down Expand Up @@ -74,7 +50,6 @@ var tDecimal = reflect.TypeOf(primitive.Decimal128{})
var tMinKey = reflect.TypeOf(primitive.MinKey{})
var tMaxKey = reflect.TypeOf(primitive.MaxKey{})
var tD = reflect.TypeOf(primitive.D{})
var tM = reflect.TypeOf(primitive.M{})
var tA = reflect.TypeOf(primitive.A{})
var tE = reflect.TypeOf(primitive.E{})

Expand Down
6 changes: 0 additions & 6 deletions bson/bsonrw/extjson_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
)

var ejvwPool = sync.Pool{
New: func() interface{} {
return new(extJSONValueWriter)
},
}

// ExtJSONValueWriterPool is a pool for ExtJSON ValueWriters.
type ExtJSONValueWriterPool struct {
pool sync.Pool
Expand Down
4 changes: 2 additions & 2 deletions bson/bsonrw/value_reader_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
type VRWInvoked byte

const (
llvrwNothing VRWInvoked = iota
llvrwReadArray
_ = iota
llvrwReadArray VRWInvoked = 1
llvrwReadBinary
llvrwReadBoolean
llvrwReadDocument
Expand Down
70 changes: 0 additions & 70 deletions bson/bsonrw/value_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,73 +366,3 @@ type errWriter struct {
}

func (ew errWriter) Write([]byte) (int, error) { return 0, ew.err }

func vwBasicDoc(t *testing.T, vw *valueWriter) {
dw, err := vw.WriteDocument()
noerr(t, err)
vw2, err := dw.WriteDocumentElement("foo")
noerr(t, err)
err = vw2.WriteBoolean(true)
noerr(t, err)
err = dw.WriteDocumentEnd()
noerr(t, err)

return
}

func vwBasicArray(t *testing.T, vw *valueWriter) {
dw, err := vw.WriteDocument()
noerr(t, err)
vw2, err := dw.WriteDocumentElement("foo")
noerr(t, err)
aw, err := vw2.WriteArray()
noerr(t, err)
vw2, err = aw.WriteArrayElement()
noerr(t, err)
err = vw2.WriteBoolean(true)
noerr(t, err)
err = aw.WriteArrayEnd()
noerr(t, err)
err = dw.WriteDocumentEnd()
noerr(t, err)

return
}

func vwNestedDoc(t *testing.T, vw *valueWriter) {
dw, err := vw.WriteDocument()
noerr(t, err)
vw2, err := dw.WriteDocumentElement("foo")
noerr(t, err)
dw2, err := vw2.WriteDocument()
noerr(t, err)
vw3, err := dw2.WriteDocumentElement("bar")
noerr(t, err)
err = vw3.WriteBoolean(true)
noerr(t, err)
err = dw2.WriteDocumentEnd()
noerr(t, err)
err = dw.WriteDocumentEnd()
noerr(t, err)

return
}

func vwCodeWithScopeNoNested(t *testing.T, vw *valueWriter) {
dw, err := vw.WriteDocument()
noerr(t, err)
vw2, err := dw.WriteDocumentElement("foo")
noerr(t, err)
dw2, err := vw2.WriteCodeWithScope("var hello = world;")
noerr(t, err)
vw2, err = dw2.WriteDocumentElement("bar")
noerr(t, err)
err = vw2.WriteBoolean(false)
noerr(t, err)
err = dw2.WriteDocumentEnd()
noerr(t, err)
err = dw.WriteDocumentEnd()
noerr(t, err)

return
}
4 changes: 0 additions & 4 deletions bson/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ type byteMarshaler []byte

func (bm byteMarshaler) MarshalBSON() ([]byte, error) { return bm, nil }

type _Interface interface {
method()
}

type _impl struct {
Foo string
}
Expand Down
2 changes: 2 additions & 0 deletions bson/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)

var tInt32 = reflect.TypeOf(int32(0))

func TestMarshalAppendWithRegistry(t *testing.T) {
for _, tc := range marshalingTestCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
7 changes: 0 additions & 7 deletions bson/mgocompat/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,6 @@ type condTime struct {
type condStruct struct {
V struct{ A []int } `bson:",omitempty"`
}
type condRaw struct {
V bson.RawValue `bson:",omitempty"`
}

type shortInt struct {
V int64 `bson:",minsize"`
Expand All @@ -1142,9 +1139,6 @@ type shortNonEmptyInt struct {
type inlineInt struct {
V struct{ A, B int } `bson:",inline"`
}
type inlineCantPtr struct {
V *struct{ A, B int } `bson:",inline"`
}
type inlineDupName struct {
A int
V struct{ A, B int } `bson:",inline"`
Expand Down Expand Up @@ -1283,7 +1277,6 @@ var (
int64var = int64(42)
int64ptr = &int64var
intvar = int(42)
intptr = &intvar

gsintvar = getterSetterInt(42)
)
Expand Down
3 changes: 3 additions & 0 deletions bson/primitive_codecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
"go.mongodb.org/mongo-driver/bson/bsonrw"
)

var tRawValue = reflect.TypeOf(RawValue{})
var tRaw = reflect.TypeOf(Raw(nil))

var primitiveCodecs PrimitiveCodecs

// PrimitiveCodecs is a namespace for all of the default bsoncodec.Codecs for the primitive types
Expand Down
4 changes: 0 additions & 4 deletions bson/primitive_codecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,3 @@ type zeroTest struct {
func (z zeroTest) IsZero() bool { return z.reportZero }

func compareZeroTest(_, _ zeroTest) bool { return true }

type nonZeroer struct {
value bool
}
7 changes: 0 additions & 7 deletions bson/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

// ErrNilReader indicates that an operation was attempted on a nil bson.Reader.
var ErrNilReader = errors.New("nil reader")
var errValidateDone = errors.New("validation loop complete")

// Raw is a wrapper around a byte slice. It will interpret the slice as a
// BSON document. This type is a wrapper around a bsoncore.Document. Errors returned from the
Expand Down Expand Up @@ -84,9 +83,3 @@ func (r Raw) IndexErr(index uint) (RawElement, error) {

// String implements the fmt.Stringer interface.
func (r Raw) String() string { return bsoncore.Document(r).String() }

// readi32 is a helper function for reading an int32 from slice of bytes.
func readi32(b []byte) int32 {
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
return int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24
}
49 changes: 0 additions & 49 deletions bson/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
package bson

import (
"reflect"
"time"

"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/bson/primitive"
)

// These constants uniquely refer to each BSON type.
Expand All @@ -38,48 +34,3 @@ const (
TypeMinKey = bsontype.MinKey
TypeMaxKey = bsontype.MaxKey
)

var tBinary = reflect.TypeOf(primitive.Binary{})
var tBool = reflect.TypeOf(false)
var tCodeWithScope = reflect.TypeOf(primitive.CodeWithScope{})
var tDBPointer = reflect.TypeOf(primitive.DBPointer{})
var tDecimal = reflect.TypeOf(primitive.Decimal128{})
var tD = reflect.TypeOf(D{})
var tA = reflect.TypeOf(A{})
var tDateTime = reflect.TypeOf(primitive.DateTime(0))
var tUndefined = reflect.TypeOf(primitive.Undefined{})
var tNull = reflect.TypeOf(primitive.Null{})
var tRawValue = reflect.TypeOf(RawValue{})
var tFloat32 = reflect.TypeOf(float32(0))
var tFloat64 = reflect.TypeOf(float64(0))
var tInt = reflect.TypeOf(int(0))
var tInt8 = reflect.TypeOf(int8(0))
var tInt16 = reflect.TypeOf(int16(0))
var tInt32 = reflect.TypeOf(int32(0))
var tInt64 = reflect.TypeOf(int64(0))
var tJavaScript = reflect.TypeOf(primitive.JavaScript(""))
var tOID = reflect.TypeOf(primitive.ObjectID{})
var tRaw = reflect.TypeOf(Raw(nil))
var tRegex = reflect.TypeOf(primitive.Regex{})
var tString = reflect.TypeOf("")
var tSymbol = reflect.TypeOf(primitive.Symbol(""))
var tTime = reflect.TypeOf(time.Time{})
var tTimestamp = reflect.TypeOf(primitive.Timestamp{})
var tUint = reflect.TypeOf(uint(0))
var tUint8 = reflect.TypeOf(uint8(0))
var tUint16 = reflect.TypeOf(uint16(0))
var tUint32 = reflect.TypeOf(uint32(0))
var tUint64 = reflect.TypeOf(uint64(0))
var tMinKey = reflect.TypeOf(primitive.MinKey{})
var tMaxKey = reflect.TypeOf(primitive.MaxKey{})

var tEmpty = reflect.TypeOf((*interface{})(nil)).Elem()
var tEmptySlice = reflect.TypeOf([]interface{}(nil))

var zeroVal reflect.Value

// this references the quantity of milliseconds between zero time and
// the unix epoch. useful for making sure that we convert time.Time
// objects correctly to match the legacy bson library's handling of
// time.Time values.
const zeroEpochMs = int64(62135596800000)
7 changes: 0 additions & 7 deletions internal/testutil/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ func DropCollection(t *testing.T, dbname, colname string) {
}
}

func autoDropDB(t *testing.T, topo *topology.Topology) {
err := operation.NewCommand(bsoncore.BuildDocument(nil, bsoncore.AppendInt32Element(nil, "dropDatabase", 1))).
Database(DBName(t)).ServerSelector(description.WriteSelector()).Deployment(topo).
Execute(context.Background())
require.NoError(t, err)
}

// AutoInsertDocs inserts the docs into the test cluster.
func AutoInsertDocs(t *testing.T, writeConcern *writeconcern.WriteConcern, docs ...bsoncore.Document) {
InsertDocs(t, DBName(t), ColName(t), writeConcern, docs...)
Expand Down
Loading