Skip to content

Commit

Permalink
GODRIVER-2156 Enable prealloc linter. (mongodb#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdale authored Nov 30, 2021
1 parent c610988 commit 28b03a4
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linters:
- makezero
# - misspell
- nakedret
- prealloc
- revive
- staticcheck
- structcheck
Expand Down
2 changes: 1 addition & 1 deletion internal/string_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func StringSliceFromRawValue(name string, val bson.RawValue) ([]string, error) {
return nil, err
}

var strs []string
strs := make([]string, 0, len(arrayValues))
for _, arrayVal := range arrayValues {
str, ok := arrayVal.StringValueOK()
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// AutoCreateIndexes creates an index in the test cluster.
func AutoCreateIndexes(t *testing.T, keys []string) {
var elems [][]byte
elems := make([][]byte, 0, len(keys))
for _, k := range keys {
elems = append(elems, bsoncore.AppendInt32Element(nil, k, 1))
}
Expand Down
8 changes: 4 additions & 4 deletions mongo/integration/gridfs_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func arrangeGridfsCollections(mt *mtest.T, arrange gridfsArrange) {
return
}

var arrangeCmds []interface{}
arrangeCmds := make([]interface{}, 0, len(arrange.Data))
for _, cmd := range arrange.Data {
if cmd[0].Key != "update" {
arrangeCmds = append(arrangeCmds, cmd)
Expand Down Expand Up @@ -230,7 +230,7 @@ func arrangeGridfsCollections(mt *mtest.T, arrange gridfsArrange) {
func executeUploadAssert(mt *mtest.T, fileID primitive.ObjectID, assert gridfsAssert) {
fileIDVal := bsonx.ObjectID(fileID)

var assertCommands []interface{}
assertCommands := make([]interface{}, 0, len(assert.Data))
for _, data := range assert.Data {
documentsIdx := data.IndexOf("documents")
if documentsIdx == -1 {
Expand Down Expand Up @@ -412,7 +412,7 @@ func executeGridfsDelete(mt *mtest.T, test gridfsTest, bucket *gridfs.Bucket) {
compareGridfsAssertError(mt, test.Assert.Error, err)
return
}
var cmds []interface{}
cmds := make([]interface{}, 0, len(test.Assert.Data))
for _, cmd := range test.Assert.Data {
cmds = append(cmds, cmd)
}
Expand All @@ -432,7 +432,7 @@ func setupGridfsTest(mt *mtest.T, data gridfsData) int32 {
break
}
}
var chunksDocs []interface{}
chunksDocs := make([]interface{}, 0, len(data.Chunks))
for _, chunk := range data.Chunks {
if hexStr, err := chunk.LookupErr("data", "$hex"); err == nil {
hexBytes := hexStringToBytes(mt, hexStr.StringValue())
Expand Down
2 changes: 1 addition & 1 deletion mongo/integration/mtest/mongotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ func (t *T) verifyConstraints() error {

// Stop once we find a RunOnBlock that matches the current environment. Record all errors as we go because if we
// don't find any matching blocks, we want to report the comparison errors for each block.
var runOnErrors []error
runOnErrors := make([]error, 0, len(t.runOn))
for _, runOn := range t.runOn {
err := verifyRunOnBlockConstraint(runOn)
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion x/mongo/driver/auth/internal/awsv4/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (ctx *signingCtx) buildCredentialString() {
}

func (ctx *signingCtx) buildCanonicalHeaders(r rule, header http.Header) {
var headers []string
headers := make([]string, 0, len(header))
headers = append(headers, "host")
for k, v := range header {
if !r.IsValid(k) {
Expand Down
2 changes: 1 addition & 1 deletion x/mongo/driver/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *Resolver) fetchSeedlistFromSRV(host string, srvName string, stopOnErr b

trimmedHost := strings.TrimSuffix(host, ".")

var parsedHosts []string
parsedHosts := make([]string, 0, len(addresses))
for _, address := range addresses {
trimmedAddressTarget := strings.TrimSuffix(address.Target, ".")
err := validateSRVResult(trimmedAddressTarget, trimmedHost)
Expand Down

0 comments on commit 28b03a4

Please sign in to comment.