mirror of https://github.com/docker/cli.git
linting: address assorted issues found by gocritic
internal/test/builders/config.go:36:15: captLocal: `ID' should not be capitalized (gocritic)
func ConfigID(ID string) func(config *swarm.Config) {
^
internal/test/builders/secret.go:45:15: captLocal: `ID' should not be capitalized (gocritic)
func SecretID(ID string) func(secret *swarm.Secret) {
^
internal/test/builders/service.go:21:16: captLocal: `ID' should not be capitalized (gocritic)
func ServiceID(ID string) func(*swarm.Service) {
^
cli/command/image/formatter_history.go💯15: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(c.h.CreatedBy, "\t", " ", -1)` (gocritic)
createdBy := strings.Replace(c.h.CreatedBy, "\t", " ", -1)
^
e2e/image/push_test.go:246:34: badCall: suspicious Join on 1 argument (gocritic)
assert.NilError(t, os.RemoveAll(filepath.Join(dir.Join("trust"))))
^
e2e/image/push_test.go:313:34: badCall: suspicious Join on 1 argument (gocritic)
assert.NilError(t, os.RemoveAll(filepath.Join(dir.Join("trust"))))
^
cli/config/configfile/file_test.go:185:2: assignOp: replace `c.GetAllCallCount = c.GetAllCallCount + 1` with `c.GetAllCallCount++` (gocritic)
c.GetAllCallCount = c.GetAllCallCount + 1
^
cli/command/context/inspect_test.go:20:58: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(si.MetadataPath, `\`, `\\`, -1)` (gocritic)
expected = strings.Replace(expected, "<METADATA_PATH>", strings.Replace(si.MetadataPath, `\`, `\\`, -1), 1)
^
cli/command/context/inspect_test.go:21:53: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(si.TLSPath, `\`, `\\`, -1)` (gocritic)
expected = strings.Replace(expected, "<TLS_PATH>", strings.Replace(si.TLSPath, `\`, `\\`, -1), 1)
^
cli/command/container/formatter_stats.go:119:46: captLocal: `Stats' should not be capitalized (gocritic)
func statsFormatWrite(ctx formatter.Context, Stats []StatsEntry, osType string, trunc bool) error {
^
cli/command/container/stats_helpers.go:209:4: assignOp: replace `blkRead = blkRead + bioEntry.Value` with `blkRead += bioEntry.Value` (gocritic)
blkRead = blkRead + bioEntry.Value
^
cli/command/container/stats_helpers.go:211:4: assignOp: replace `blkWrite = blkWrite + bioEntry.Value` with `blkWrite += bioEntry.Value` (gocritic)
blkWrite = blkWrite + bioEntry.Value
^
cli/command/registry/formatter_search.go:67:10: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(c.s.Description, "\n", " ", -1)` (gocritic)
desc := strings.Replace(c.s.Description, "\n", " ", -1)
^
cli/command/registry/formatter_search.go:68:9: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(desc, "\r", " ", -1)` (gocritic)
desc = strings.Replace(desc, "\r", " ", -1)
^
cli/command/service/list_test.go:164:5: assignOp: replace `tc.doc = tc.doc + " with quiet"` with `tc.doc += " with quiet"` (gocritic)
tc.doc = tc.doc + " with quiet"
^
cli/command/service/progress/progress.go:274:11: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(errMsg, "\n", " ", -1)` (gocritic)
errMsg = strings.Replace(errMsg, "\n", " ", -1)
^
cli/manifest/store/store.go:153:9: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(fileName, "/", "_", -1)` (gocritic)
return strings.Replace(fileName, "/", "_", -1)
^
cli/manifest/store/store.go:152:14: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(ref, ":", "-", -1)` (gocritic)
fileName := strings.Replace(ref, ":", "-", -1)
^
cli/command/plugin/formatter.go:79:10: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(c.p.Config.Description, "\n", "", -1)` (gocritic)
desc := strings.Replace(c.p.Config.Description, "\n", "", -1)
^
cli/command/plugin/formatter.go:80:9: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(desc, "\r", "", -1)` (gocritic)
desc = strings.Replace(desc, "\r", "", -1)
^
cli/compose/convert/service.go:642:23: captLocal: `DNS' should not be capitalized (gocritic)
func convertDNSConfig(DNS []string, DNSSearch []string) *swarm.DNSConfig {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d0dee3cebe
commit
888df09879
|
@ -116,9 +116,9 @@ func NewStats(container string) *Stats {
|
||||||
}
|
}
|
||||||
|
|
||||||
// statsFormatWrite renders the context for a list of containers statistics
|
// 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 {
|
render := func(format func(subContext formatter.SubContext) error) error {
|
||||||
for _, cstats := range Stats {
|
for _, cstats := range stats {
|
||||||
statsCtx := &statsContext{
|
statsCtx := &statsContext{
|
||||||
s: cstats,
|
s: cstats,
|
||||||
os: osType,
|
os: osType,
|
||||||
|
|
|
@ -206,9 +206,9 @@ func calculateBlockIO(blkio types.BlkioStats) (uint64, uint64) {
|
||||||
}
|
}
|
||||||
switch bioEntry.Op[0] {
|
switch bioEntry.Op[0] {
|
||||||
case 'r', 'R':
|
case 'r', 'R':
|
||||||
blkRead = blkRead + bioEntry.Value
|
blkRead += bioEntry.Value
|
||||||
case 'w', 'W':
|
case 'w', 'W':
|
||||||
blkWrite = blkWrite + bioEntry.Value
|
blkWrite += bioEntry.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return blkRead, blkWrite
|
return blkRead, blkWrite
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestInspect(t *testing.T) {
|
||||||
}))
|
}))
|
||||||
expected := string(golden.Get(t, "inspect.golden"))
|
expected := string(golden.Get(t, "inspect.golden"))
|
||||||
si := cli.ContextStore().GetStorageInfo("current")
|
si := cli.ContextStore().GetStorageInfo("current")
|
||||||
expected = strings.Replace(expected, "<METADATA_PATH>", strings.Replace(si.MetadataPath, `\`, `\\`, -1), 1)
|
expected = strings.Replace(expected, "<METADATA_PATH>", strings.ReplaceAll(si.MetadataPath, `\`, `\\`), 1)
|
||||||
expected = strings.Replace(expected, "<TLS_PATH>", strings.Replace(si.TLSPath, `\`, `\\`, -1), 1)
|
expected = strings.Replace(expected, "<TLS_PATH>", strings.ReplaceAll(si.TLSPath, `\`, `\\`), 1)
|
||||||
assert.Equal(t, cli.OutBuffer().String(), expected)
|
assert.Equal(t, cli.OutBuffer().String(), expected)
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ func (c *historyContext) CreatedSince() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *historyContext) CreatedBy() string {
|
func (c *historyContext) CreatedBy() string {
|
||||||
createdBy := strings.Replace(c.h.CreatedBy, "\t", " ", -1)
|
createdBy := strings.ReplaceAll(c.h.CreatedBy, "\t", " ")
|
||||||
if c.trunc {
|
if c.trunc {
|
||||||
return formatter.Ellipsis(createdBy, 45)
|
return formatter.Ellipsis(createdBy, 45)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,8 +76,8 @@ func (c *pluginContext) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pluginContext) Description() string {
|
func (c *pluginContext) Description() string {
|
||||||
desc := strings.Replace(c.p.Config.Description, "\n", "", -1)
|
desc := strings.ReplaceAll(c.p.Config.Description, "\n", "")
|
||||||
desc = strings.Replace(desc, "\r", "", -1)
|
desc = strings.ReplaceAll(desc, "\r", "")
|
||||||
if c.trunc {
|
if c.trunc {
|
||||||
desc = formatter.Ellipsis(desc, 45)
|
desc = formatter.Ellipsis(desc, 45)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,8 @@ func (c *searchContext) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *searchContext) Description() string {
|
func (c *searchContext) Description() string {
|
||||||
desc := strings.Replace(c.s.Description, "\n", " ", -1)
|
desc := strings.ReplaceAll(c.s.Description, "\n", " ")
|
||||||
desc = strings.Replace(desc, "\r", " ", -1)
|
desc = strings.ReplaceAll(desc, "\r", " ")
|
||||||
if c.trunc {
|
if c.trunc {
|
||||||
desc = formatter.Ellipsis(desc, 45)
|
desc = formatter.Ellipsis(desc, 45)
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ func TestServiceListServiceStatus(t *testing.T) {
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
if quiet {
|
if quiet {
|
||||||
tc.withQuiet = quiet
|
tc.withQuiet = quiet
|
||||||
tc.doc = tc.doc + " with quiet"
|
tc.doc += " with quiet"
|
||||||
}
|
}
|
||||||
matrix = append(matrix, tc)
|
matrix = append(matrix, tc)
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ func writeOverallProgress(progressOut progress.Output, numerator, denominator in
|
||||||
|
|
||||||
func truncError(errMsg string) string {
|
func truncError(errMsg string) string {
|
||||||
// Remove newlines from the error, which corrupt the output.
|
// 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
|
// Limit the length to 75 characters, so that even on narrow terminals
|
||||||
// this will not overflow to the next line.
|
// this will not overflow to the next line.
|
||||||
|
|
|
@ -639,11 +639,11 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error)
|
||||||
return serviceMode, nil
|
return serviceMode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertDNSConfig(DNS []string, DNSSearch []string) *swarm.DNSConfig {
|
func convertDNSConfig(dns []string, dnsSearch []string) *swarm.DNSConfig {
|
||||||
if DNS != nil || DNSSearch != nil {
|
if dns != nil || dnsSearch != nil {
|
||||||
return &swarm.DNSConfig{
|
return &swarm.DNSConfig{
|
||||||
Nameservers: DNS,
|
Nameservers: dns,
|
||||||
Search: DNSSearch,
|
Search: dnsSearch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -182,7 +182,7 @@ func (c *mockNativeStore) Get(registryHostname string) (types.AuthConfig, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockNativeStore) GetAll() (map[string]types.AuthConfig, error) {
|
func (c *mockNativeStore) GetAll() (map[string]types.AuthConfig, error) {
|
||||||
c.GetAllCallCount = c.GetAllCallCount + 1
|
c.GetAllCallCount++
|
||||||
return c.authConfigs, nil
|
return c.authConfigs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -149,8 +149,8 @@ func manifestToFilename(root, manifestList, manifest string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeFilesafeName(ref string) string {
|
func makeFilesafeName(ref string) string {
|
||||||
fileName := strings.Replace(ref, ":", "-", -1)
|
fileName := strings.ReplaceAll(ref, ":", "-")
|
||||||
return strings.Replace(fileName, "/", "_", -1)
|
return strings.ReplaceAll(fileName, "/", "_")
|
||||||
}
|
}
|
||||||
|
|
||||||
type notFoundError struct {
|
type notFoundError struct {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package image
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -243,7 +242,7 @@ func TestPushWithContentTrustSignsAllFirstLevelRolesWeHaveKeysFor(t *testing.T)
|
||||||
targetsInRole = notaryListTargetsInRole(t, notaryDir, homeDir, baseRef, "targets")
|
targetsInRole = notaryListTargetsInRole(t, notaryDir, homeDir, baseRef, "targets")
|
||||||
assert.Assert(t, targetsInRole["latest"] != "targets", "%v", targetsInRole)
|
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
|
// Try to pull, should fail because non of these are the release role
|
||||||
// FIXME(vdemeester) should be unit test
|
// FIXME(vdemeester) should be unit test
|
||||||
result = icmd.RunCmd(icmd.Command("docker", "pull", targetRef),
|
result = icmd.RunCmd(icmd.Command("docker", "pull", targetRef),
|
||||||
|
@ -310,7 +309,7 @@ func TestPushWithContentTrustSignsForRolesWithKeysAndValidPaths(t *testing.T) {
|
||||||
targetsInRole = notaryListTargetsInRole(t, notaryDir, homeDir, baseRef, "targets")
|
targetsInRole = notaryListTargetsInRole(t, notaryDir, homeDir, baseRef, "targets")
|
||||||
assert.Assert(t, targetsInRole["latest"] != "targets", "%v", targetsInRole)
|
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
|
// Try to pull, should fail because non of these are the release role
|
||||||
// FIXME(vdemeester) should be unit test
|
// FIXME(vdemeester) should be unit test
|
||||||
result = icmd.RunCmd(icmd.Command("docker", "pull", targetRef),
|
result = icmd.RunCmd(icmd.Command("docker", "pull", targetRef),
|
||||||
|
|
|
@ -33,9 +33,9 @@ func ConfigName(name string) func(config *swarm.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigID sets the config's ID
|
// 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) {
|
return func(config *swarm.Config) {
|
||||||
config.ID = ID
|
config.ID = id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,9 @@ func SecretDriver(driver string) func(secret *swarm.Secret) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SecretID sets the secret's ID
|
// 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) {
|
return func(secret *swarm.Secret) {
|
||||||
secret.ID = ID
|
secret.ID = id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ func Service(builders ...func(*swarm.Service)) *swarm.Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceID sets the service ID
|
// ServiceID sets the service ID
|
||||||
func ServiceID(ID string) func(*swarm.Service) {
|
func ServiceID(id string) func(*swarm.Service) {
|
||||||
return func(service *swarm.Service) {
|
return func(service *swarm.Service) {
|
||||||
service.ID = ID
|
service.ID = id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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": "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",
|
"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://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: ",
|
"": "invalid bind address format: ",
|
||||||
}
|
}
|
||||||
valids := map[string]string{
|
valids := map[string]string{
|
||||||
|
|
|
@ -428,12 +428,10 @@ func TestValidateLink(t *testing.T) {
|
||||||
for link, expectedError := range invalid {
|
for link, expectedError := range invalid {
|
||||||
if _, err := ValidateLink(link); err == nil {
|
if _, err := ValidateLink(link); err == nil {
|
||||||
t.Fatalf("ValidateLink(`%q`) should have failed validation", link)
|
t.Fatalf("ValidateLink(`%q`) should have failed validation", link)
|
||||||
} else {
|
} else if !strings.Contains(err.Error(), expectedError) {
|
||||||
if !strings.Contains(err.Error(), expectedError) {
|
|
||||||
t.Fatalf("ValidateLink(`%q`) error should contain %q", link, expectedError)
|
t.Fatalf("ValidateLink(`%q`) error should contain %q", link, expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseLink(t *testing.T) {
|
func TestParseLink(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue