From 01e1e58adaec1147f6e223791fe1da9d5f026588 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 9 Jun 2017 12:32:14 -0400 Subject: [PATCH 1/6] Add unused linter. Signed-off-by: Daniel Nephin --- cli/command/container/stats_helpers.go | 5 ++--- cli/command/formatter/disk_usage.go | 2 -- cli/command/formatter/reflect_test.go | 2 +- cli/command/image/pull_test.go | 19 +++++-------------- cli/command/image/push_test.go | 11 ++--------- cli/command/node/opts.go | 1 - cli/command/registry/login.go | 1 - cli/command/swarm/unlock_test.go | 1 - cli/compose/loader/loader_test.go | 4 ---- dockerfiles/Dockerfile.lint | 3 ++- gometalinter.json | 3 ++- 11 files changed, 14 insertions(+), 38 deletions(-) diff --git a/cli/command/container/stats_helpers.go b/cli/command/container/stats_helpers.go index c6849c805a..eb12cd0dec 100644 --- a/cli/command/container/stats_helpers.go +++ b/cli/command/container/stats_helpers.go @@ -16,9 +16,8 @@ import ( ) type stats struct { - ostype string - mu sync.Mutex - cs []*formatter.ContainerStats + mu sync.Mutex + cs []*formatter.ContainerStats } // daemonOSType is set once we have at least one stat for a container diff --git a/cli/command/formatter/disk_usage.go b/cli/command/formatter/disk_usage.go index 07e39826ed..caea53f924 100644 --- a/cli/command/formatter/disk_usage.go +++ b/cli/command/formatter/disk_usage.go @@ -234,7 +234,6 @@ func (c *diskUsageImagesContext) Reclaimable() string { type diskUsageContainersContext struct { HeaderContext - verbose bool containers []*types.Container } @@ -297,7 +296,6 @@ func (c *diskUsageContainersContext) Reclaimable() string { type diskUsageVolumesContext struct { HeaderContext - verbose bool volumes []*types.Volume } diff --git a/cli/command/formatter/reflect_test.go b/cli/command/formatter/reflect_test.go index e547b18411..ffda51b858 100644 --- a/cli/command/formatter/reflect_test.go +++ b/cli/command/formatter/reflect_test.go @@ -12,7 +12,7 @@ func (d *dummy) Func1() string { return "Func1" } -func (d *dummy) func2() string { +func (d *dummy) func2() string { // nolint: unused return "func2(should not be marshalled)" } diff --git a/cli/command/image/pull_test.go b/cli/command/image/pull_test.go index b4b57e2abc..d72531b768 100644 --- a/cli/command/image/pull_test.go +++ b/cli/command/image/pull_test.go @@ -6,24 +6,17 @@ import ( "io/ioutil" "testing" - "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/internal/test" - "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" - "github.com/docker/docker/registry" "github.com/stretchr/testify/assert" - "golang.org/x/net/context" ) func TestNewPullCommandErrors(t *testing.T) { testCases := []struct { - name string - args []string - expectedError string - trustedPullFunc func(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, - authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error + name string + args []string + expectedError string }{ { name: "wrong-args", @@ -57,10 +50,8 @@ func TestNewPullCommandErrors(t *testing.T) { func TestNewPullCommandSuccess(t *testing.T) { testCases := []struct { - name string - args []string - trustedPullFunc func(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, - authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error + name string + args []string }{ { name: "simple", diff --git a/cli/command/image/push_test.go b/cli/command/image/push_test.go index b382ad7ee1..559b1b89c3 100644 --- a/cli/command/image/push_test.go +++ b/cli/command/image/push_test.go @@ -7,15 +7,11 @@ import ( "strings" "testing" - "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/internal/test" - "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/testutil" - "github.com/docker/docker/registry" "github.com/pkg/errors" "github.com/stretchr/testify/assert" - "golang.org/x/net/context" ) func TestNewPushCommandErrors(t *testing.T) { @@ -60,11 +56,8 @@ func TestNewPushCommandErrors(t *testing.T) { func TestNewPushCommandSuccess(t *testing.T) { testCases := []struct { - name string - args []string - trustedPushFunc func(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, - ref reference.Named, authConfig types.AuthConfig, - requestPrivilege types.RequestPrivilegeFunc) error + name string + args []string }{ { name: "simple", diff --git a/cli/command/node/opts.go b/cli/command/node/opts.go index 484ab5edaf..e30e5de910 100644 --- a/cli/command/node/opts.go +++ b/cli/command/node/opts.go @@ -11,7 +11,6 @@ type nodeOptions struct { } type annotations struct { - name string labels opts.ListOpts } diff --git a/cli/command/registry/login.go b/cli/command/registry/login.go index af79e967cc..ba1b133054 100644 --- a/cli/command/registry/login.go +++ b/cli/command/registry/login.go @@ -16,7 +16,6 @@ type loginOptions struct { serverAddress string user string password string - email string } // NewLoginCommand creates a new `docker login` command diff --git a/cli/command/swarm/unlock_test.go b/cli/command/swarm/unlock_test.go index 991365f873..3dae5239f5 100644 --- a/cli/command/swarm/unlock_test.go +++ b/cli/command/swarm/unlock_test.go @@ -19,7 +19,6 @@ func TestSwarmUnlockErrors(t *testing.T) { testCases := []struct { name string args []string - input string swarmUnlockFunc func(req swarm.UnlockRequest) error infoFunc func() (types.Info, error) expectedError string diff --git a/cli/compose/loader/loader_test.go b/cli/compose/loader/loader_test.go index 4e604431d3..43a02204b7 100644 --- a/cli/compose/loader/loader_test.go +++ b/cli/compose/loader/loader_test.go @@ -632,10 +632,6 @@ func durationPtr(value time.Duration) *time.Duration { return &value } -func int64Ptr(value int64) *int64 { - return &value -} - func uint64Ptr(value uint64) *uint64 { return &value } diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 14c124642e..71ea437914 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -7,5 +7,6 @@ RUN go get -u gopkg.in/alecthomas/gometalinter.v1 && \ gometalinter --install WORKDIR /go/src/github.com/docker/cli +ENV CGO_ENABLED=0 ENTRYPOINT ["/usr/local/bin/gometalinter"] -CMD ["--config=gometalinter.json", "./..."] +CMD ["--config=gometalinter.json", "./..."] diff --git a/gometalinter.json b/gometalinter.json index f7c6a88a5d..27b6735195 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -1,6 +1,6 @@ { "Vendor": true, - "Deadline": "2m", + "Deadline": "3m", "Sort": ["linter", "severity", "path"], "Exclude": ["cli/compose/schema/bindata.go"], @@ -14,6 +14,7 @@ "ineffassign", "interfacer", "lll", + "unused", "vet" ], From a712993e93605b9c153eaab16c2bf0cf449a7ec7 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 23 May 2017 11:33:38 -0400 Subject: [PATCH 2/6] Add misspell lint Signed-off-by: Daniel Nephin --- cli/command/container/hijack.go | 2 +- gometalinter.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/command/container/hijack.go b/cli/command/container/hijack.go index 603557f3bd..b6d467d081 100644 --- a/cli/command/container/hijack.go +++ b/cli/command/container/hijack.go @@ -110,7 +110,7 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) { func (h *hijackedIOStreamer) beginOutputStream(restoreInput func()) <-chan error { if h.outputStream == nil && h.errorStream == nil { - // Ther is no need to copy output. + // There is no need to copy output. return nil } diff --git a/gometalinter.json b/gometalinter.json index 27b6735195..eb86268e63 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -14,6 +14,7 @@ "ineffassign", "interfacer", "lll", + "misspell", "unused", "vet" ], From 3bf0317fead60e2b8526b47abb2dd243ab57c74d Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 9 Jun 2017 16:41:53 -0400 Subject: [PATCH 3/6] Add unconvert linter Signed-off-by: Daniel Nephin --- cli/command/formatter/container.go | 4 ++-- cli/command/formatter/history.go | 9 +++------ cli/command/formatter/image.go | 4 ++-- cli/command/swarm/opts.go | 4 ++-- cli/command/system/info.go | 3 +-- cli/trust/trust.go | 2 +- gometalinter.json | 1 + opts/opts.go | 2 +- opts/quotedstring.go | 2 +- opts/throttledevice.go | 5 +---- 10 files changed, 15 insertions(+), 21 deletions(-) diff --git a/cli/command/formatter/container.go b/cli/command/formatter/container.go index 9b5c24636c..8ffb1a69b2 100644 --- a/cli/command/formatter/container.go +++ b/cli/command/formatter/container.go @@ -171,11 +171,11 @@ func (c *containerContext) Command() string { } func (c *containerContext) CreatedAt() string { - return time.Unix(int64(c.c.Created), 0).String() + return time.Unix(c.c.Created, 0).String() } func (c *containerContext) RunningFor() string { - createdAt := time.Unix(int64(c.c.Created), 0) + createdAt := time.Unix(c.c.Created, 0) return units.HumanDuration(time.Now().UTC().Sub(createdAt)) + " ago" } diff --git a/cli/command/formatter/history.go b/cli/command/formatter/history.go index ed2af4637e..161aaa4b00 100644 --- a/cli/command/formatter/history.go +++ b/cli/command/formatter/history.go @@ -79,21 +79,18 @@ func (c *historyContext) ID() string { } func (c *historyContext) CreatedAt() string { - var created string - created = units.HumanDuration(time.Now().UTC().Sub(time.Unix(int64(c.h.Created), 0))) - return created + return units.HumanDuration(time.Now().UTC().Sub(time.Unix(c.h.Created, 0))) } func (c *historyContext) CreatedSince() string { - var created string - created = units.HumanDuration(time.Now().UTC().Sub(time.Unix(int64(c.h.Created), 0))) + created := units.HumanDuration(time.Now().UTC().Sub(time.Unix(c.h.Created, 0))) return created + " ago" } func (c *historyContext) CreatedBy() string { createdBy := strings.Replace(c.h.CreatedBy, "\t", " ", -1) if c.trunc { - createdBy = stringutils.Ellipsis(createdBy, 45) + return stringutils.Ellipsis(createdBy, 45) } return createdBy } diff --git a/cli/command/formatter/image.go b/cli/command/formatter/image.go index 3aae34ea11..cbd3edad3c 100644 --- a/cli/command/formatter/image.go +++ b/cli/command/formatter/image.go @@ -234,12 +234,12 @@ func (c *imageContext) Digest() string { } func (c *imageContext) CreatedSince() string { - createdAt := time.Unix(int64(c.i.Created), 0) + createdAt := time.Unix(c.i.Created, 0) return units.HumanDuration(time.Now().UTC().Sub(createdAt)) + " ago" } func (c *imageContext) CreatedAt() string { - return time.Unix(int64(c.i.Created), 0).String() + return time.Unix(c.i.Created, 0).String() } func (c *imageContext) Size() string { diff --git a/cli/command/swarm/opts.go b/cli/command/swarm/opts.go index 4625835055..0522f9fdfa 100644 --- a/cli/command/swarm/opts.go +++ b/cli/command/swarm/opts.go @@ -217,13 +217,13 @@ func parseExternalCA(caSpec string) (*swarm.ExternalCA, error) { } func addSwarmCAFlags(flags *pflag.FlagSet, opts *swarmOptions) { - flags.DurationVar(&opts.nodeCertExpiry, flagCertExpiry, time.Duration(90*24*time.Hour), "Validity period for node certificates (ns|us|ms|s|m|h)") + flags.DurationVar(&opts.nodeCertExpiry, flagCertExpiry, 90*24*time.Hour, "Validity period for node certificates (ns|us|ms|s|m|h)") flags.Var(&opts.externalCA, flagExternalCA, "Specifications of one or more certificate signing endpoints") } func addSwarmFlags(flags *pflag.FlagSet, opts *swarmOptions) { flags.Int64Var(&opts.taskHistoryLimit, flagTaskHistoryLimit, 5, "Task history retention limit") - flags.DurationVar(&opts.dispatcherHeartbeat, flagDispatcherHeartbeat, time.Duration(5*time.Second), "Dispatcher heartbeat period (ns|us|ms|s|m|h)") + flags.DurationVar(&opts.dispatcherHeartbeat, flagDispatcherHeartbeat, 5*time.Second, "Dispatcher heartbeat period (ns|us|ms|s|m|h)") flags.Uint64Var(&opts.maxSnapshots, flagMaxSnapshots, 0, "Number of additional Raft snapshots to retain") flags.SetAnnotation(flagMaxSnapshots, "version", []string{"1.25"}) flags.Uint64Var(&opts.snapshotInterval, flagSnapshotInterval, 10000, "Number of log entries between Raft snapshots") diff --git a/cli/command/system/info.go b/cli/command/system/info.go index 7b91066974..55b867b296 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -5,7 +5,6 @@ import ( "io" "sort" "strings" - "time" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" @@ -120,7 +119,7 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error { fmt.Fprintf(dockerCli.Out(), " Heartbeat Tick: %d\n", info.Swarm.Cluster.Spec.Raft.HeartbeatTick) fmt.Fprintf(dockerCli.Out(), " Election Tick: %d\n", info.Swarm.Cluster.Spec.Raft.ElectionTick) fmt.Fprintf(dockerCli.Out(), " Dispatcher:\n") - fmt.Fprintf(dockerCli.Out(), " Heartbeat Period: %s\n", units.HumanDuration(time.Duration(info.Swarm.Cluster.Spec.Dispatcher.HeartbeatPeriod))) + fmt.Fprintf(dockerCli.Out(), " Heartbeat Period: %s\n", units.HumanDuration(info.Swarm.Cluster.Spec.Dispatcher.HeartbeatPeriod)) fmt.Fprintf(dockerCli.Out(), " CA Configuration:\n") fmt.Fprintf(dockerCli.Out(), " Expiry Duration: %s\n", units.HumanDuration(info.Swarm.Cluster.Spec.CAConfig.NodeCertExpiry)) fmt.Fprintf(dockerCli.Out(), " Force Rotate: %d\n", info.Swarm.Cluster.Spec.CAConfig.ForceRotate) diff --git a/cli/trust/trust.go b/cli/trust/trust.go index c325b966a8..600a2acc41 100644 --- a/cli/trust/trust.go +++ b/cli/trust/trust.go @@ -161,7 +161,7 @@ func GetNotaryRepository(streams command.Streams, repoInfo *registry.RepositoryI } tokenHandler := auth.NewTokenHandlerWithOptions(tokenHandlerOptions) basicHandler := auth.NewBasicHandler(creds) - modifiers = append(modifiers, transport.RequestModifier(auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler))) + modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler)) tr := transport.NewTransport(base, modifiers...) return client.NewNotaryRepository( diff --git a/gometalinter.json b/gometalinter.json index eb86268e63..9ba9ea47a5 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -15,6 +15,7 @@ "interfacer", "lll", "misspell", + "unconvert", "unused", "vet" ], diff --git a/opts/opts.go b/opts/opts.go index f76f308051..d915ec2f76 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -179,7 +179,7 @@ func (opts *MapOpts) GetAll() map[string]string { } func (opts *MapOpts) String() string { - return fmt.Sprintf("%v", map[string]string((opts.values))) + return fmt.Sprintf("%v", opts.values) } // Type returns a string name for this Option type diff --git a/opts/quotedstring.go b/opts/quotedstring.go index fb1e5374bc..09c68a5261 100644 --- a/opts/quotedstring.go +++ b/opts/quotedstring.go @@ -18,7 +18,7 @@ func (s *QuotedString) Type() string { } func (s *QuotedString) String() string { - return string(*s.value) + return *s.value } func trimQuotes(value string) string { diff --git a/opts/throttledevice.go b/opts/throttledevice.go index 65dd3ebf68..0959efae35 100644 --- a/opts/throttledevice.go +++ b/opts/throttledevice.go @@ -52,10 +52,7 @@ func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, error) { return nil, fmt.Errorf("invalid rate for device: %s. The correct format is :. Number must be a positive integer", val) } - return &blkiodev.ThrottleDevice{ - Path: split[0], - Rate: uint64(rate), - }, nil + return &blkiodev.ThrottleDevice{Path: split[0], Rate: rate}, nil } // ThrottledeviceOpt defines a map of ThrottleDevices From 3e3934c19f4541b0026a45385ccc0c0dfc389fb4 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 9 Jun 2017 17:16:56 -0400 Subject: [PATCH 4/6] Add unparam linter Signed-off-by: Daniel Nephin --- cli/command/container/opts_test.go | 47 +++++++++-------------------- cli/command/container/stats.go | 8 ++--- cli/command/formatter/stats.go | 6 ++-- cli/command/swarm/init.go | 2 +- cli/command/swarm/unlock_key.go | 8 ++--- cli/command/swarm/update.go | 2 +- cli/internal/test/network/client.go | 10 +++--- docs/yaml/yaml.go | 4 +-- gometalinter.json | 3 +- 9 files changed, 36 insertions(+), 54 deletions(-) diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index e10754f31b..6001cde2c0 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -61,16 +61,14 @@ func parseRun(args []string) (*container.Config, *container.HostConfig, *network return containerConfig.Config, containerConfig.HostConfig, containerConfig.NetworkingConfig, err } -func parsetest(t *testing.T, args string) (*container.Config, *container.HostConfig, error) { - config, hostConfig, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) - return config, hostConfig, err +func parseMustError(t *testing.T, args string) { + _, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) + assert.Error(t, err, args) } func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) { - config, hostConfig, err := parsetest(t, args) - if err != nil { - t.Fatal(err) - } + config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash")) + assert.NoError(t, err) return config, hostConfig } @@ -86,7 +84,6 @@ func TestParseRunLinks(t *testing.T) { } } -// nolint: gocyclo func TestParseRunAttach(t *testing.T) { if config, _ := mustParse(t, "-a stdin"); !config.AttachStdin || config.AttachStdout || config.AttachStderr { t.Fatalf("Error parsing attach flags. Expect only Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr) @@ -103,31 +100,17 @@ func TestParseRunAttach(t *testing.T) { if config, _ := mustParse(t, "-i"); !config.AttachStdin || !config.AttachStdout || !config.AttachStderr { t.Fatalf("Error parsing attach flags. Expect Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr) } +} - if _, _, err := parsetest(t, "-a"); err == nil { - t.Fatal("Error parsing attach flags, `-a` should be an error but is not") - } - if _, _, err := parsetest(t, "-a invalid"); err == nil { - t.Fatal("Error parsing attach flags, `-a invalid` should be an error but is not") - } - if _, _, err := parsetest(t, "-a invalid -a stdout"); err == nil { - t.Fatal("Error parsing attach flags, `-a stdout -a invalid` should be an error but is not") - } - if _, _, err := parsetest(t, "-a stdout -a stderr -d"); err == nil { - t.Fatal("Error parsing attach flags, `-a stdout -a stderr -d` should be an error but is not") - } - if _, _, err := parsetest(t, "-a stdin -d"); err == nil { - t.Fatal("Error parsing attach flags, `-a stdin -d` should be an error but is not") - } - if _, _, err := parsetest(t, "-a stdout -d"); err == nil { - t.Fatal("Error parsing attach flags, `-a stdout -d` should be an error but is not") - } - if _, _, err := parsetest(t, "-a stderr -d"); err == nil { - t.Fatal("Error parsing attach flags, `-a stderr -d` should be an error but is not") - } - if _, _, err := parsetest(t, "-d --rm"); err == nil { - t.Fatal("Error parsing attach flags, `-d --rm` should be an error but is not") - } +func TestParseRunWithInvalidArgs(t *testing.T) { + parseMustError(t, "-a") + parseMustError(t, "-a invalid") + parseMustError(t, "-a invalid -a stdout") + parseMustError(t, "-a stdout -a stderr -d") + parseMustError(t, "-a stdin -d") + parseMustError(t, "-a stdout -d") + parseMustError(t, "-a stderr -d") + parseMustError(t, "-d --rm") } // nolint: gocyclo diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index da6a6d059b..50495f00c3 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -106,7 +106,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { closeChan <- err } for _, container := range cs { - s := formatter.NewContainerStats(container.ID[:12], daemonOSType) + s := formatter.NewContainerStats(container.ID[:12]) if cStats.add(s) { waitFirst.Add(1) go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) @@ -123,7 +123,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { eh := command.InitEventHandler() eh.Handle("create", func(e events.Message) { if opts.all { - s := formatter.NewContainerStats(e.ID[:12], daemonOSType) + s := formatter.NewContainerStats(e.ID[:12]) if cStats.add(s) { waitFirst.Add(1) go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) @@ -132,7 +132,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { }) eh.Handle("start", func(e events.Message) { - s := formatter.NewContainerStats(e.ID[:12], daemonOSType) + s := formatter.NewContainerStats(e.ID[:12]) if cStats.add(s) { waitFirst.Add(1) go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) @@ -158,7 +158,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { // Artificially send creation events for the containers we were asked to // monitor (same code path than we use when monitoring all containers). for _, name := range opts.containers { - s := formatter.NewContainerStats(name, daemonOSType) + s := formatter.NewContainerStats(name) if cStats.add(s) { waitFirst.Add(1) go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) diff --git a/cli/command/formatter/stats.go b/cli/command/formatter/stats.go index c0151101a0..f53387e90a 100644 --- a/cli/command/formatter/stats.go +++ b/cli/command/formatter/stats.go @@ -109,10 +109,8 @@ func NewStatsFormat(source, osType string) Format { } // NewContainerStats returns a new ContainerStats entity and sets in it the given name -func NewContainerStats(container, osType string) *ContainerStats { - return &ContainerStats{ - StatsEntry: StatsEntry{Container: container}, - } +func NewContainerStats(container string) *ContainerStats { + return &ContainerStats{StatsEntry: StatsEntry{Container: container}} } // ContainerStatsWrite renders the context for a list of containers statistics diff --git a/cli/command/swarm/init.go b/cli/command/swarm/init.go index ea3189a0c7..91b827eb97 100644 --- a/cli/command/swarm/init.go +++ b/cli/command/swarm/init.go @@ -92,7 +92,7 @@ func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) erro if err != nil { return errors.Wrap(err, "could not fetch unlock key") } - printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey) + printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey) } return nil diff --git a/cli/command/swarm/unlock_key.go b/cli/command/swarm/unlock_key.go index 870f8e4435..4618de7dea 100644 --- a/cli/command/swarm/unlock_key.go +++ b/cli/command/swarm/unlock_key.go @@ -2,6 +2,7 @@ package swarm import ( "fmt" + "io" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" @@ -74,16 +75,15 @@ func runUnlockKey(dockerCli command.Cli, opts unlockKeyOptions) error { return nil } - printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey) + printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey) return nil } -func printUnlockCommand(ctx context.Context, dockerCli command.Cli, unlockKey string) { +func printUnlockCommand(out io.Writer, unlockKey string) { if len(unlockKey) > 0 { - fmt.Fprintf(dockerCli.Out(), "To unlock a swarm manager after it restarts, "+ + fmt.Fprintf(out, "To unlock a swarm manager after it restarts, "+ "run the `docker swarm unlock`\ncommand and provide the following key:\n\n %s\n\n"+ "Please remember to store this key in a password manager, since without it you\n"+ "will not be able to restart the manager.\n", unlockKey) } - return } diff --git a/cli/command/swarm/update.go b/cli/command/swarm/update.go index 561ca0a768..4d751bbd4e 100644 --- a/cli/command/swarm/update.go +++ b/cli/command/swarm/update.go @@ -65,7 +65,7 @@ func runUpdate(dockerCli command.Cli, flags *pflag.FlagSet, opts swarmOptions) e if err != nil { return errors.Wrap(err, "could not fetch unlock key") } - printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey) + printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey) } return nil diff --git a/cli/internal/test/network/client.go b/cli/internal/test/network/client.go index b12fdec6f2..d83288d619 100644 --- a/cli/internal/test/network/client.go +++ b/cli/internal/test/network/client.go @@ -18,11 +18,11 @@ func (c *FakeClient) NetworkConnect(ctx context.Context, networkID, container st } // NetworkCreate fakes creating a network -func (c *FakeClient) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) { +func (c *FakeClient) NetworkCreate(_ context.Context, _ string, options types.NetworkCreate) (types.NetworkCreateResponse, error) { return types.NetworkCreateResponse{}, nil } -// NetworkDisconnect fakes disconencting from a network +// NetworkDisconnect fakes disconnecting from a network func (c *FakeClient) NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error { return nil } @@ -36,12 +36,12 @@ func (c *FakeClient) NetworkInspect(ctx context.Context, networkID string, optio } // NetworkInspectWithRaw fakes inspecting a network with a raw response -func (c *FakeClient) NetworkInspectWithRaw(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error) { +func (c *FakeClient) NetworkInspectWithRaw(_ context.Context, _ string, _ types.NetworkInspectOptions) (types.NetworkResource, []byte, error) { return types.NetworkResource{}, nil, nil } // NetworkList fakes listing networks -func (c *FakeClient) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) { +func (c *FakeClient) NetworkList(_ context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) { return nil, nil } @@ -51,6 +51,6 @@ func (c *FakeClient) NetworkRemove(ctx context.Context, networkID string) error } // NetworksPrune fakes pruning networks -func (c *FakeClient) NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) { +func (c *FakeClient) NetworksPrune(_ context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) { return types.NetworksPruneReport{}, nil } diff --git a/docs/yaml/yaml.go b/docs/yaml/yaml.go index 575f9bec5c..edf5e9dd7f 100644 --- a/docs/yaml/yaml.go +++ b/docs/yaml/yaml.go @@ -66,14 +66,14 @@ func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandle if _, err := io.WriteString(f, filePrepender(filename)); err != nil { return err } - if err := GenYamlCustom(cmd, f, linkHandler); err != nil { + if err := GenYamlCustom(cmd, f); err != nil { return err } return nil } // GenYamlCustom creates custom yaml output -func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error { +func GenYamlCustom(cmd *cobra.Command, w io.Writer) error { cliDoc := cmdDoc{} cliDoc.Name = cmd.CommandPath() diff --git a/gometalinter.json b/gometalinter.json index 9ba9ea47a5..873f9a2bd8 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -1,6 +1,6 @@ { "Vendor": true, - "Deadline": "3m", + "Deadline": "5m", "Sort": ["linter", "severity", "path"], "Exclude": ["cli/compose/schema/bindata.go"], @@ -16,6 +16,7 @@ "lll", "misspell", "unconvert", + "unparam", "unused", "vet" ], From 3724fb7f37c81e050ca9d66c79c6026b928af884 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 9 Jun 2017 17:42:16 -0400 Subject: [PATCH 5/6] Add gosimple lint Signed-off-by: Daniel Nephin --- cli/command/container/exec.go | 7 +------ cli/command/container/opts.go | 2 +- cli/command/formatter/disk_usage.go | 2 +- cli/command/service/logs.go | 2 +- cli/command/service/opts.go | 2 +- cli/command/stack/deploy_composefile.go | 5 +---- cli/command/stack/list.go | 2 +- cli/command/system/info.go | 2 +- cli/compose/convert/service.go | 7 ++----- cli/config/credentials/native_store.go | 2 +- cli/internal/test/store.go | 3 +-- gometalinter.json | 3 ++- opts/weightdevice.go | 7 +------ 13 files changed, 15 insertions(+), 31 deletions(-) diff --git a/cli/command/container/exec.go b/cli/command/container/exec.go index 843b609a0e..bbcd34ae0c 100644 --- a/cli/command/container/exec.go +++ b/cli/command/container/exec.go @@ -111,12 +111,7 @@ func runExec(dockerCli command.Cli, options *execOptions, container string, exec Tty: execConfig.Tty, } - if err := client.ContainerExecStart(ctx, execID, execStartCheck); err != nil { - return err - } - // For now don't print this - wait for when we support exec wait() - // fmt.Fprintf(dockerCli.Out(), "%s\n", execID) - return nil + return client.ContainerExecStart(ctx, execID, execStartCheck) } // Interactive exec requested. diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 2b7471b352..82d7426c75 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -23,7 +23,7 @@ import ( ) var ( - deviceCgroupRuleRegexp = regexp.MustCompile("^[acb] ([0-9]+|\\*):([0-9]+|\\*) [rwm]{1,3}$") + deviceCgroupRuleRegexp = regexp.MustCompile(`^[acb] ([0-9]+|\*):([0-9]+|\*) [rwm]{1,3}$`) ) // containerOptions is a data object with all the options for creating a container diff --git a/cli/command/formatter/disk_usage.go b/cli/command/formatter/disk_usage.go index caea53f924..9a3b4b9fe6 100644 --- a/cli/command/formatter/disk_usage.go +++ b/cli/command/formatter/disk_usage.go @@ -65,7 +65,7 @@ reclaimable: {{.Reclaimable}} } func (ctx *DiskUsageContext) Write() (err error) { - if ctx.Verbose == false { + if !ctx.Verbose { ctx.buffer = bytes.NewBufferString("") ctx.preFormat() diff --git a/cli/command/service/logs.go b/cli/command/service/logs.go index fbefa5f52e..3d3b3f1d46 100644 --- a/cli/command/service/logs.go +++ b/cli/command/service/logs.go @@ -164,7 +164,7 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { // getMaxLength gets the maximum length of the number in base 10 func getMaxLength(i int) int { - return len(strconv.FormatInt(int64(i), 10)) + return len(strconv.Itoa(i)) } type taskFormatter struct { diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index 5e70863f01..5d1595b055 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -354,7 +354,7 @@ func convertNetworks(ctx context.Context, apiClient client.NetworkAPIClient, net if err != nil { return nil, err } - netAttach = append(netAttach, swarm.NetworkAttachmentConfig{Target: net.Target, Aliases: net.Aliases, DriverOpts: net.DriverOpts}) + netAttach = append(netAttach, swarm.NetworkAttachmentConfig(net)) } sort.Sort(byNetworkTarget(netAttach)) return netAttach, nil diff --git a/cli/command/stack/deploy_composefile.go b/cli/command/stack/deploy_composefile.go index e8cab8fa4e..8e5dfed4d5 100644 --- a/cli/command/stack/deploy_composefile.go +++ b/cli/command/stack/deploy_composefile.go @@ -134,10 +134,7 @@ func getConfigDetails(composefile string) (composetypes.ConfigDetails, error) { // TODO: support multiple files details.ConfigFiles = []composetypes.ConfigFile{*configFile} details.Environment, err = buildEnvironment(os.Environ()) - if err != nil { - return details, err - } - return details, nil + return details, err } func buildEnvironment(env []string) (map[string]string, error) { diff --git a/cli/command/stack/list.go b/cli/command/stack/list.go index 4560a98ec9..26566f6cb2 100644 --- a/cli/command/stack/list.go +++ b/cli/command/stack/list.go @@ -69,7 +69,7 @@ func getStacks(ctx context.Context, apiclient client.APIClient) ([]*formatter.St if err != nil { return nil, err } - m := make(map[string]*formatter.Stack, 0) + m := make(map[string]*formatter.Stack) for _, service := range services { labels := service.Spec.Labels name, ok := labels[convert.LabelNamespace] diff --git a/cli/command/system/info.go b/cli/command/system/info.go index 55b867b296..f2a404e905 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -263,7 +263,7 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error { if info.RegistryConfig != nil && (len(info.RegistryConfig.InsecureRegistryCIDRs) > 0 || len(info.RegistryConfig.IndexConfigs) > 0) { fmt.Fprintln(dockerCli.Out(), "Insecure Registries:") for _, registry := range info.RegistryConfig.IndexConfigs { - if registry.Secure == false { + if !registry.Secure { fmt.Fprintf(dockerCli.Out(), " %s\n", registry.Name) } } diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 75c86e9e64..730f5e1ee5 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -563,9 +563,6 @@ func convertCredentialSpec(spec composetypes.CredentialSpecConfig) (*swarm.Crede if spec.File != "" && spec.Registry != "" { return nil, errors.New("Invalid credential spec - must provide one of `File` or `Registry`") } - - return &swarm.CredentialSpec{ - File: spec.File, - Registry: spec.Registry, - }, nil + swarmCredSpec := swarm.CredentialSpec(spec) + return &swarmCredSpec, nil } diff --git a/cli/config/credentials/native_store.go b/cli/config/credentials/native_store.go index 15bb0e912f..cef34db92f 100644 --- a/cli/config/credentials/native_store.go +++ b/cli/config/credentials/native_store.go @@ -73,7 +73,7 @@ func (c *nativeStore) GetAll() (map[string]types.AuthConfig, error) { if err != nil { return nil, err } - ac, _ := fileConfigs[registry] // might contain Email + ac := fileConfigs[registry] // might contain Email ac.Username = creds.Username ac.Password = creds.Password ac.IdentityToken = creds.IdentityToken diff --git a/cli/internal/test/store.go b/cli/internal/test/store.go index 28e52bab05..e5b3de7abb 100644 --- a/cli/internal/test/store.go +++ b/cli/internal/test/store.go @@ -53,8 +53,7 @@ func (c *fakeStore) Get(serverAddress string) (types.AuthConfig, error) { if c.getFunc != nil { return c.getFunc(serverAddress) } - authConfig, _ := c.store[serverAddress] - return authConfig, nil + return c.store[serverAddress], nil } func (c *fakeStore) GetAll() (map[string]types.AuthConfig, error) { diff --git a/gometalinter.json b/gometalinter.json index 873f9a2bd8..4791bb01fa 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -1,6 +1,6 @@ { "Vendor": true, - "Deadline": "5m", + "Deadline": "8m", "Sort": ["linter", "severity", "path"], "Exclude": ["cli/compose/schema/bindata.go"], @@ -11,6 +11,7 @@ "gofmt", "goimports", "golint", + "gosimple", "ineffassign", "interfacer", "lll", diff --git a/opts/weightdevice.go b/opts/weightdevice.go index 7e3d064f27..46ce9b6567 100644 --- a/opts/weightdevice.go +++ b/opts/weightdevice.go @@ -75,12 +75,7 @@ func (opt *WeightdeviceOpt) String() string { // GetList returns a slice of pointers to WeightDevices. func (opt *WeightdeviceOpt) GetList() []*blkiodev.WeightDevice { - var weightdevice []*blkiodev.WeightDevice - for _, v := range opt.values { - weightdevice = append(weightdevice, v) - } - - return weightdevice + return opt.values } // Type returns the option type From 4881ef507fe7a6c3ff7c06c112cfb4025265ae3e Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 14 Jun 2017 17:30:45 -0700 Subject: [PATCH 6/6] Use a fork of gometalinter Until https://github.com/alecthomas/gometalinter/pull/289 is merged. This reduces the runtime of the linter by 50x Signed-off-by: Daniel Nephin --- dockerfiles/Dockerfile.lint | 2 +- gometalinter.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 71ea437914..240af474c5 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -2,7 +2,7 @@ FROM golang:1.8.3-alpine RUN apk add -U git -RUN go get -u gopkg.in/alecthomas/gometalinter.v1 && \ +RUN go get -u gopkg.in/dnephin/gometalinter.v1 && \ mv /go/bin/gometalinter.v1 /usr/local/bin/gometalinter && \ gometalinter --install diff --git a/gometalinter.json b/gometalinter.json index 4791bb01fa..b5956dca60 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -1,6 +1,6 @@ { "Vendor": true, - "Deadline": "8m", + "Deadline": "2m", "Sort": ["linter", "severity", "path"], "Exclude": ["cli/compose/schema/bindata.go"],