diff --git a/cli/command/container/formatter_stats.go b/cli/command/container/formatter_stats.go index c079c913ff..5b46fe2650 100644 --- a/cli/command/container/formatter_stats.go +++ b/cli/command/container/formatter_stats.go @@ -116,9 +116,9 @@ func NewStats(container string) *Stats { } // statsFormatWrite renders the context for a list of containers statistics -func statsFormatWrite(ctx formatter.Context, Stats []StatsEntry, osType string, trunc bool) error { +func statsFormatWrite(ctx formatter.Context, stats []StatsEntry, osType string, trunc bool) error { render := func(format func(subContext formatter.SubContext) error) error { - for _, cstats := range Stats { + for _, cstats := range stats { statsCtx := &statsContext{ s: cstats, os: osType, diff --git a/cli/command/container/stats_helpers.go b/cli/command/container/stats_helpers.go index 5ea7f665dc..938a3d83cd 100644 --- a/cli/command/container/stats_helpers.go +++ b/cli/command/container/stats_helpers.go @@ -206,9 +206,9 @@ func calculateBlockIO(blkio types.BlkioStats) (uint64, uint64) { } switch bioEntry.Op[0] { case 'r', 'R': - blkRead = blkRead + bioEntry.Value + blkRead += bioEntry.Value case 'w', 'W': - blkWrite = blkWrite + bioEntry.Value + blkWrite += bioEntry.Value } } return blkRead, blkWrite diff --git a/cli/command/context/inspect_test.go b/cli/command/context/inspect_test.go index 396a267d74..703898ed53 100644 --- a/cli/command/context/inspect_test.go +++ b/cli/command/context/inspect_test.go @@ -17,7 +17,7 @@ func TestInspect(t *testing.T) { })) expected := string(golden.Get(t, "inspect.golden")) si := cli.ContextStore().GetStorageInfo("current") - expected = strings.Replace(expected, "", strings.Replace(si.MetadataPath, `\`, `\\`, -1), 1) - expected = strings.Replace(expected, "", strings.Replace(si.TLSPath, `\`, `\\`, -1), 1) + expected = strings.Replace(expected, "", strings.ReplaceAll(si.MetadataPath, `\`, `\\`), 1) + expected = strings.Replace(expected, "", strings.ReplaceAll(si.TLSPath, `\`, `\\`), 1) assert.Equal(t, cli.OutBuffer().String(), expected) } diff --git a/cli/command/image/formatter_history.go b/cli/command/image/formatter_history.go index 4e826cb641..a36ab42576 100644 --- a/cli/command/image/formatter_history.go +++ b/cli/command/image/formatter_history.go @@ -97,7 +97,7 @@ func (c *historyContext) CreatedSince() string { } func (c *historyContext) CreatedBy() string { - createdBy := strings.Replace(c.h.CreatedBy, "\t", " ", -1) + createdBy := strings.ReplaceAll(c.h.CreatedBy, "\t", " ") if c.trunc { return formatter.Ellipsis(createdBy, 45) } diff --git a/cli/command/plugin/formatter.go b/cli/command/plugin/formatter.go index 438bf95171..c5c0c9c4e4 100644 --- a/cli/command/plugin/formatter.go +++ b/cli/command/plugin/formatter.go @@ -76,8 +76,8 @@ func (c *pluginContext) Name() string { } func (c *pluginContext) Description() string { - desc := strings.Replace(c.p.Config.Description, "\n", "", -1) - desc = strings.Replace(desc, "\r", "", -1) + desc := strings.ReplaceAll(c.p.Config.Description, "\n", "") + desc = strings.ReplaceAll(desc, "\r", "") if c.trunc { desc = formatter.Ellipsis(desc, 45) } diff --git a/cli/command/registry/formatter_search.go b/cli/command/registry/formatter_search.go index 7d3f55b4d4..ec11298968 100644 --- a/cli/command/registry/formatter_search.go +++ b/cli/command/registry/formatter_search.go @@ -64,8 +64,8 @@ func (c *searchContext) Name() string { } func (c *searchContext) Description() string { - desc := strings.Replace(c.s.Description, "\n", " ", -1) - desc = strings.Replace(desc, "\r", " ", -1) + desc := strings.ReplaceAll(c.s.Description, "\n", " ") + desc = strings.ReplaceAll(desc, "\r", " ") if c.trunc { desc = formatter.Ellipsis(desc, 45) } diff --git a/cli/command/service/list_test.go b/cli/command/service/list_test.go index 6a50210ec5..28952e5c0a 100644 --- a/cli/command/service/list_test.go +++ b/cli/command/service/list_test.go @@ -161,7 +161,7 @@ func TestServiceListServiceStatus(t *testing.T) { for _, tc := range tests { if quiet { tc.withQuiet = quiet - tc.doc = tc.doc + " with quiet" + tc.doc += " with quiet" } matrix = append(matrix, tc) } diff --git a/cli/command/service/progress/progress.go b/cli/command/service/progress/progress.go index d6f049f91b..61f347b8fb 100644 --- a/cli/command/service/progress/progress.go +++ b/cli/command/service/progress/progress.go @@ -271,7 +271,7 @@ func writeOverallProgress(progressOut progress.Output, numerator, denominator in func truncError(errMsg string) string { // Remove newlines from the error, which corrupt the output. - errMsg = strings.Replace(errMsg, "\n", " ", -1) + errMsg = strings.ReplaceAll(errMsg, "\n", " ") // Limit the length to 75 characters, so that even on narrow terminals // this will not overflow to the next line. diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 2302245a01..e835380bff 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -639,11 +639,11 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error) return serviceMode, nil } -func convertDNSConfig(DNS []string, DNSSearch []string) *swarm.DNSConfig { - if DNS != nil || DNSSearch != nil { +func convertDNSConfig(dns []string, dnsSearch []string) *swarm.DNSConfig { + if dns != nil || dnsSearch != nil { return &swarm.DNSConfig{ - Nameservers: DNS, - Search: DNSSearch, + Nameservers: dns, + Search: dnsSearch, } } return nil diff --git a/cli/config/configfile/file_test.go b/cli/config/configfile/file_test.go index 74a0317d5e..51aac67964 100644 --- a/cli/config/configfile/file_test.go +++ b/cli/config/configfile/file_test.go @@ -182,7 +182,7 @@ func (c *mockNativeStore) Get(registryHostname string) (types.AuthConfig, error) } func (c *mockNativeStore) GetAll() (map[string]types.AuthConfig, error) { - c.GetAllCallCount = c.GetAllCallCount + 1 + c.GetAllCallCount++ return c.authConfigs, nil } diff --git a/cli/manifest/store/store.go b/cli/manifest/store/store.go index 02c635674b..dbf7730632 100644 --- a/cli/manifest/store/store.go +++ b/cli/manifest/store/store.go @@ -149,8 +149,8 @@ func manifestToFilename(root, manifestList, manifest string) string { } func makeFilesafeName(ref string) string { - fileName := strings.Replace(ref, ":", "-", -1) - return strings.Replace(fileName, "/", "_", -1) + fileName := strings.ReplaceAll(ref, ":", "-") + return strings.ReplaceAll(fileName, "/", "_") } type notFoundError struct { diff --git a/e2e/image/push_test.go b/e2e/image/push_test.go index 9098aa0478..1774bd82ea 100644 --- a/e2e/image/push_test.go +++ b/e2e/image/push_test.go @@ -3,7 +3,6 @@ package image import ( "fmt" "os" - "path/filepath" "strings" "testing" @@ -243,7 +242,7 @@ func TestPushWithContentTrustSignsAllFirstLevelRolesWeHaveKeysFor(t *testing.T) targetsInRole = notaryListTargetsInRole(t, notaryDir, homeDir, baseRef, "targets") assert.Assert(t, targetsInRole["latest"] != "targets", "%v", targetsInRole) - assert.NilError(t, os.RemoveAll(filepath.Join(dir.Join("trust")))) + assert.NilError(t, os.RemoveAll(dir.Join("trust"))) // Try to pull, should fail because non of these are the release role // FIXME(vdemeester) should be unit test result = icmd.RunCmd(icmd.Command("docker", "pull", targetRef), @@ -310,7 +309,7 @@ func TestPushWithContentTrustSignsForRolesWithKeysAndValidPaths(t *testing.T) { targetsInRole = notaryListTargetsInRole(t, notaryDir, homeDir, baseRef, "targets") assert.Assert(t, targetsInRole["latest"] != "targets", "%v", targetsInRole) - assert.NilError(t, os.RemoveAll(filepath.Join(dir.Join("trust")))) + assert.NilError(t, os.RemoveAll(dir.Join("trust"))) // Try to pull, should fail because non of these are the release role // FIXME(vdemeester) should be unit test result = icmd.RunCmd(icmd.Command("docker", "pull", targetRef), diff --git a/internal/test/builders/config.go b/internal/test/builders/config.go index be48c30397..53aeb43e29 100644 --- a/internal/test/builders/config.go +++ b/internal/test/builders/config.go @@ -33,9 +33,9 @@ func ConfigName(name string) func(config *swarm.Config) { } // ConfigID sets the config's ID -func ConfigID(ID string) func(config *swarm.Config) { +func ConfigID(id string) func(config *swarm.Config) { return func(config *swarm.Config) { - config.ID = ID + config.ID = id } } diff --git a/internal/test/builders/secret.go b/internal/test/builders/secret.go index 3cd5f7872a..500193cab6 100644 --- a/internal/test/builders/secret.go +++ b/internal/test/builders/secret.go @@ -42,9 +42,9 @@ func SecretDriver(driver string) func(secret *swarm.Secret) { } // SecretID sets the secret's ID -func SecretID(ID string) func(secret *swarm.Secret) { +func SecretID(id string) func(secret *swarm.Secret) { return func(secret *swarm.Secret) { - secret.ID = ID + secret.ID = id } } diff --git a/internal/test/builders/service.go b/internal/test/builders/service.go index 4a6b50baa6..6548806769 100644 --- a/internal/test/builders/service.go +++ b/internal/test/builders/service.go @@ -18,9 +18,9 @@ func Service(builders ...func(*swarm.Service)) *swarm.Service { } // ServiceID sets the service ID -func ServiceID(ID string) func(*swarm.Service) { +func ServiceID(id string) func(*swarm.Service) { return func(service *swarm.Service) { - service.ID = ID + service.ID = id } } diff --git a/opts/hosts_test.go b/opts/hosts_test.go index 9d38d164be..f1b2ca6b12 100644 --- a/opts/hosts_test.go +++ b/opts/hosts_test.go @@ -57,7 +57,7 @@ func TestParseDockerDaemonHost(t *testing.T) { "udp://127.0.0.1": "invalid bind address format: udp://127.0.0.1", "udp://127.0.0.1:2375": "invalid bind address format: udp://127.0.0.1:2375", "tcp://unix:///run/docker.sock": "invalid proto, expected tcp: unix:///run/docker.sock", - " tcp://:7777/path ": "invalid bind address format: tcp://:7777/path ", + " tcp://:7777/path ": "invalid bind address format: tcp://:7777/path ", //nolint:gocritic // ignore mapKey: suspucious whitespace "": "invalid bind address format: ", } valids := map[string]string{ diff --git a/opts/opts_test.go b/opts/opts_test.go index 98b97003a8..2868b04f4f 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -428,10 +428,8 @@ func TestValidateLink(t *testing.T) { for link, expectedError := range invalid { if _, err := ValidateLink(link); err == nil { t.Fatalf("ValidateLink(`%q`) should have failed validation", link) - } else { - if !strings.Contains(err.Error(), expectedError) { - t.Fatalf("ValidateLink(`%q`) error should contain %q", link, expectedError) - } + } else if !strings.Contains(err.Error(), expectedError) { + t.Fatalf("ValidateLink(`%q`) error should contain %q", link, expectedError) } } }