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
222 changes: 125 additions & 97 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
run:
timeout: 5m

version: "2"
linters:
disable-all: true
# TODO(GODRIVER-2156): Enable all commented-out linters.
default: none
enable:
- errcheck
# - errorlint
- exportloopref
- gocritic
- goimports
- gosimple
- gosec
# TODO(GODRIVER-3712): Enable gosec in golangci-lint version 2.6.2
#- gosec
- govet
- ineffassign
- makezero
Expand All @@ -21,95 +15,129 @@ linters:
- prealloc
- revive
- staticcheck
- typecheck
- unused
- unconvert
- unparam
- unused
settings:
errcheck:
exclude-functions:
- .errcheck-excludes
govet:
disable:
- cgocall
- composites
paralleltest:
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of
# `t.Parallel()`.
ignore-missing: true
staticcheck:
checks:
- all
# Disable deprecation warnings for now.
- -SA1012
# Disable "do not pass a nil Context" to allow testing nil contexts in
# tests.
- -SA1019
exclusions:
generated: lax
rules:
# Ignore some linters for example code that is intentionally simplified.
- linters:
- errcheck
- revive
path: examples/
# Disable "unused" linter for code files that depend on the
# "mongocrypt.MongoCrypt" type because the linter build doesn't work
# correctly with CGO enabled. As a result, all calls to a
# "mongocrypt.MongoCrypt" API appear to always panic (see
# mongocrypt_not_enabled.go), leading to confusing messages about unused
# code.
- linters:
- unused
path: x/mongo/driver/crypt.go|mongo/(crypt_retrievers|mongocryptd).go
# Ignore "TLS MinVersion too low", "TLS InsecureSkipVerify set true", and
# "Use of weak random number generator (math/rand instead of crypto/rand)"
# in tests. Disable gosec entirely for test files to reduce noise.
- linters:
- gosec
path: _test\.go
# Ignore missing comments for exported variable/function/type for code in
# the "internal" and "benchmark" directories.
- path: (internal\/|benchmark\/)
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
# Ignore missing package comments for directories that aren't frequently
# used by external users.
- path: (internal\/|benchmark\/|x\/|cmd\/|mongo\/integration\/)
text: should have a package comment

linters-settings:
errcheck:
exclude-functions: .errcheck-excludes
govet:
disable:
- cgocall
- composites
paralleltest:
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of `t.Parallel()`.
ignore-missing: true
staticcheck:
checks: [
"all",
"-SA1019", # Disable deprecation warnings for now.
"-SA1012", # Disable "do not pass a nil Context" to allow testing nil contexts in tests.
]

issues:
exclude-dirs-use-default: false
exclude-dirs:
- (^|/)testdata($|/)
- (^|/)etc($|/)
# Disable all linters for copied third-party code.
- internal/rand
- internal/aws
- internal/assert
exclude-use-default: false
exclude:
# Add all default excluded issues except issues related to exported types/functions not having
# comments; we want those warnings. The defaults are copied from the "--exclude-use-default"
# documentation on https://golangci-lint.run/usage/configuration/#command-line-options
## Defaults ##
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
# EXC0003 golint: False positive when tests are defined in package 'test'
- func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
# EXC0004 govet: Common false positives
- (possible misuse of unsafe.Pointer|should have signature)
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
- ineffective break statement. Did you mean to break out of the outer loop
# EXC0006 gosec: Too many false-positives on 'unsafe' usage
- Use of unsafe calls should be audited
# EXC0007 gosec: Too many false-positives for parametrized shell calls
- Subprocess launch(ed with variable|ing should be audited)
# EXC0008 gosec: Duplicated errcheck checks
- (G104|G307)
# EXC0009 gosec: Too many issues in popular repos
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
- Potential file inclusion via variable
## End Defaults ##
# Add all default excluded issues except issues related to exported
# types/functions not having comments; we want those warnings. The
# defaults are copied from the "--exclude-use-default" documentation on
# https://golangci-lint.run/usage/configuration/#command-line-options
#
## Defaults ##
#
# EXC0001 errcheck: Almost all programs ignore errors on these functions
# and in most cases it's ok
- path: (.+)\.go$
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
# EXC0003 golint: False positive when tests are defined in package 'test'
- path: (.+)\.go$
text: func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
# EXC0004 govet: Common false positives
- path: (.+)\.go$
text: (possible misuse of unsafe.Pointer|should have signature)
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
- path: (.+)\.go$
text: ineffective break statement. Did you mean to break out of the outer loop
# EXC0006 gosec: Too many false-positives on 'unsafe' usage
- path: (.+)\.go$
text: Use of unsafe calls should be audited
# EXC0007 gosec: Too many false-positives for parametrized shell calls
- path: (.+)\.go$
text: Subprocess launch(ed with variable|ing should be audited)
# EXC0008 gosec: Duplicated errcheck checks
- path: (.+)\.go$
text: (G104|G307)
# EXC0009 gosec: Too many issues in popular repos
- path: (.+)\.go$
text: (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
# EXC0010 gosec: False positive is triggered by
# 'src, err := ioutil.ReadFile(filename)'
- path: (.+)\.go$
text: Potential file inclusion via variable
## End Defaults ##

# Ignore capitalization warning for this weird field name.
- "var-naming: struct field CqCssWxW should be CqCSSWxW"
# Ignore warnings for common "wiremessage.Read..." usage because the safest way to use that API
# is by assigning possibly unused returned byte buffers.
- "SA4006: this value of `wm` is never used"
- "SA4006: this value of `rem` is never used"
- "ineffectual assignment to wm"
- "ineffectual assignment to rem"
# Ignore capitalization warning for this weird field name.
- path: (.+)\.go$
text: "var-naming: struct field CqCssWxW should be CqCSSWxW"

exclude-rules:
# Ignore some linters for example code that is intentionally simplified.
- path: examples/
linters:
- revive
- errcheck
# Disable "unused" linter for code files that depend on the "mongocrypt.MongoCrypt" type because
# the linter build doesn't work correctly with CGO enabled. As a result, all calls to a
# "mongocrypt.MongoCrypt" API appear to always panic (see mongocrypt_not_enabled.go), leading
# to confusing messages about unused code.
- path: x/mongo/driver/crypt.go|mongo/(crypt_retrievers|mongocryptd).go
linters:
- unused
# Ignore "TLS MinVersion too low", "TLS InsecureSkipVerify set true", and "Use of weak random
# number generator (math/rand instead of crypto/rand)" in tests.
- path: _test\.go
text: G401|G402|G404
linters:
- gosec
# Ignore missing comments for exported variable/function/type for code in the "internal" and
# "benchmark" directories.
- path: (internal\/|benchmark\/)
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
# Ignore missing package comments for directories that aren't frequently used by external users.
- path: (internal\/|benchmark\/|x\/|cmd\/|mongo\/integration\/)
text: should have a package comment
# Ignore warnings for common "wiremessage.Read..." usage because the
# safest way to use that API is by assigning possibly unused returned byte
# buffers.
- path: (.+)\.go$
text: "SA4006: this value of `wm` is never used"
- path: (.+)\.go$
text: "SA4006: this value of `rem` is never used"
- path: (.+)\.go$
text: ineffectual assignment to wm
- path: (.+)\.go$
text: ineffectual assignment to rem
paths:
- (^|/)testdata($|/)
- (^|/)etc($|/)
# Disable all linters for copied third-party code.
- internal/rand
- internal/aws
- internal/assert
formatters:
enable:
- goimports
exclusions:
generated: lax
paths:
- (^|/)testdata($|/)
- (^|/)etc($|/)
- internal/rand
- internal/aws
- internal/assert
9 changes: 5 additions & 4 deletions bson/map_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (mc *mapCodec) EncodeValue(ec EncodeContext, vw ValueWriter, val reflect.Va
// true if the provided key exists, this is mainly used for inline maps in the
// struct codec.
func (mc *mapCodec) encodeMapElements(ec EncodeContext, dw DocumentWriter, val reflect.Value, collisionFn func(string) bool) error {

elemType := val.Type().Elem()
encoder, err := ec.LookupEncoder(elemType)
if err != nil && elemType.Kind() != reflect.Interface {
Expand Down Expand Up @@ -237,8 +236,10 @@ func (mc *mapCodec) encodeKey(val reflect.Value, encodeKeysWithStringer bool) (s
return "", fmt.Errorf("unsupported key type: %v", val.Type())
}

var keyUnmarshalerType = reflect.TypeOf((*KeyUnmarshaler)(nil)).Elem()
var textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
var (
keyUnmarshalerType = reflect.TypeOf((*KeyUnmarshaler)(nil)).Elem()
textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
)

func (mc *mapCodec) decodeKey(key string, keyType reflect.Type) (reflect.Value, error) {
keyVal := reflect.ValueOf(key)
Expand Down Expand Up @@ -278,7 +279,7 @@ func (mc *mapCodec) decodeKey(key string, keyType reflect.Type) (reflect.Value,
if mc.encodeKeysWithStringer {
parsed, err := strconv.ParseFloat(key, 64)
if err != nil {
return keyVal, fmt.Errorf("Map key is defined to be a decimal type (%v) but got error %w", keyType.Kind(), err)
return keyVal, fmt.Errorf("map key is defined to be a decimal type (%v) but got error %w", keyType.Kind(), err)
}
keyVal = reflect.ValueOf(parsed)
break
Expand Down
2 changes: 1 addition & 1 deletion bson/mgoregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func getterEncodeValue(ec EncodeContext, vw ValueWriter, val reflect.Value) erro
return vw.WriteNull()
}
vv := reflect.ValueOf(x)
encoder, err := ec.Registry.LookupEncoder(vv.Type())
encoder, err := ec.LookupEncoder(vv.Type())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion etc/golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -ex

# Keep this in sync with go version used in static-analysis Evergreen build variant.
GO_VERSION=1.25.0
GOLANGCI_LINT_VERSION=1.60.1
GOLANGCI_LINT_VERSION=2.6.2

# Unset the cross-compiler overrides while downloading binaries.
GOOS_ORIG=${GOOS:-}
Expand Down
2 changes: 1 addition & 1 deletion internal/credproviders/static_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func verify(v credentials.Value) error {
func (s *StaticProvider) Retrieve() (credentials.Value, error) {
if !s.verified {
s.err = verify(s.Value)
s.Value.ProviderName = staticProviderName
s.ProviderName = staticProviderName
s.verified = true
}
return s.Value, s.err
Expand Down
Loading
Loading