Skip to content

Commit 807c602

Browse files
authored
chore: bump golangci-lint to v2 (#3082)
* fix: do not use titles in errors * fix: proper variable names * chore: proper usage of require * chore: Fprintf the hasher instead * chore: skip embedded type in method calls * chore: simplify * fix: add staticcheck exclusion * chore: bump golangci-lint to v2 * chore: deprecate Visit errors * fix: lint * chore: sort and remove defaults
1 parent 7907986 commit 807c602

Some content is hidden

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

50 files changed

+250
-234
lines changed

.github/workflows/ci-lint-go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ jobs:
3131
id: go
3232

3333
- name: golangci-lint
34-
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
34+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
3535
with:
3636
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
37-
version: v1.63.4
37+
version: v2.0.2
3838
# Optional: working directory, useful for monorepos
3939
working-directory: ${{ inputs.project-directory }}
4040

.golangci.yml

Lines changed: 76 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,89 @@
1+
formatters:
2+
enable:
3+
- gci
4+
- gofumpt
5+
settings:
6+
gci:
7+
sections:
8+
- standard
9+
- default
10+
- prefix(github.com/testcontainers)
111
linters:
212
enable:
3-
- errcheck
413
- errorlint
5-
- gci
614
- gocritic
7-
- gofumpt
815
- misspell
9-
- nolintlint
1016
- nakedret
17+
- nolintlint
1118
- perfsprint
1219
- revive
1320
- testifylint
1421
- thelper
1522
- usestdlibvars
16-
17-
linters-settings:
18-
errorlint:
19-
# Check whether fmt.Errorf uses the %w verb for formatting errors.
20-
# See the https://github.com/polyfloyd/go-errorlint for caveats.
21-
errorf: true
22-
# Permit more than 1 %w verb, valid per Go 1.20 (Requires errorf:true)
23-
errorf-multi: true
24-
# Check for plain type assertions and type switches.
25-
asserts: true
26-
# Check for plain error comparisons.
27-
comparison: true
28-
gci:
29-
sections:
30-
- standard
31-
- default
32-
- prefix(github.com/testcontainers)
33-
nakedret:
34-
max-func-lines: 0
35-
revive:
36-
rules:
37-
- name: blank-imports
38-
- name: context-as-argument
39-
arguments:
40-
- allowTypesBefore: "*testing.T"
41-
- name: context-keys-type
42-
- name: dot-imports
43-
- name: early-return
44-
arguments:
45-
- "preserveScope"
46-
- name: empty-block
47-
- name: error-naming
48-
disabled: true
49-
- name: error-return
50-
- name: error-strings
51-
disabled: true
52-
- name: errorf
53-
- name: increment-decrement
54-
- name: indent-error-flow
55-
arguments:
56-
- "preserveScope"
57-
- name: range
58-
- name: receiver-naming
59-
- name: redefines-builtin-id
60-
disabled: true
61-
- name: superfluous-else
62-
arguments:
63-
- "preserveScope"
64-
- name: time-naming
65-
- name: unexported-return
66-
disabled: true
67-
- name: unreachable-code
68-
- name: unused-parameter
69-
- name: use-any
70-
- name: var-declaration
71-
- name: var-naming
72-
arguments:
73-
- ["ID"] # AllowList
74-
- ["VM"] # DenyList
75-
- - upperCaseConst: true # Extra parameter (upperCaseConst|skipPackageNameChecks)
76-
testifylint:
77-
disable:
78-
- float-compare
79-
- go-require
80-
enable-all: true
23+
exclusions:
24+
presets:
25+
- comments
26+
- common-false-positives
27+
- legacy
28+
- std-error-handling
29+
settings:
30+
errorlint:
31+
asserts: true
32+
comparison: true
33+
errorf: true
34+
errorf-multi: true
35+
revive:
36+
rules:
37+
- name: blank-imports
38+
- name: context-as-argument
39+
arguments:
40+
- allowTypesBefore: '*testing.T'
41+
- name: context-keys-type
42+
- name: dot-imports
43+
- name: early-return
44+
arguments:
45+
- preserveScope
46+
- name: empty-block
47+
- name: error-naming
48+
disabled: true
49+
- name: error-return
50+
- name: error-strings
51+
disabled: true
52+
- name: errorf
53+
- name: increment-decrement
54+
- name: indent-error-flow
55+
arguments:
56+
- preserveScope
57+
- name: range
58+
- name: receiver-naming
59+
- name: redefines-builtin-id
60+
disabled: true
61+
- name: superfluous-else
62+
arguments:
63+
- preserveScope
64+
- name: time-naming
65+
- name: unexported-return
66+
disabled: true
67+
- name: unreachable-code
68+
- name: unused-parameter
69+
- name: use-any
70+
- name: var-declaration
71+
- name: var-naming
72+
arguments:
73+
- - ID
74+
- - VM
75+
- - upperCaseConst: true
76+
staticcheck:
77+
checks:
78+
- all
79+
testifylint:
80+
disable:
81+
- float-compare
82+
- go-require
83+
enable-all: true
8184
output:
8285
formats:
83-
- format: colored-line-number
84-
path-prefix: "."
85-
run:
86-
timeout: 5m
86+
text:
87+
path: stdout
88+
path-prefix: .
89+
version: "2"

commons-test.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define go_install
66
endef
77

88
$(GOBIN)/golangci-lint:
9-
$(call go_install,github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4)
9+
$(call go_install,github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2)
1010

1111
$(GOBIN)/gotestsum:
1212
$(call go_install,gotest.tools/gotestsum@latest)

container.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -285,37 +285,37 @@ func parseDockerIgnore(targetDir string) (bool, []string, error) {
285285

286286
// GetBuildArgs returns the env args to be used when creating from Dockerfile
287287
func (c *ContainerRequest) GetBuildArgs() map[string]*string {
288-
return c.FromDockerfile.BuildArgs
288+
return c.BuildArgs
289289
}
290290

291291
// GetDockerfile returns the Dockerfile from the ContainerRequest, defaults to "Dockerfile".
292292
// Sets FromDockerfile.Dockerfile to the default if blank.
293293
func (c *ContainerRequest) GetDockerfile() string {
294-
if c.FromDockerfile.Dockerfile == "" {
295-
c.FromDockerfile.Dockerfile = "Dockerfile"
294+
if c.Dockerfile == "" {
295+
c.Dockerfile = "Dockerfile"
296296
}
297297

298-
return c.FromDockerfile.Dockerfile
298+
return c.Dockerfile
299299
}
300300

301301
// GetRepo returns the Repo label for image from the ContainerRequest, defaults to UUID.
302302
// Sets FromDockerfile.Repo to the default value if blank.
303303
func (c *ContainerRequest) GetRepo() string {
304-
if c.FromDockerfile.Repo == "" {
305-
c.FromDockerfile.Repo = uuid.NewString()
304+
if c.Repo == "" {
305+
c.Repo = uuid.NewString()
306306
}
307307

308-
return strings.ToLower(c.FromDockerfile.Repo)
308+
return strings.ToLower(c.Repo)
309309
}
310310

311311
// GetTag returns the Tag label for image from the ContainerRequest, defaults to UUID.
312312
// Sets FromDockerfile.Tag to the default value if blank.
313313
func (c *ContainerRequest) GetTag() string {
314-
if c.FromDockerfile.Tag == "" {
315-
c.FromDockerfile.Tag = uuid.NewString()
314+
if c.Tag == "" {
315+
c.Tag = uuid.NewString()
316316
}
317317

318-
return strings.ToLower(c.FromDockerfile.Tag)
318+
return strings.ToLower(c.Tag)
319319
}
320320

321321
// Deprecated: Testcontainers will detect registry credentials automatically, and it will be removed in the next major release.
@@ -343,13 +343,13 @@ func (c *ContainerRequest) dockerFileImages() ([]string, error) {
343343

344344
// Source is an archive, we need to read it to get the Dockerfile.
345345
dockerFile := c.GetDockerfile()
346-
tr := tar.NewReader(c.FromDockerfile.ContextArchive)
346+
tr := tar.NewReader(c.ContextArchive)
347347

348348
for {
349349
hdr, err := tr.Next()
350350
if err != nil {
351351
if errors.Is(err, io.EOF) {
352-
return nil, fmt.Errorf("Dockerfile %q not found in context archive", dockerFile)
352+
return nil, fmt.Errorf("dockerfile %q not found in context archive", dockerFile)
353353
}
354354

355355
return nil, fmt.Errorf("reading tar archive: %w", err)
@@ -405,22 +405,24 @@ func getAuthConfigsFromDockerfile(c *ContainerRequest) (map[string]registry.Auth
405405
}
406406

407407
func (c *ContainerRequest) ShouldBuildImage() bool {
408-
return c.FromDockerfile.Context != "" || c.FromDockerfile.ContextArchive != nil
408+
return c.Context != "" || c.ContextArchive != nil
409409
}
410410

411411
func (c *ContainerRequest) ShouldKeepBuiltImage() bool {
412-
return c.FromDockerfile.KeepImage
412+
return c.KeepImage
413413
}
414414

415415
// BuildLogWriter returns the io.Writer for output of log when building a Docker image from
416416
// a Dockerfile. It returns the BuildLogWriter from the ContainerRequest, defaults to io.Discard.
417417
// For backward compatibility, if BuildLogWriter is default and PrintBuildLog is true,
418418
// the function returns os.Stderr.
419+
//
420+
//nolint:staticcheck //FIXME
419421
func (c *ContainerRequest) BuildLogWriter() io.Writer {
420422
if c.FromDockerfile.BuildLogWriter != nil {
421423
return c.FromDockerfile.BuildLogWriter
422424
}
423-
if c.FromDockerfile.PrintBuildLog {
425+
if c.PrintBuildLog {
424426
c.FromDockerfile.BuildLogWriter = os.Stderr
425427
} else {
426428
c.FromDockerfile.BuildLogWriter = io.Discard
@@ -437,8 +439,8 @@ func (c *ContainerRequest) BuildOptions() (types.ImageBuildOptions, error) {
437439
ForceRemove: true,
438440
}
439441

440-
if c.FromDockerfile.BuildOptionsModifier != nil {
441-
c.FromDockerfile.BuildOptionsModifier(&buildOptions)
442+
if c.BuildOptionsModifier != nil {
443+
c.BuildOptionsModifier(&buildOptions)
442444
}
443445

444446
// apply mandatory values after the modifier
@@ -505,15 +507,15 @@ func (c *ContainerRequest) BuildOptions() (types.ImageBuildOptions, error) {
505507
}
506508

507509
func (c *ContainerRequest) validateContextAndImage() error {
508-
if c.FromDockerfile.Context != "" && c.Image != "" {
510+
if c.Context != "" && c.Image != "" {
509511
return errors.New("you cannot specify both an Image and Context in a ContainerRequest")
510512
}
511513

512514
return nil
513515
}
514516

515517
func (c *ContainerRequest) validateContextOrImageIsSpecified() error {
516-
if c.FromDockerfile.Context == "" && c.FromDockerfile.ContextArchive == nil && c.Image == "" {
518+
if c.Context == "" && c.ContextArchive == nil && c.Image == "" {
517519
return errors.New("you must specify either a build context or an image")
518520
}
519521

docker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (c *DockerContainer) MappedPort(ctx context.Context, port nat.Port) (nat.Po
186186
if err != nil {
187187
return "", fmt.Errorf("inspect: %w", err)
188188
}
189-
if inspect.ContainerJSONBase.HostConfig.NetworkMode == "host" {
189+
if inspect.HostConfig.NetworkMode == "host" {
190190
return port, nil
191191
}
192192

@@ -1619,7 +1619,7 @@ func (p *DockerProvider) getGatewayIP(ctx context.Context, defaultNetwork string
16191619
}
16201620
}
16211621
if ip == "" {
1622-
return "", errors.New("Failed to get gateway IP from network settings")
1622+
return "", errors.New("failed to get gateway IP from network settings")
16231623
}
16241624

16251625
return ip, nil

docker_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (c *DockerClient) Info(ctx context.Context) (system.Info, error) {
7676

7777
log.Printf(infoMessage, packagePath,
7878
dockerInfo.ServerVersion,
79-
c.Client.ClientVersion(),
79+
c.ClientVersion(),
8080
dockerInfo.OperatingSystem, dockerInfo.MemTotal/1024/1024,
8181
infoLabels,
8282
internal.Version,

docs/features/wait/walk.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ removing specific strategies based on requirements of functional options.
88
For example removing a TLS strategy if a functional option enabled insecure mode
99
or changing the location of the certificate based on the configured user.
1010

11-
If visit function returns `wait.VisitStop`, the walk stops.
12-
If visit function returns `wait.VisitRemove`, the current node is removed.
11+
If visit function returns `wait.ErrVisitStop`, the walk stops.
12+
If visit function returns `wait.ErrVisitRemove`, the current node is removed.
1313

1414
## Walk removing entries
1515

internal/core/bootstrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func init() {
8484
}
8585

8686
hasher := sha256.New()
87-
_, err = hasher.Write([]byte(fmt.Sprintf(sessionIDPlaceholder, parentPid, createTime)))
87+
_, err = fmt.Fprintf(hasher, sessionIDPlaceholder, parentPid, createTime)
8888
if err != nil {
8989
sessionID = uuid.New().String()
9090
return

internal/core/docker_host_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestExtractDockerHost(t *testing.T) {
104104

105105
host, err := extractDockerHost(context.Background())
106106
require.Error(t, err)
107-
require.Equal(t, "", host)
107+
require.Empty(t, host)
108108
})
109109

110110
t.Run("Docker Host as environment variable", func(t *testing.T) {
@@ -122,7 +122,7 @@ func TestExtractDockerHost(t *testing.T) {
122122

123123
host, err := extractDockerHost(context.WithValue(ctx, DockerHostContextKey, "path-to-docker-sock"))
124124
require.Error(t, err)
125-
require.Equal(t, "", host)
125+
require.Empty(t, host)
126126
})
127127

128128
t.Run("Malformed Schema Docker Host is passed in context", func(t *testing.T) {
@@ -132,7 +132,7 @@ func TestExtractDockerHost(t *testing.T) {
132132

133133
host, err := extractDockerHost(context.WithValue(ctx, DockerHostContextKey, "http://path to docker sock"))
134134
require.Error(t, err)
135-
require.Equal(t, "", host)
135+
require.Empty(t, host)
136136
})
137137

138138
t.Run("Unix Docker Host is passed in context", func(t *testing.T) {
@@ -169,7 +169,7 @@ func TestExtractDockerHost(t *testing.T) {
169169
setupRootlessNotFound(t)
170170
host, err := extractDockerHost(context.Background())
171171
require.Error(t, err)
172-
require.Equal(t, "", host)
172+
require.Empty(t, host)
173173
})
174174

175175
t.Run("Extract Docker socket", func(t *testing.T) {

0 commit comments

Comments
 (0)