Skip to content

Commit 432c3fa

Browse files
authored
GODRIVER-2156 Enable unused linter. (#773)
1 parent 84c7a26 commit 432c3fa

File tree

17 files changed

+21
-173
lines changed

17 files changed

+21
-173
lines changed

.golangci.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ linters:
1818
- staticcheck
1919
# - structcheck
2020
- typecheck
21-
# - unused
21+
- unused
2222
# - unconvert
2323
# - unparam
2424
# - varcheck
@@ -54,11 +54,23 @@ issues:
5454
- (^|/)data($|/)
5555
- (^|/)etc($|/)
5656
exclude-rules:
57+
# Ignore some linters for example code that is intentionally simplified.
5758
- path: examples/
5859
linters:
5960
- revive
6061
- errcheck
62+
# Ignore some linters for generated operation code.
63+
# TODO: Re-enable once GODRIVER-2154 is done.
6164
- path: x/mongo/driver/operation/
6265
linters:
63-
- staticcheck # TODO: Re-enable once GODRIVER-2154 is done.
64-
- ineffassign # TODO: Re-enable once GODRIVER-2154 is done.
66+
- staticcheck
67+
- ineffassign
68+
# Disable unused code linters for the copy/pasted "awsv4" package.
69+
- path: x/mongo/driver/auth/internal/awsv4
70+
linters:
71+
- unused
72+
# Disable "unused" linter for "crypt.go" because the linter doesn't work correctly without
73+
# enabling CGO.
74+
- path: x/mongo/driver/crypt.go
75+
linters:
76+
- unused

benchmark/harness_case.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ func (c *CaseDefinition) StopTimer() {
5656
c.isRunning = false
5757
}
5858

59-
func (c *CaseDefinition) roundedRuntime() time.Duration {
60-
return roundDurationMS(c.Runtime)
61-
}
62-
6359
func (c *CaseDefinition) Run(ctx context.Context) *BenchResult {
6460
out := &BenchResult{
6561
Trials: 1,

bson/bsoncodec/default_value_encoders_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func TestDefaultValueEncoders(t *testing.T) {
5454
type myuint uint
5555
type myfloat32 float32
5656
type myfloat64 float64
57-
type mystring string
5857

5958
now := time.Now().Truncate(time.Millisecond)
6059
pjsnum := new(json.Number)

bson/bsoncodec/registry.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ func (entme ErrNoTypeMapEntry) Error() string {
5454
// ErrNotInterface is returned when the provided type is not an interface.
5555
var ErrNotInterface = errors.New("The provided type is not an interface")
5656

57-
var defaultRegistry *Registry
58-
59-
func init() {
60-
defaultRegistry = buildDefaultRegistry()
61-
}
62-
6357
// A RegistryBuilder is used to build a Registry. This type is not goroutine
6458
// safe.
6559
type RegistryBuilder struct {

bson/bsoncodec/registry_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ func TestRegistry(t *testing.T) {
409409
})
410410
}
411411

412-
type fakeType1 struct{ b bool }
413-
type fakeType2 struct{ b bool }
414-
type fakeType4 struct{ b bool }
412+
type fakeType1 struct{}
413+
type fakeType2 struct{}
414+
type fakeType4 struct{}
415415
type fakeType5 func(string, string) string
416416
type fakeStructCodec struct{ fakeCodec }
417417
type fakeSliceCodec struct{ fakeCodec }

bson/bsonrw/value_reader.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -790,16 +790,6 @@ func (vr *valueReader) readCString() (string, error) {
790790
return string(vr.d[start : start+int64(idx)]), nil
791791
}
792792

793-
func (vr *valueReader) skipCString() error {
794-
idx := bytes.IndexByte(vr.d[vr.offset:], 0x00)
795-
if idx < 0 {
796-
return io.EOF
797-
}
798-
// idx does not include the null byte
799-
vr.offset += int64(idx) + 1
800-
return nil
801-
}
802-
803793
func (vr *valueReader) readString() (string, error) {
804794
length, err := vr.readLength()
805795
if err != nil {

bson/bsonrw/writer.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,3 @@ func (sw *SliceWriter) Write(p []byte) (int, error) {
7676
*sw = append(*sw, p...)
7777
return written, nil
7878
}
79-
80-
type writer []byte
81-
82-
func (w *writer) Write(p []byte) (int, error) {
83-
index := len(*w)
84-
return w.WriteAt(p, int64(index))
85-
}
86-
87-
func (w *writer) WriteAt(p []byte, off int64) (int, error) {
88-
newend := off + int64(len(p))
89-
if newend < int64(len(*w)) {
90-
newend = int64(len(*w))
91-
}
92-
93-
if newend > int64(cap(*w)) {
94-
buf := make([]byte, int64(2*cap(*w))+newend)
95-
copy(buf, *w)
96-
*w = buf
97-
}
98-
99-
*w = []byte(*w)[:newend]
100-
copy([]byte(*w)[off:], p)
101-
return len(p), nil
102-
}

bson/decoder_test.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func TestDecoderv2(t *testing.T) {
6262
}
6363
t.Run("lookup error", func(t *testing.T) {
6464
type certainlydoesntexistelsewhereihope func(string, string) string
65+
// Avoid unused code lint error.
66+
_ = certainlydoesntexistelsewhereihope(func(string, string) string { return "" })
67+
6568
cdeih := func(string, string) string { return "certainlydoesntexistelsewhereihope" }
6669
dec, err := NewDecoder(bsonrw.NewBSONDocumentReader([]byte{}))
6770
noerr(t, err)
@@ -249,21 +252,6 @@ func TestDecoderv2(t *testing.T) {
249252
})
250253
}
251254

252-
type testDecoderCodec struct {
253-
EncodeValueCalled bool
254-
DecodeValueCalled bool
255-
}
256-
257-
func (tdc *testDecoderCodec) EncodeValue(bsoncodec.EncodeContext, bsonrw.ValueWriter, interface{}) error {
258-
tdc.EncodeValueCalled = true
259-
return nil
260-
}
261-
262-
func (tdc *testDecoderCodec) DecodeValue(bsoncodec.DecodeContext, bsonrw.ValueReader, interface{}) error {
263-
tdc.DecodeValueCalled = true
264-
return nil
265-
}
266-
267255
type testUnmarshaler struct {
268256
invoked bool
269257
err error

bson/encoder_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,3 @@ func docToBytes(d interface{}) []byte {
133133
}
134134
return b
135135
}
136-
137-
type byteMarshaler []byte
138-
139-
func (bm byteMarshaler) MarshalBSON() ([]byte, error) { return bm, nil }
140-
141-
type _impl struct {
142-
Foo string
143-
}
144-
145-
func (_impl) method() {}

bson/primitive_codecs.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,3 @@ func (PrimitiveCodecs) RawDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.Valu
9090
val.Set(reflect.ValueOf(rdr))
9191
return err
9292
}
93-
94-
func (pc PrimitiveCodecs) encodeRaw(ec bsoncodec.EncodeContext, dw bsonrw.DocumentWriter, raw Raw) error {
95-
var copier bsonrw.Copier
96-
elems, err := raw.Elements()
97-
if err != nil {
98-
return err
99-
}
100-
for _, elem := range elems {
101-
dvw, err := dw.WriteDocumentElement(elem.Key())
102-
if err != nil {
103-
return err
104-
}
105-
106-
val := elem.Value()
107-
err = copier.CopyValueFromBytes(dvw, val.Type, val.Value)
108-
if err != nil {
109-
return err
110-
}
111-
}
112-
113-
return dw.WriteDocumentEnd()
114-
}

0 commit comments

Comments
 (0)