Skip to content

Commit

Permalink
chore: enable early-return, indent-error-flow and superfluous-else fr…
Browse files Browse the repository at this point in the history
…om revive linter

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 committed Jan 24, 2025
1 parent 8b5211f commit fe64cdf
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 17 deletions.
49 changes: 47 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ linters:
- nolintlint
- nakedret
- perfsprint
- revive
- testifylint
- thelper
- usestdlibvars

linters-settings:
nakedret:
max-func-lines: 0
errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors.
# See the https://github.com/polyfloyd/go-errorlint for caveats.
Expand All @@ -31,6 +30,52 @@ linters-settings:
- standard
- default
- prefix(github.com/testcontainers)
nakedret:
max-func-lines: 0
revive:
min-confidence: 0.8
rules:
- name: blank-imports
- name: context-as-argument
disabled: true
arguments:
- allowTypesBefore: "*testing.T"
- name: context-keys-type
- name: dot-imports
- name: early-return
arguments:
- "preserveScope"
- name: empty-block
disabled: true
- name: error-naming
disabled: true
- name: error-return
- name: error-strings
disabled: true
- name: errorf
- name: increment-decrement
- name: indent-error-flow
arguments:
- "preserveScope"
- name: range
- name: receiver-naming
- name: redefines-builtin-id
disabled: true
- name: superfluous-else
arguments:
- "preserveScope"
- name: time-naming
- name: unexported-return
disabled: true
- name: unreachable-code
- name: unused-parameter
disabled: true
- name: use-any
disabled: true
- name: var-declaration
disabled: true
- name: var-naming
disabled: true
testifylint:
disable:
- float-compare
Expand Down
6 changes: 2 additions & 4 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,8 @@ func (c *ContainerRequest) validateMounts() error {
targetPath := m.Target.Target()
if targets[targetPath] {
return fmt.Errorf("%w: %s", ErrDuplicateMountTarget, targetPath)
} else {
targets[targetPath] = true
}
targets[targetPath] = true
}

if c.HostConfigModifier == nil {
Expand All @@ -551,9 +550,8 @@ func (c *ContainerRequest) validateMounts() error {
targetPath := parts[1]
if targets[targetPath] {
return fmt.Errorf("%w: %s", ErrDuplicateMountTarget, targetPath)
} else {
targets[targetPath] = true
}
targets[targetPath] = true
}
}

Expand Down
5 changes: 2 additions & 3 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,11 +1120,10 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
} else {
img, _, err := p.client.ImageInspectWithRaw(ctx, imageName)
if err != nil {
if client.IsErrNotFound(err) {
shouldPullImage = true
} else {
if !client.IsErrNotFound(err) {
return nil, err
}
shouldPullImage = true
}
if platform != nil && (img.Architecture != platform.Architecture || img.Os != platform.OS) {
shouldPullImage = true
Expand Down
6 changes: 2 additions & 4 deletions internal/core/docker_rootless.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ func fileExists(f string) bool {
}

func parseURL(s string) (string, error) {
var hostURL *url.URL
if u, err := url.Parse(s); err != nil {
hostURL, err := url.Parse(s)
if err != nil {
return "", err
} else {
hostURL = u
}

switch hostURL.Scheme {
Expand Down
3 changes: 1 addition & 2 deletions modules/compose/compose_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,8 @@ func withEnv(env map[string]string) func(*cli.ProjectOptions) error {
for k, v := range env {
if _, ok := options.Environment[k]; ok {
return fmt.Errorf("environment with key %s already set", k)
} else {
options.Environment[k] = v
}
options.Environment[k] = v
}

return nil
Expand Down
3 changes: 1 addition & 2 deletions wait/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ func (ws *ExitStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge
if err != nil {
if !strings.Contains(err.Error(), "No such container") {
return err
} else {
return nil
}
return nil
}
if state.Running {
time.Sleep(ws.PollInterval)
Expand Down

0 comments on commit fe64cdf

Please sign in to comment.