Skip to content

Commit 4f0bcf8

Browse files
authored
chore: enable early-return, indent-error-flow and superfluous-else from revive linter (#2947)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 8b5211f commit 4f0bcf8

File tree

7 files changed

+56
-19
lines changed

7 files changed

+56
-19
lines changed

.golangci.yml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ linters:
99
- nolintlint
1010
- nakedret
1111
- perfsprint
12+
- revive
1213
- testifylint
1314
- thelper
1415
- usestdlibvars
1516

1617
linters-settings:
17-
nakedret:
18-
max-func-lines: 0
1918
errorlint:
2019
# Check whether fmt.Errorf uses the %w verb for formatting errors.
2120
# See the https://github.com/polyfloyd/go-errorlint for caveats.
@@ -31,6 +30,52 @@ linters-settings:
3130
- standard
3231
- default
3332
- prefix(github.com/testcontainers)
33+
nakedret:
34+
max-func-lines: 0
35+
revive:
36+
min-confidence: 0.8
37+
rules:
38+
- name: blank-imports
39+
- name: context-as-argument
40+
disabled: true
41+
arguments:
42+
- allowTypesBefore: "*testing.T"
43+
- name: context-keys-type
44+
- name: dot-imports
45+
- name: early-return
46+
arguments:
47+
- "preserveScope"
48+
- name: empty-block
49+
disabled: true
50+
- name: error-naming
51+
disabled: true
52+
- name: error-return
53+
- name: error-strings
54+
disabled: true
55+
- name: errorf
56+
- name: increment-decrement
57+
- name: indent-error-flow
58+
arguments:
59+
- "preserveScope"
60+
- name: range
61+
- name: receiver-naming
62+
- name: redefines-builtin-id
63+
disabled: true
64+
- name: superfluous-else
65+
arguments:
66+
- "preserveScope"
67+
- name: time-naming
68+
- name: unexported-return
69+
disabled: true
70+
- name: unreachable-code
71+
- name: unused-parameter
72+
disabled: true
73+
- name: use-any
74+
disabled: true
75+
- name: var-declaration
76+
disabled: true
77+
- name: var-naming
78+
disabled: true
3479
testifylint:
3580
disable:
3681
- float-compare

container.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,8 @@ func (c *ContainerRequest) validateMounts() error {
529529
targetPath := m.Target.Target()
530530
if targets[targetPath] {
531531
return fmt.Errorf("%w: %s", ErrDuplicateMountTarget, targetPath)
532-
} else {
533-
targets[targetPath] = true
534532
}
533+
targets[targetPath] = true
535534
}
536535

537536
if c.HostConfigModifier == nil {
@@ -551,9 +550,8 @@ func (c *ContainerRequest) validateMounts() error {
551550
targetPath := parts[1]
552551
if targets[targetPath] {
553552
return fmt.Errorf("%w: %s", ErrDuplicateMountTarget, targetPath)
554-
} else {
555-
targets[targetPath] = true
556553
}
554+
targets[targetPath] = true
557555
}
558556
}
559557

docker.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,10 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
11201120
} else {
11211121
img, _, err := p.client.ImageInspectWithRaw(ctx, imageName)
11221122
if err != nil {
1123-
if client.IsErrNotFound(err) {
1124-
shouldPullImage = true
1125-
} else {
1123+
if !client.IsErrNotFound(err) {
11261124
return nil, err
11271125
}
1126+
shouldPullImage = true
11281127
}
11291128
if platform != nil && (img.Architecture != platform.Architecture || img.Os != platform.OS) {
11301129
shouldPullImage = true

internal/core/docker_rootless.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,9 @@ func fileExists(f string) bool {
7979
}
8080

8181
func parseURL(s string) (string, error) {
82-
var hostURL *url.URL
83-
if u, err := url.Parse(s); err != nil {
82+
hostURL, err := url.Parse(s)
83+
if err != nil {
8484
return "", err
85-
} else {
86-
hostURL = u
8785
}
8886

8987
switch hostURL.Scheme {

modules/compose/compose_api.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,8 @@ func withEnv(env map[string]string) func(*cli.ProjectOptions) error {
592592
for k, v := range env {
593593
if _, ok := options.Environment[k]; ok {
594594
return fmt.Errorf("environment with key %s already set", k)
595-
} else {
596-
options.Environment[k] = v
597595
}
596+
options.Environment[k] = v
598597
}
599598

600599
return nil

modules/registry/registry.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,8 @@ func (c *RegistryContainer) PushImage(ctx context.Context, ref string) error {
194194
encodedJSON, err := json.Marshal(imageAuth)
195195
if err != nil {
196196
return fmt.Errorf("failed to encode image auth: %w", err)
197-
} else {
198-
pushOpts.RegistryAuth = base64.URLEncoding.EncodeToString(encodedJSON)
199197
}
198+
pushOpts.RegistryAuth = base64.URLEncoding.EncodeToString(encodedJSON)
200199

201200
_, err = dockerCli.ImagePush(ctx, ref, pushOpts)
202201
if err != nil {

wait/exit.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ func (ws *ExitStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge
7676
if err != nil {
7777
if !strings.Contains(err.Error(), "No such container") {
7878
return err
79-
} else {
80-
return nil
8179
}
80+
return nil
8281
}
8382
if state.Running {
8483
time.Sleep(ws.PollInterval)

0 commit comments

Comments
 (0)