Skip to content

Commit 852c0f4

Browse files
committed
chore: enable revive's conditions nesting related rules
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent c80675b commit 852c0f4

File tree

5 files changed

+37
-30
lines changed

5 files changed

+37
-30
lines changed

.golangci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,21 @@ linters:
123123

124124
revive:
125125
rules:
126+
- name: early-return # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return
127+
arguments:
128+
- preserveScope
126129
- name: empty-block # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block
127130
- name: empty-lines # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
131+
- name: if-return # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return
128132
- name: import-shadowing # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing
133+
- name: indent-error-flow # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#indent-error-flow
134+
arguments:
135+
- preserveScope
129136
- name: line-length-limit # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit
130137
arguments: [200]
138+
- name: superfluous-else # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#superfluous-else
139+
arguments:
140+
- preserveScope
131141
- name: unused-receiver # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
132142
- name: use-any # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any
133143

cli/command/container/create.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -342,24 +342,23 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
342342
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, options.name)
343343
if err != nil {
344344
// Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior.
345-
if errdefs.IsNotFound(err) && namedRef != nil && options.pull == PullImageMissing {
346-
if !options.quiet {
347-
// we don't want to write to stdout anything apart from container.ID
348-
_, _ = fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
349-
}
350-
351-
if err := pullAndTagImage(); err != nil {
352-
return "", err
353-
}
345+
if !errdefs.IsNotFound(err) || namedRef == nil || options.pull != PullImageMissing {
346+
return "", err
347+
}
348+
if !options.quiet {
349+
// we don't want to write to stdout anything apart from container.ID
350+
_, _ = fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
351+
}
354352

355-
var retryErr error
356-
response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, options.name)
357-
if retryErr != nil {
358-
return "", retryErr
359-
}
360-
} else {
353+
if err := pullAndTagImage(); err != nil {
361354
return "", err
362355
}
356+
357+
var retryErr error
358+
response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, options.name)
359+
if retryErr != nil {
360+
return "", retryErr
361+
}
363362
}
364363

365364
if warn := localhostDNSWarning(*hostConfig); warn != "" {

cli/command/formatter/container.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,16 @@ func (c *ContainerContext) Image() string {
167167
// truncate digest if no-trunc option was not selected
168168
ref, err := reference.ParseNormalizedNamed(c.c.Image)
169169
if err == nil {
170-
if nt, ok := ref.(reference.NamedTagged); ok {
171-
// case for when a tag is provided
172-
if namedTagged, err := reference.WithTag(reference.TrimNamed(nt), nt.Tag()); err == nil {
173-
return reference.FamiliarString(namedTagged)
174-
}
175-
} else {
170+
nt, ok := ref.(reference.NamedTagged)
171+
if !ok {
176172
// case for when a tag is not provided
177173
named := reference.TrimNamed(ref)
178174
return reference.FamiliarString(named)
179175
}
176+
// case for when a tag is provided
177+
if namedTagged, err := reference.WithTag(reference.TrimNamed(nt), nt.Tag()); err == nil {
178+
return reference.FamiliarString(namedTagged)
179+
}
180180
}
181181
}
182182

cli/command/formatter/tabwriter/tabwriter_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ func (b *buffer) clear() { b.a = b.a[0:0] }
2323
func (b *buffer) Write(buf []byte) (written int, err error) {
2424
n := len(b.a)
2525
m := len(buf)
26-
if n+m <= cap(b.a) {
27-
b.a = b.a[0 : n+m]
28-
for i := 0; i < m; i++ {
29-
b.a[n+i] = buf[i]
30-
}
31-
} else {
26+
if n+m > cap(b.a) {
3227
panic("buffer.Write: buffer too small")
3328
}
29+
b.a = b.a[0 : n+m]
30+
for i := 0; i < m; i++ {
31+
b.a[n+i] = buf[i]
32+
}
3433
return len(buf), nil
3534
}
3635

cli/command/swarm/opts.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,10 @@ func parseExternalCA(caSpec string) (*swarm.ExternalCA, error) {
184184
switch strings.ToLower(key) {
185185
case "protocol":
186186
hasProtocol = true
187-
if strings.ToLower(value) == string(swarm.ExternalCAProtocolCFSSL) {
188-
externalCA.Protocol = swarm.ExternalCAProtocolCFSSL
189-
} else {
187+
if strings.ToLower(value) != string(swarm.ExternalCAProtocolCFSSL) {
190188
return nil, errors.Errorf("unrecognized external CA protocol %s", value)
191189
}
190+
externalCA.Protocol = swarm.ExternalCAProtocolCFSSL
192191
case "url":
193192
hasURL = true
194193
externalCA.URL = value

0 commit comments

Comments
 (0)