Skip to content

Commit a34c432

Browse files
Migrate v2 config and apply linter --fix
1 parent 3913452 commit a34c432

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+285
-185
lines changed

.golangci.bck.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
run:
2+
timeout: 5m
3+
4+
linters:
5+
disable-all: true
6+
# TODO(GODRIVER-2156): Enable all commented-out linters.
7+
enable:
8+
- errcheck
9+
# - errorlint
10+
- exportloopref
11+
- gocritic
12+
- goimports
13+
- gosimple
14+
- gosec
15+
- govet
16+
- ineffassign
17+
- makezero
18+
- misspell
19+
- nakedret
20+
- paralleltest
21+
- prealloc
22+
- revive
23+
- staticcheck
24+
- typecheck
25+
- unused
26+
- unconvert
27+
- unparam
28+
29+
linters-settings:
30+
errcheck:
31+
exclude-functions: .errcheck-excludes
32+
govet:
33+
disable:
34+
- cgocall
35+
- composites
36+
paralleltest:
37+
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of `t.Parallel()`.
38+
ignore-missing: true
39+
staticcheck:
40+
checks: [
41+
"all",
42+
"-SA1019", # Disable deprecation warnings for now.
43+
"-SA1012", # Disable "do not pass a nil Context" to allow testing nil contexts in tests.
44+
]
45+
46+
issues:
47+
exclude-dirs-use-default: false
48+
exclude-dirs:
49+
- (^|/)testdata($|/)
50+
- (^|/)etc($|/)
51+
# Disable all linters for copied third-party code.
52+
- internal/rand
53+
- internal/aws
54+
- internal/assert
55+
exclude-use-default: false
56+
exclude:
57+
# Add all default excluded issues except issues related to exported types/functions not having
58+
# comments; we want those warnings. The defaults are copied from the "--exclude-use-default"
59+
# documentation on https://golangci-lint.run/usage/configuration/#command-line-options
60+
## Defaults ##
61+
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
62+
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
63+
# EXC0003 golint: False positive when tests are defined in package 'test'
64+
- func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
65+
# EXC0004 govet: Common false positives
66+
- (possible misuse of unsafe.Pointer|should have signature)
67+
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
68+
- ineffective break statement. Did you mean to break out of the outer loop
69+
# EXC0006 gosec: Too many false-positives on 'unsafe' usage
70+
- Use of unsafe calls should be audited
71+
# EXC0007 gosec: Too many false-positives for parametrized shell calls
72+
- Subprocess launch(ed with variable|ing should be audited)
73+
# EXC0008 gosec: Duplicated errcheck checks
74+
- (G104|G307)
75+
# EXC0009 gosec: Too many issues in popular repos
76+
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
77+
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
78+
- Potential file inclusion via variable
79+
## End Defaults ##
80+
81+
# Ignore capitalization warning for this weird field name.
82+
- "var-naming: struct field CqCssWxW should be CqCSSWxW"
83+
# Ignore warnings for common "wiremessage.Read..." usage because the safest way to use that API
84+
# is by assigning possibly unused returned byte buffers.
85+
- "SA4006: this value of `wm` is never used"
86+
- "SA4006: this value of `rem` is never used"
87+
- "ineffectual assignment to wm"
88+
- "ineffectual assignment to rem"
89+
90+
exclude-rules:
91+
# Ignore some linters for example code that is intentionally simplified.
92+
- path: examples/
93+
linters:
94+
- revive
95+
- errcheck
96+
# Disable "unused" linter for code files that depend on the "mongocrypt.MongoCrypt" type because
97+
# the linter build doesn't work correctly with CGO enabled. As a result, all calls to a
98+
# "mongocrypt.MongoCrypt" API appear to always panic (see mongocrypt_not_enabled.go), leading
99+
# to confusing messages about unused code.
100+
- path: x/mongo/driver/crypt.go|mongo/(crypt_retrievers|mongocryptd).go
101+
linters:
102+
- unused
103+
# Ignore "TLS MinVersion too low", "TLS InsecureSkipVerify set true", and "Use of weak random
104+
# number generator (math/rand instead of crypto/rand)" in tests.
105+
- path: _test\.go
106+
text: G401|G402|G404
107+
linters:
108+
- gosec
109+
# Ignore missing comments for exported variable/function/type for code in the "internal" and
110+
# "benchmark" directories.
111+
- path: (internal\/|benchmark\/)
112+
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
113+
# Ignore missing package comments for directories that aren't frequently used by external users.
114+
- path: (internal\/|benchmark\/|x\/|cmd\/|mongo\/integration\/)
115+
text: should have a package comment

.golangci.yml

Lines changed: 124 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
run:
2-
timeout: 5m
3-
1+
version: "2"
42
linters:
5-
disable-all: true
6-
# TODO(GODRIVER-2156): Enable all commented-out linters.
3+
default: none
74
enable:
85
- errcheck
9-
# - errorlint
10-
- exportloopref
116
- gocritic
12-
- goimports
13-
- gosimple
147
- gosec
158
- govet
169
- ineffassign
@@ -21,95 +14,130 @@ linters:
2114
- prealloc
2215
- revive
2316
- staticcheck
24-
- typecheck
25-
- unused
2617
- unconvert
2718
- unparam
19+
- unused
20+
settings:
21+
errcheck:
22+
exclude-functions:
23+
- .errcheck-excludes
24+
govet:
25+
disable:
26+
- cgocall
27+
- composites
28+
paralleltest:
29+
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of
30+
# `t.Parallel()`.
31+
ignore-missing: true
32+
staticcheck:
33+
checks:
34+
- all
35+
# Disable deprecation warnings for now.
36+
- -SA1012
37+
# Disable "do not pass a nil Context" to allow testing nil contexts in
38+
# tests.
39+
- -SA1019
40+
exclusions:
41+
generated: lax
42+
rules:
43+
# Ignore some linters for example code that is intentionally simplified.
44+
- linters:
45+
- errcheck
46+
- revive
47+
path: examples/
48+
# Disable "unused" linter for code files that depend on the
49+
# "mongocrypt.MongoCrypt" type because the linter build doesn't work
50+
# correctly with CGO enabled. As a result, all calls to a
51+
# "mongocrypt.MongoCrypt" API appear to always panic (see
52+
# mongocrypt_not_enabled.go), leading to confusing messages about unused
53+
# code.
54+
- linters:
55+
- unused
56+
path: x/mongo/driver/crypt.go|mongo/(crypt_retrievers|mongocryptd).go
57+
# Ignore "TLS MinVersion too low", "TLS InsecureSkipVerify set true", and
58+
# "Use of weak random number generator (math/rand instead of crypto/rand)"
59+
# in tests.
60+
- linters:
61+
- gosec
62+
path: _test\.go
63+
text: G401|G402|G404
64+
# Ignore missing comments for exported variable/function/type for code in
65+
# the "internal" and "benchmark" directories.
66+
- path: (internal\/|benchmark\/)
67+
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
68+
# Ignore missing package comments for directories that aren't frequently
69+
# used by external users.
70+
- path: (internal\/|benchmark\/|x\/|cmd\/|mongo\/integration\/)
71+
text: should have a package comment
2872

29-
linters-settings:
30-
errcheck:
31-
exclude-functions: .errcheck-excludes
32-
govet:
33-
disable:
34-
- cgocall
35-
- composites
36-
paralleltest:
37-
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of `t.Parallel()`.
38-
ignore-missing: true
39-
staticcheck:
40-
checks: [
41-
"all",
42-
"-SA1019", # Disable deprecation warnings for now.
43-
"-SA1012", # Disable "do not pass a nil Context" to allow testing nil contexts in tests.
44-
]
45-
46-
issues:
47-
exclude-dirs-use-default: false
48-
exclude-dirs:
49-
- (^|/)testdata($|/)
50-
- (^|/)etc($|/)
51-
# Disable all linters for copied third-party code.
52-
- internal/rand
53-
- internal/aws
54-
- internal/assert
55-
exclude-use-default: false
56-
exclude:
57-
# Add all default excluded issues except issues related to exported types/functions not having
58-
# comments; we want those warnings. The defaults are copied from the "--exclude-use-default"
59-
# documentation on https://golangci-lint.run/usage/configuration/#command-line-options
60-
## Defaults ##
61-
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
62-
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
63-
# EXC0003 golint: False positive when tests are defined in package 'test'
64-
- func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
65-
# EXC0004 govet: Common false positives
66-
- (possible misuse of unsafe.Pointer|should have signature)
67-
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
68-
- ineffective break statement. Did you mean to break out of the outer loop
69-
# EXC0006 gosec: Too many false-positives on 'unsafe' usage
70-
- Use of unsafe calls should be audited
71-
# EXC0007 gosec: Too many false-positives for parametrized shell calls
72-
- Subprocess launch(ed with variable|ing should be audited)
73-
# EXC0008 gosec: Duplicated errcheck checks
74-
- (G104|G307)
75-
# EXC0009 gosec: Too many issues in popular repos
76-
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
77-
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
78-
- Potential file inclusion via variable
79-
## End Defaults ##
73+
# Add all default excluded issues except issues related to exported
74+
# types/functions not having comments; we want those warnings. The
75+
# defaults are copied from the "--exclude-use-default" documentation on
76+
# https://golangci-lint.run/usage/configuration/#command-line-options
77+
#
78+
## Defaults ##
79+
#
80+
# EXC0001 errcheck: Almost all programs ignore errors on these functions
81+
# and in most cases it's ok
82+
- path: (.+)\.go$
83+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
84+
# EXC0003 golint: False positive when tests are defined in package 'test'
85+
- path: (.+)\.go$
86+
text: func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
87+
# EXC0004 govet: Common false positives
88+
- path: (.+)\.go$
89+
text: (possible misuse of unsafe.Pointer|should have signature)
90+
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
91+
- path: (.+)\.go$
92+
text: ineffective break statement. Did you mean to break out of the outer loop
93+
# EXC0006 gosec: Too many false-positives on 'unsafe' usage
94+
- path: (.+)\.go$
95+
text: Use of unsafe calls should be audited
96+
# EXC0007 gosec: Too many false-positives for parametrized shell calls
97+
- path: (.+)\.go$
98+
text: Subprocess launch(ed with variable|ing should be audited)
99+
# EXC0008 gosec: Duplicated errcheck checks
100+
- path: (.+)\.go$
101+
text: (G104|G307)
102+
# EXC0009 gosec: Too many issues in popular repos
103+
- path: (.+)\.go$
104+
text: (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
105+
# EXC0010 gosec: False positive is triggered by
106+
# 'src, err := ioutil.ReadFile(filename)'
107+
- path: (.+)\.go$
108+
text: Potential file inclusion via variable
109+
## End Defaults ##
80110

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

90-
exclude-rules:
91-
# Ignore some linters for example code that is intentionally simplified.
92-
- path: examples/
93-
linters:
94-
- revive
95-
- errcheck
96-
# Disable "unused" linter for code files that depend on the "mongocrypt.MongoCrypt" type because
97-
# the linter build doesn't work correctly with CGO enabled. As a result, all calls to a
98-
# "mongocrypt.MongoCrypt" API appear to always panic (see mongocrypt_not_enabled.go), leading
99-
# to confusing messages about unused code.
100-
- path: x/mongo/driver/crypt.go|mongo/(crypt_retrievers|mongocryptd).go
101-
linters:
102-
- unused
103-
# Ignore "TLS MinVersion too low", "TLS InsecureSkipVerify set true", and "Use of weak random
104-
# number generator (math/rand instead of crypto/rand)" in tests.
105-
- path: _test\.go
106-
text: G401|G402|G404
107-
linters:
108-
- gosec
109-
# Ignore missing comments for exported variable/function/type for code in the "internal" and
110-
# "benchmark" directories.
111-
- path: (internal\/|benchmark\/)
112-
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
113-
# Ignore missing package comments for directories that aren't frequently used by external users.
114-
- path: (internal\/|benchmark\/|x\/|cmd\/|mongo\/integration\/)
115-
text: should have a package comment
115+
# Ignore warnings for common "wiremessage.Read..." usage because the
116+
# safest way to use that API is by assigning possibly unused returned byte
117+
# buffers.
118+
- path: (.+)\.go$
119+
text: "SA4006: this value of `wm` is never used"
120+
- path: (.+)\.go$
121+
text: "SA4006: this value of `rem` is never used"
122+
- path: (.+)\.go$
123+
text: ineffectual assignment to wm
124+
- path: (.+)\.go$
125+
text: ineffectual assignment to rem
126+
paths:
127+
- (^|/)testdata($|/)
128+
- (^|/)etc($|/)
129+
# Disable all linters for copied third-party code.
130+
- internal/rand
131+
- internal/aws
132+
- internal/assert
133+
formatters:
134+
enable:
135+
- goimports
136+
exclusions:
137+
generated: lax
138+
paths:
139+
- (^|/)testdata($|/)
140+
- (^|/)etc($|/)
141+
- internal/rand
142+
- internal/aws
143+
- internal/assert

bson/mgoregistry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func getterEncodeValue(ec EncodeContext, vw ValueWriter, val reflect.Value) erro
201201
return vw.WriteNull()
202202
}
203203
vv := reflect.ValueOf(x)
204-
encoder, err := ec.Registry.LookupEncoder(vv.Type())
204+
encoder, err := ec.LookupEncoder(vv.Type())
205205
if err != nil {
206206
return err
207207
}

etc/golangci-lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -ex
33

44
# Keep this in sync with go version used in static-analysis Evergreen build variant.
55
GO_VERSION=1.23.0
6-
GOLANGCI_LINT_VERSION=1.60.1
6+
GOLANGCI_LINT_VERSION=2.6.2
77

88
# Unset the cross-compiler overrides while downloading binaries.
99
GOOS_ORIG=${GOOS:-}

internal/credproviders/static_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func verify(v credentials.Value) error {
4545
func (s *StaticProvider) Retrieve() (credentials.Value, error) {
4646
if !s.verified {
4747
s.err = verify(s.Value)
48-
s.Value.ProviderName = staticProviderName
48+
s.ProviderName = staticProviderName
4949
s.verified = true
5050
}
5151
return s.Value, s.err

internal/errutil/join_go1.19.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66

77
//go:build !go1.20
8-
// +build !go1.20
98

109
package errutil
1110

internal/errutil/join_go1.20.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66

77
//go:build go1.20
8-
// +build go1.20
98

109
package errutil
1110

0 commit comments

Comments
 (0)