Skip to content

Commit

Permalink
GODRIVER-2156 Enable unused linter. (mongodb#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdale authored Oct 27, 2021
1 parent 84c7a26 commit 432c3fa
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 173 deletions.
18 changes: 15 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ linters:
- staticcheck
# - structcheck
- typecheck
# - unused
- unused
# - unconvert
# - unparam
# - varcheck
Expand Down Expand Up @@ -54,11 +54,23 @@ issues:
- (^|/)data($|/)
- (^|/)etc($|/)
exclude-rules:
# Ignore some linters for example code that is intentionally simplified.
- path: examples/
linters:
- revive
- errcheck
# Ignore some linters for generated operation code.
# TODO: Re-enable once GODRIVER-2154 is done.
- path: x/mongo/driver/operation/
linters:
- staticcheck # TODO: Re-enable once GODRIVER-2154 is done.
- ineffassign # TODO: Re-enable once GODRIVER-2154 is done.
- staticcheck
- ineffassign
# Disable unused code linters for the copy/pasted "awsv4" package.
- path: x/mongo/driver/auth/internal/awsv4
linters:
- unused
# Disable "unused" linter for "crypt.go" because the linter doesn't work correctly without
# enabling CGO.
- path: x/mongo/driver/crypt.go
linters:
- unused
4 changes: 0 additions & 4 deletions benchmark/harness_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ func (c *CaseDefinition) StopTimer() {
c.isRunning = false
}

func (c *CaseDefinition) roundedRuntime() time.Duration {
return roundDurationMS(c.Runtime)
}

func (c *CaseDefinition) Run(ctx context.Context) *BenchResult {
out := &BenchResult{
Trials: 1,
Expand Down
1 change: 0 additions & 1 deletion bson/bsoncodec/default_value_encoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func TestDefaultValueEncoders(t *testing.T) {
type myuint uint
type myfloat32 float32
type myfloat64 float64
type mystring string

now := time.Now().Truncate(time.Millisecond)
pjsnum := new(json.Number)
Expand Down
6 changes: 0 additions & 6 deletions bson/bsoncodec/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ func (entme ErrNoTypeMapEntry) Error() string {
// ErrNotInterface is returned when the provided type is not an interface.
var ErrNotInterface = errors.New("The provided type is not an interface")

var defaultRegistry *Registry

func init() {
defaultRegistry = buildDefaultRegistry()
}

// A RegistryBuilder is used to build a Registry. This type is not goroutine
// safe.
type RegistryBuilder struct {
Expand Down
6 changes: 3 additions & 3 deletions bson/bsoncodec/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ func TestRegistry(t *testing.T) {
})
}

type fakeType1 struct{ b bool }
type fakeType2 struct{ b bool }
type fakeType4 struct{ b bool }
type fakeType1 struct{}
type fakeType2 struct{}
type fakeType4 struct{}
type fakeType5 func(string, string) string
type fakeStructCodec struct{ fakeCodec }
type fakeSliceCodec struct{ fakeCodec }
Expand Down
10 changes: 0 additions & 10 deletions bson/bsonrw/value_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,16 +790,6 @@ func (vr *valueReader) readCString() (string, error) {
return string(vr.d[start : start+int64(idx)]), nil
}

func (vr *valueReader) skipCString() error {
idx := bytes.IndexByte(vr.d[vr.offset:], 0x00)
if idx < 0 {
return io.EOF
}
// idx does not include the null byte
vr.offset += int64(idx) + 1
return nil
}

func (vr *valueReader) readString() (string, error) {
length, err := vr.readLength()
if err != nil {
Expand Down
24 changes: 0 additions & 24 deletions bson/bsonrw/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,3 @@ func (sw *SliceWriter) Write(p []byte) (int, error) {
*sw = append(*sw, p...)
return written, nil
}

type writer []byte

func (w *writer) Write(p []byte) (int, error) {
index := len(*w)
return w.WriteAt(p, int64(index))
}

func (w *writer) WriteAt(p []byte, off int64) (int, error) {
newend := off + int64(len(p))
if newend < int64(len(*w)) {
newend = int64(len(*w))
}

if newend > int64(cap(*w)) {
buf := make([]byte, int64(2*cap(*w))+newend)
copy(buf, *w)
*w = buf
}

*w = []byte(*w)[:newend]
copy([]byte(*w)[off:], p)
return len(p), nil
}
18 changes: 3 additions & 15 deletions bson/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func TestDecoderv2(t *testing.T) {
}
t.Run("lookup error", func(t *testing.T) {
type certainlydoesntexistelsewhereihope func(string, string) string
// Avoid unused code lint error.
_ = certainlydoesntexistelsewhereihope(func(string, string) string { return "" })

cdeih := func(string, string) string { return "certainlydoesntexistelsewhereihope" }
dec, err := NewDecoder(bsonrw.NewBSONDocumentReader([]byte{}))
noerr(t, err)
Expand Down Expand Up @@ -249,21 +252,6 @@ func TestDecoderv2(t *testing.T) {
})
}

type testDecoderCodec struct {
EncodeValueCalled bool
DecodeValueCalled bool
}

func (tdc *testDecoderCodec) EncodeValue(bsoncodec.EncodeContext, bsonrw.ValueWriter, interface{}) error {
tdc.EncodeValueCalled = true
return nil
}

func (tdc *testDecoderCodec) DecodeValue(bsoncodec.DecodeContext, bsonrw.ValueReader, interface{}) error {
tdc.DecodeValueCalled = true
return nil
}

type testUnmarshaler struct {
invoked bool
err error
Expand Down
10 changes: 0 additions & 10 deletions bson/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,3 @@ func docToBytes(d interface{}) []byte {
}
return b
}

type byteMarshaler []byte

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

type _impl struct {
Foo string
}

func (_impl) method() {}
22 changes: 0 additions & 22 deletions bson/primitive_codecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,3 @@ func (PrimitiveCodecs) RawDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.Valu
val.Set(reflect.ValueOf(rdr))
return err
}

func (pc PrimitiveCodecs) encodeRaw(ec bsoncodec.EncodeContext, dw bsonrw.DocumentWriter, raw Raw) error {
var copier bsonrw.Copier
elems, err := raw.Elements()
if err != nil {
return err
}
for _, elem := range elems {
dvw, err := dw.WriteDocumentElement(elem.Key())
if err != nil {
return err
}

val := elem.Value()
err = copier.CopyValueFromBytes(dvw, val.Type, val.Value)
if err != nil {
return err
}
}

return dw.WriteDocumentEnd()
}
3 changes: 0 additions & 3 deletions mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
"go.mongodb.org/mongo-driver/x/mongo/driver"
"go.mongodb.org/mongo-driver/x/mongo/driver/auth"
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
"go.mongodb.org/mongo-driver/x/mongo/driver/ocsp"
"go.mongodb.org/mongo-driver/x/mongo/driver/operation"
"go.mongodb.org/mongo-driver/x/mongo/driver/session"
Expand All @@ -52,7 +51,6 @@ type Client struct {
id uuid.UUID
topologyOptions []topology.Option
deployment driver.Deployment
connString connstring.ConnString
localThreshold time.Duration
retryWrites bool
retryReads bool
Expand All @@ -61,7 +59,6 @@ type Client struct {
readConcern *readconcern.ReadConcern
writeConcern *writeconcern.WriteConcern
registry *bsoncodec.Registry
marshaller BSONAppender
monitor *event.CommandMonitor
serverAPI *driver.ServerAPIOptions
serverMonitor *event.ServerMonitor
Expand Down
1 change: 0 additions & 1 deletion mongo/integration/unified/unified_spec_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type TestCase struct {

initialData []*collectionData
createEntities []map[string]*entityOptions
fileReqs []mtest.RunOnBlock
killAllSessions bool
schemaVersion string

Expand Down
21 changes: 0 additions & 21 deletions x/bsonx/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,6 @@ type Val struct {
primitive interface{}
}

func (v Val) reset() Val {
v.primitive = nil // clear out any pointers so we don't accidentally stop them from being garbage collected.
v.t = bsontype.Type(0)
v.bootstrap[0] = 0x00
v.bootstrap[1] = 0x00
v.bootstrap[2] = 0x00
v.bootstrap[3] = 0x00
v.bootstrap[4] = 0x00
v.bootstrap[5] = 0x00
v.bootstrap[6] = 0x00
v.bootstrap[7] = 0x00
v.bootstrap[8] = 0x00
v.bootstrap[9] = 0x00
v.bootstrap[10] = 0x00
v.bootstrap[11] = 0x00
v.bootstrap[12] = 0x00
v.bootstrap[13] = 0x00
v.bootstrap[14] = 0x00
return v
}

func (v Val) string() string {
if v.primitive != nil {
return v.primitive.(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,3 @@ func (kc *KmsContext) BytesNeeded() int32 {
func (kc *KmsContext) FeedResponse(response []byte) error {
panic(cseNotSupportedMsg)
}

// createErrorFromStatus creates a new Error from the status of the KmsContext instance.
func (kc *KmsContext) createErrorFromStatus() error {
panic(cseNotSupportedMsg)
}
2 changes: 0 additions & 2 deletions x/mongo/driver/operation/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ type Command struct {
monitor *event.CommandMonitor
resultResponse bsoncore.Document
resultCursor *driver.BatchCursor
srvr driver.Server
desc description.Server
crypt *driver.Crypt
serverAPI *driver.ServerAPIOptions
createCursor bool
Expand Down
42 changes: 0 additions & 42 deletions x/mongo/driver/operation/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package operation
import (
"context"
"errors"
"fmt"
"runtime"
"strconv"

Expand Down Expand Up @@ -108,47 +107,6 @@ func (h *Hello) Result(addr address.Address) description.Server {
return description.NewServer(addr, bson.Raw(h.res))
}

func (h *Hello) decodeStringSlice(element bsoncore.Element, name string) ([]string, error) {
arr, ok := element.Value().ArrayOK()
if !ok {
return nil, fmt.Errorf("expected '%s' to be an array but it's a BSON %s", name, element.Value().Type)
}
vals, err := arr.Values()
if err != nil {
return nil, err
}
var strs []string
for _, val := range vals {
str, ok := val.StringValueOK()
if !ok {
return nil, fmt.Errorf("expected '%s' to be an array of strings, but found a BSON %s", name, val.Type)
}
strs = append(strs, str)
}
return strs, nil
}

func (h *Hello) decodeStringMap(element bsoncore.Element, name string) (map[string]string, error) {
doc, ok := element.Value().DocumentOK()
if !ok {
return nil, fmt.Errorf("expected '%s' to be a document but it's a BSON %s", name, element.Value().Type)
}
elements, err := doc.Elements()
if err != nil {
return nil, err
}
m := make(map[string]string)
for _, element := range elements {
key := element.Key()
value, ok := element.Value().StringValueOK()
if !ok {
return nil, fmt.Errorf("expected '%s' to be a document of strings, but found a BSON %s", name, element.Value().Type)
}
m[key] = value
}
return m, nil
}

// handshakeCommand appends all necessary command fields as well as client metadata, SASL supported mechs, and compression.
func (h *Hello) handshakeCommand(dst []byte, desc description.SelectedServer) ([]byte, error) {
dst, err := h.command(dst, desc)
Expand Down
1 change: 0 additions & 1 deletion x/mongo/driver/topology/connection_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type Handshaker = driver.Handshaker
type generationNumberFn func(serviceID *primitive.ObjectID) uint64

type connectionConfig struct {
appName string
connectTimeout time.Duration
dialer Dialer
handshaker Handshaker
Expand Down

0 comments on commit 432c3fa

Please sign in to comment.