Skip to content
Open
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
94 changes: 61 additions & 33 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,77 @@
version: "2"
linters:
disable-all: true
default: none
enable:
- dupword
- errcheck
- gci
- gocheckcompilerdirectives
- godot
- goimports
- ineffassign
- misspell
- nolintlint
- staticcheck
- unconvert
- unparam
- unused
fast: false

linters-settings:
errcheck:
check-type-assertions: true

gci:
sections:
- standard
- default

misspell:
locale: US
extra-words:
- typo: "cancelation"
correction: "cancellation"
- typo: "cancelations"
correction: "cancellations"
- typo: "cancelling"
correction: "canceling"
- typo: "cancelled"
correction: "canceled"
settings:
errcheck:
check-type-assertions: true
misspell:
locale: US
extra-words:
- typo: cancelation
correction: cancellation
- typo: cancelations
correction: cancellations
- typo: cancelling
correction: canceling
- typo: cancelled
correction: canceled
staticcheck:
checks:
# default rules:
- "all"
- "-ST1000"
- "-ST1003"
- "-ST1016"
- "-ST1020"
- "-ST1021"
- "-ST1022"

# custom:
- "-ST1005"
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- staticcheck
path: \.go$
text: is deprecated
- path: (.+)\.go$
text: "composites: .+(primitive.(Binary|Decimal128|E|Timestamp)|types.(Destination|Source)(Client|Database)) struct literal uses unkeyed fields"
paths:
- third_party$
- builtin$
- examples$
issues:
max-same-issues: 0
exclude:
- "composites: .+(primitive.(Binary|Decimal128|E|Timestamp)|types.(Destination|Source)(Client|Database)) struct literal uses unkeyed fields"
# TODO (TOOLS-3633): Remove this exclusion and actually fix the issues.
exclude-rules:
- path: '\.go$'
linters:
- staticcheck
text: "is deprecated"
formatters:
enable:
- gci
- goimports
settings:
gci:
sections:
- standard
- default
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
3 changes: 1 addition & 2 deletions bsondump/bsondump.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"bytes"
"fmt"
"io"
"math"
"os"
"strings"
"time"
Expand Down Expand Up @@ -96,7 +95,7 @@ func New(opts Options) (*BSONDump, error) {

// 16kb + 16mb - This is the maximum size we would get when dumping the
// oplog itself. See https://jira.mongodb.org/browse/TOOLS-3001.
maxBSONSize := (16 * 1024) + (16 * math.Pow(1024, 2))
maxBSONSize := (16 * 1024) + (16 * float64(1024*1024))
dumper.InputSource.SetMaxBSONSize(int32(maxBSONSize))

writer, err := opts.GetWriter()
Expand Down
3 changes: 1 addition & 2 deletions bsondump/bsondump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package bsondump
import (
"bytes"
"crypto/rand"
"math"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -273,7 +272,7 @@ func TestBsondumpMaxBSONSize(t *testing.T) {
testtype.SkipUnlessTestType(t, testtype.UnitTestType)

// 16mb + 16kb
maxSize := int(16*math.Pow(1024, 2)) + sixteenKB
maxSize := int(16*float64(1024*1024)) + sixteenKB

t.Run("bsondump with file at exactly max size of 16mb + 16kb", func(t *testing.T) {
_, err := runBsondumpWithLargeFile(t, maxSize)
Expand Down
7 changes: 4 additions & 3 deletions buildscript/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func CheckMinimumGoVersion(ctx *task.Context) error {
return fmt.Errorf("failed to get current go version: %w", err)
}

_, _ = ctx.Write([]byte(fmt.Sprintf("Found Go version \"%s\"\n", goVersionStr)))
_, _ = fmt.Fprintf(ctx, "Found Go version \"%s\"\n", goVersionStr)

versionPattern := `go(\d+\.\d+\.*\d*)`

Expand Down Expand Up @@ -232,13 +232,14 @@ func getBuildFlags(ctx *task.Context, forTests bool) []string {

pf, err := getPlatform()
if err == nil {
if pf.OS == platform.OSLinux {
switch pf.OS {
case platform.OSLinux:
// We don't want to enable -buildmode=pie for tests. This interferes with enabling the race
// detector.
if !forTests {
flags = append(flags, "-buildmode=pie")
}
} else if pf.OS == platform.OSWindows {
case platform.OSWindows:
flags = append(flags, "-buildmode=exe")
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions buildscript/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ func stopPodmanMachine(ctx *task.Context) error {
var (
// This matches a file that starts with "license" or "licence", in any
// case, with an optional extension.
licenseRegexp1 = regexp.MustCompile("(?i)^licen[cs]e(?:\\..+)?$")
licenseRegexp1 = regexp.MustCompile(`(?i)^licen[cs]e(?:\..+)?$`)
// This matches a file that has an extension of "license" or "licence", in
// any case.
licenseRegexp2 = regexp.MustCompile("(?i)\\.licen[cs]e$")
trailingSpaceRegexp = regexp.MustCompile("(?m)[^\\n\\S]+$")
licenseRegexp2 = regexp.MustCompile(`(?i)\.licen[cs]e$`)
trailingSpaceRegexp = regexp.MustCompile(`(?m)[^\\n\\S]+$`)

horizontalLine = strings.Repeat("-", 70)
)
Expand Down
10 changes: 5 additions & 5 deletions buildscript/sa.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const (
// the new config file syntax did not seem trivial.
eslintVersion = "8.57.0"
gitHubCodeownersVersion = "0.2.1"
golangCILintVersion = "1.64.5"
golangCILintVersion = "2.2.2"
golinesVersion = "0.12.2"
gosecVersion = "2.20.0"
gosecVersion = "2.22.5"
preciousVersion = "0.7.3"
ubiVersion = "0.4.2"
prettierVersion = "3.4.2"
Expand Down Expand Up @@ -408,9 +408,9 @@ func SAEvergreenValidate(ctx *task.Context) error {
// See ticket for more details.
if strings.HasSuffix(output, "is valid with warnings") {
for _, line := range strings.Split(output, "\n") {
if !(strings.HasSuffix(line, "unmarshal errors:") ||
strings.HasSuffix(line, "already set in map") ||
strings.HasSuffix(line, "is valid with warnings")) {
if !strings.HasSuffix(line, "unmarshal errors:") &&
!strings.HasSuffix(line, "already set in map") &&
!strings.HasSuffix(line, "is valid with warnings") {
return fmt.Errorf("error from `evergreen validate`: %s", output)
}
}
Expand Down
5 changes: 2 additions & 3 deletions common/archive/demultiplexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (receiver *RegularCollectionReceiver) Sum64() (uint64, bool) {

// Read() runs in the restoring goroutine.
func (receiver *RegularCollectionReceiver) Read(r []byte) (int, error) {
if receiver.partialReadBuf != nil && len(receiver.partialReadBuf) > 0 {
if len(receiver.partialReadBuf) > 0 {
wLen := len(receiver.partialReadBuf)
copyLen := copy(r, receiver.partialReadBuf)
if wLen == copyLen {
Expand Down Expand Up @@ -552,7 +552,6 @@ func (prioritizer *Prioritizer) Get() *intents.Intent {
}

// Finish is part of the IntentPrioritizer interface, and does nothing.
func (prioritizer *Prioritizer) Finish(*intents.Intent) {
func (*Prioritizer) Finish(*intents.Intent) {
// no-op
return
}
4 changes: 0 additions & 4 deletions common/archive/multiplexer_roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func TestBasicMux(t *testing.T) {
})
})
})
return
}

func TestParallelMux(t *testing.T) {
Expand Down Expand Up @@ -193,7 +192,6 @@ func TestParallelMux(t *testing.T) {
wg.Wait()
So(demuxErr, ShouldBeNil)
})
return
}

func makeIns(
Expand Down Expand Up @@ -386,6 +384,4 @@ func TestTOOLS2403(t *testing.T) {

wg.Wait()
require.NoError(demuxErr)

return
}
1 change: 0 additions & 1 deletion common/archive/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,4 @@ func TestParsing(t *testing.T) {
So(tc.bodies, ShouldBeNil)
})
})
return
}
2 changes: 1 addition & 1 deletion common/archive/prelude.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewPrelude(
prelude.AddMetadata(&CollectionMetadata{
Database: intent.DB,
Collection: intent.C,
Metadata: archiveMetadata.Buffer.String(),
Metadata: archiveMetadata.String(),
Type: intent.Type,
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion common/bsonutil/bsonutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func IsEqual(left, right bson.D) (bool, error) {
return false, err
}

return bytes.Compare(leftBytes, rightBytes) == 0, nil
return bytes.Equal(leftBytes, rightBytes), nil
}

// ConvertLegacyExtJSONDocumentToBSON iterates through the document map and converts JSON
Expand Down
31 changes: 16 additions & 15 deletions common/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func NewSessionProvider(opts options.ToolOptions) (*SessionProvider, error) {
}
err = client.Ping(context.Background(), nil)
if err != nil {
return nil, fmt.Errorf("failed to connect to %s: %v", opts.URI.ParsedConnString(), err)
return nil, fmt.Errorf("failed to connect to %s: %v", opts.ParsedConnString(), err)
}

// create the provider
Expand Down Expand Up @@ -279,7 +279,7 @@ func addCACertsFromFile(cfg *tls.Config, file string) error {
cfg.RootCAs = x509.NewCertPool()
}

if cfg.RootCAs.AppendCertsFromPEM(data) == false {
if !cfg.RootCAs.AppendCertsFromPEM(data) {
return fmt.Errorf(
"SSL trusted server certificates file does not contain any valid certificates. File: `%v`",
file,
Expand Down Expand Up @@ -317,7 +317,7 @@ func AKSCallback(

// configure the client according to the options set in the uri and in the provided ToolOptions, with ToolOptions having precedence.
func configureClient(opts options.ToolOptions) (*mongo.Client, error) {
if opts.URI == nil || opts.URI.ConnectionString == "" {
if opts.URI == nil || opts.ConnectionString == "" {
// XXX Normal operations shouldn't ever reach here because a URI should
// be created in options parsing, but tests still manually construct
// options and generally don't construct a URI, so we invoke the URI
Expand All @@ -328,7 +328,7 @@ func configureClient(opts options.ToolOptions) (*mongo.Client, error) {
}

clientopt := mopt.Client()
cs := opts.URI.ParsedConnString()
cs := opts.ParsedConnString()

clientopt.Hosts = cs.Hosts

Expand All @@ -338,9 +338,9 @@ func configureClient(opts options.ToolOptions) (*mongo.Client, error) {

clientopt.SetConnectTimeout(time.Duration(opts.Timeout) * time.Second)
clientopt.SetSocketTimeout(time.Duration(opts.SocketTimeout) * time.Second)
if opts.Connection.ServerSelectionTimeout > 0 {
if opts.ServerSelectionTimeout > 0 {
clientopt.SetServerSelectionTimeout(
time.Duration(opts.Connection.ServerSelectionTimeout) * time.Second,
time.Duration(opts.ServerSelectionTimeout) * time.Second,
)
}
if opts.ReplicaSetName != "" {
Expand Down Expand Up @@ -453,20 +453,21 @@ func configureClient(opts options.ToolOptions) (*mongo.Client, error) {
clientopt.SetWriteConcern(writeconcern.New(opts...))
}

if opts.Auth != nil && opts.Auth.IsSet() {
if opts.Auth != nil && opts.IsSet() {
cred := mopt.Credential{
Username: opts.Auth.Username,
Password: opts.Auth.Password,
Username: opts.Username,
Password: opts.Password,
AuthSource: opts.GetAuthenticationDatabase(),
AuthMechanism: opts.Auth.Mechanism,
AuthMechanism: opts.Mechanism,
}
if cs.AuthMechanism == "MONGODB-AWS" {
switch cs.AuthMechanism {
case "MONGODB-AWS":
cred.Username = cs.Username
cred.Password = cs.Password
cred.AuthSource = cs.AuthSource
cred.AuthMechanism = cs.AuthMechanism
cred.AuthMechanismProperties = cs.AuthMechanismProperties
} else if cs.AuthMechanism == "MONGODB-OIDC" {
case "MONGODB-OIDC":
if env, ok := cs.AuthMechanismProperties["ENVIRONMENT"]; ok && env == "azure" {
_, okApp := os.LookupEnv("AZURE_APP_CLIENT_ID")
_, okClient := os.LookupEnv("AZURE_IDENTITY_CLIENT_ID")
Expand Down Expand Up @@ -496,8 +497,8 @@ func configureClient(opts options.ToolOptions) (*mongo.Client, error) {
}
if opts.Kerberos != nil && cred.AuthMechanism == "GSSAPI" {
props := make(map[string]string)
if opts.Kerberos.Service != "" {
props["SERVICE_NAME"] = opts.Kerberos.Service
if opts.Service != "" {
props["SERVICE_NAME"] = opts.Service
}
// XXX How do we use opts.Kerberos.ServiceHost if at all?
cred.AuthMechanismProperties = props
Expand All @@ -523,7 +524,7 @@ func configureClient(opts options.ToolOptions) (*mongo.Client, error) {
}

var x509Subject string
keyPasswd := opts.SSL.SSLPEMKeyPassword
keyPasswd := opts.SSLPEMKeyPassword
var err error
if cs.SSLClientCertificateKeyPasswordSet && cs.SSLClientCertificateKeyPassword != nil {
keyPasswd = cs.SSLClientCertificateKeyPassword()
Expand Down
Loading