From 690ef8af798b44947362b30c339ad0664adb13bd Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 2 May 2017 15:35:25 -0400 Subject: [PATCH 1/5] Enable golint Signed-off-by: Daniel Nephin --- cli/command/container/export.go | 2 +- cli/command/container/start.go | 4 ++-- cli/command/container/update.go | 2 +- cli/command/image/save.go | 2 +- cli/command/node/ps.go | 2 +- cli/command/service/ps.go | 2 +- cli/command/stack/deploy.go | 2 +- cli/command/stack/ps.go | 2 +- cli/command/task/print.go | 2 +- gometalinter.json | 4 ++-- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/command/container/export.go b/cli/command/container/export.go index 4b2c293a6c..700f557624 100644 --- a/cli/command/container/export.go +++ b/cli/command/container/export.go @@ -38,7 +38,7 @@ func NewExportCommand(dockerCli *command.DockerCli) *cobra.Command { func runExport(dockerCli *command.DockerCli, opts exportOptions) error { if opts.output == "" && dockerCli.Out().IsTerminal() { - return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.") + return errors.New("cowardly refusing to save to a terminal. Use the -o flag or redirect") } clnt := dockerCli.Client() diff --git a/cli/command/container/start.go b/cli/command/container/start.go index e6e5b595b1..08d8023f55 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -59,7 +59,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error { // We're going to attach to a container. // 1. Ensure we only have one container. if len(opts.containers) > 1 { - return errors.New("You cannot start and attach multiple containers at once.") + return errors.New("you cannot start and attach multiple containers at once") } // 2. Attach to the container. @@ -143,7 +143,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error { } } else if opts.checkpoint != "" { if len(opts.containers) > 1 { - return errors.New("You cannot restore multiple containers at once.") + return errors.New("you cannot restore multiple containers at once") } container := opts.containers[0] startOptions := types.ContainerStartOptions{ diff --git a/cli/command/container/update.go b/cli/command/container/update.go index dd452dc01e..3743ad5c59 100644 --- a/cli/command/container/update.go +++ b/cli/command/container/update.go @@ -77,7 +77,7 @@ func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error { var err error if opts.nFlag == 0 { - return errors.New("You must provide one or more flags when using this command.") + return errors.New("you must provide one or more flags when using this command") } var restartPolicy containertypes.RestartPolicy diff --git a/cli/command/image/save.go b/cli/command/image/save.go index 37325edead..cb049d5eaf 100644 --- a/cli/command/image/save.go +++ b/cli/command/image/save.go @@ -38,7 +38,7 @@ func NewSaveCommand(dockerCli *command.DockerCli) *cobra.Command { func runSave(dockerCli *command.DockerCli, opts saveOptions) error { if opts.output == "" && dockerCli.Out().IsTerminal() { - return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.") + return errors.New("cowardly refusing to save to a terminal. Use the -o flag or redirect") } responseBody, err := dockerCli.Client().ImageSave(context.Background(), opts.images) diff --git a/cli/command/node/ps.go b/cli/command/node/ps.go index 0e1aa6bd41..37346ce862 100644 --- a/cli/command/node/ps.go +++ b/cli/command/node/ps.go @@ -96,7 +96,7 @@ func runPs(dockerCli command.Cli, opts psOptions) error { } if len(errs) == 0 || len(tasks) != 0 { - if err := task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format); err != nil { + if err := task.Print(ctx, dockerCli, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format); err != nil { errs = append(errs, err.Error()) } } diff --git a/cli/command/service/ps.go b/cli/command/service/ps.go index 51a00638bc..624873815a 100644 --- a/cli/command/service/ps.go +++ b/cli/command/service/ps.go @@ -119,5 +119,5 @@ func runPS(dockerCli *command.DockerCli, opts psOptions) error { } } - return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format) + return task.Print(ctx, dockerCli, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format) } diff --git a/cli/command/stack/deploy.go b/cli/command/stack/deploy.go index 1bef0e7f4a..5817e35c51 100644 --- a/cli/command/stack/deploy.go +++ b/cli/command/stack/deploy.go @@ -72,7 +72,7 @@ func checkDaemonIsSwarmManager(ctx context.Context, dockerCli *command.DockerCli return err } if !info.Swarm.ControlAvailable { - return errors.New("This node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again.") + return errors.New("this node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again") } return nil } diff --git a/cli/command/stack/ps.go b/cli/command/stack/ps.go index a09e7fa8a8..45df793e80 100644 --- a/cli/command/stack/ps.go +++ b/cli/command/stack/ps.go @@ -72,5 +72,5 @@ func runPS(dockerCli *command.DockerCli, opts psOptions) error { } } - return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format) + return task.Print(ctx, dockerCli, tasks, idresolver.New(client, opts.noResolve), !opts.noTrunc, opts.quiet, format) } diff --git a/cli/command/task/print.go b/cli/command/task/print.go index 5b96854ffe..658c0e5510 100644 --- a/cli/command/task/print.go +++ b/cli/command/task/print.go @@ -35,7 +35,7 @@ func (t tasksBySlot) Less(i, j int) bool { // Print task information in a format. // Besides this, command `docker node ps ` // and `docker stack ps` will call this, too. -func Print(dockerCli command.Cli, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, trunc, quiet bool, format string) error { +func Print(ctx context.Context, dockerCli command.Cli, tasks []swarm.Task, resolver *idresolver.IDResolver, trunc, quiet bool, format string) error { sort.Stable(tasksBySlot(tasks)) names := map[string]string{} diff --git a/gometalinter.json b/gometalinter.json index f3aa2725cb..4e10e547f5 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -1,8 +1,8 @@ { "Vendor": true, - "Sort": ["linter", "severity"], + "Sort": ["linter", "severity", "path"], "Exclude": ["cli/compose/schema/bindata.go"], "DisableAll": true, - "Enable": ["gofmt", "vet"] + "Enable": ["gofmt", "vet", "golint"] } From 1378bf3dbea205de955cebcf349548f917c852ad Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 2 May 2017 15:36:45 -0400 Subject: [PATCH 2/5] Add goimports to linting Signed-off-by: Daniel Nephin --- cli/command/formatter/history_test.go | 1 + client/image_search_test.go | 1 + client/utils.go | 3 ++- gometalinter.json | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/command/formatter/history_test.go b/cli/command/formatter/history_test.go index ce80dc9b8b..97ebcfdde1 100644 --- a/cli/command/formatter/history_test.go +++ b/cli/command/formatter/history_test.go @@ -7,6 +7,7 @@ import ( "time" "bytes" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringutils" diff --git a/client/image_search_test.go b/client/image_search_test.go index b17bbd8343..a64e0c458b 100644 --- a/client/image_search_test.go +++ b/client/image_search_test.go @@ -11,6 +11,7 @@ import ( "golang.org/x/net/context" "encoding/json" + "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/registry" diff --git a/client/utils.go b/client/utils.go index 23d520ecb8..f3d8877df7 100644 --- a/client/utils.go +++ b/client/utils.go @@ -1,9 +1,10 @@ package client import ( - "github.com/docker/docker/api/types/filters" "net/url" "regexp" + + "github.com/docker/docker/api/types/filters" ) var headerRegexp = regexp.MustCompile(`\ADocker/.+\s\((.+)\)\z`) diff --git a/gometalinter.json b/gometalinter.json index 4e10e547f5..c3ae185dbd 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -4,5 +4,5 @@ "Exclude": ["cli/compose/schema/bindata.go"], "DisableAll": true, - "Enable": ["gofmt", "vet", "golint"] + "Enable": ["gofmt", "vet", "golint", "goimports"] } From 8f73a12f9b878961e9888470353fd0eb72e4b6b9 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 2 May 2017 15:48:52 -0400 Subject: [PATCH 3/5] Add deadcode linter. Signed-off-by: Daniel Nephin --- cli/command/events_utils.go | 2 -- cli/command/formatter/secret.go | 1 - cli/command/service/update.go | 10 ---------- cli/command/swarm/opts.go | 1 - cli/compose/loader/loader.go | 5 ----- client/client_mock_test.go | 8 ++++++++ client/transport.go | 8 -------- gometalinter.json | 8 +++++++- 8 files changed, 15 insertions(+), 28 deletions(-) diff --git a/cli/command/events_utils.go b/cli/command/events_utils.go index e710c97576..c271b20508 100644 --- a/cli/command/events_utils.go +++ b/cli/command/events_utils.go @@ -7,8 +7,6 @@ import ( eventtypes "github.com/docker/docker/api/types/events" ) -type eventProcessor func(eventtypes.Message, error) error - // EventHandler is abstract interface for user to customize // own handle functions of each type of events type EventHandler interface { diff --git a/cli/command/formatter/secret.go b/cli/command/formatter/secret.go index 7ec6f9a62e..46c97e2393 100644 --- a/cli/command/formatter/secret.go +++ b/cli/command/formatter/secret.go @@ -12,7 +12,6 @@ import ( const ( defaultSecretTableFormat = "table {{.ID}}\t{{.Name}}\t{{.CreatedAt}}\t{{.UpdatedAt}}" secretIDHeader = "ID" - secretNameHeader = "NAME" secretCreatedHeader = "CREATED" secretUpdatedHeader = "UPDATED" ) diff --git a/cli/command/service/update.go b/cli/command/service/update.go index 2845086217..0686850c94 100644 --- a/cli/command/service/update.go +++ b/cli/command/service/update.go @@ -16,7 +16,6 @@ import ( "github.com/docker/docker/api/types/versions" "github.com/docker/docker/opts" runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/go-connections/nat" "github.com/docker/swarmkit/api/defaults" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -585,10 +584,6 @@ func envKey(value string) string { return kv[0] } -func itemKey(value string) string { - return value -} - func buildToRemoveSet(flags *pflag.FlagSet, flag string) map[string]struct{} { var empty struct{} toRemove := make(map[string]struct{}) @@ -826,11 +821,6 @@ func equalPublishMode(mode1, mode2 swarm.PortConfigPublishMode) bool { (mode2 == swarm.PortConfigPublishMode("") && mode1 == swarm.PortConfigPublishModeIngress) } -func equalPort(targetPort nat.Port, port swarm.PortConfig) bool { - return (string(port.Protocol) == targetPort.Proto() && - port.TargetPort == uint32(targetPort.Int())) -} - func updateReplicas(flags *pflag.FlagSet, serviceMode *swarm.ServiceMode) error { if !flags.Changed(flagReplicas) { return nil diff --git a/cli/command/swarm/opts.go b/cli/command/swarm/opts.go index 6eddddccae..225d38d110 100644 --- a/cli/command/swarm/opts.go +++ b/cli/command/swarm/opts.go @@ -26,7 +26,6 @@ const ( flagExternalCA = "external-ca" flagMaxSnapshots = "max-snapshots" flagSnapshotInterval = "snapshot-interval" - flagLockKey = "lock-key" flagAutolock = "autolock" flagAvailability = "availability" ) diff --git a/cli/compose/loader/loader.go b/cli/compose/loader/loader.go index c6d92e4f26..a6a3409942 100644 --- a/cli/compose/loader/loader.go +++ b/cli/compose/loader/loader.go @@ -4,7 +4,6 @@ import ( "fmt" "path" "reflect" - "regexp" "sort" "strings" @@ -23,10 +22,6 @@ import ( yaml "gopkg.in/yaml.v2" ) -var ( - fieldNameRegexp = regexp.MustCompile("[A-Z][a-z0-9]+") -) - // ParseYAML reads the bytes from a file, parses the bytes into a mapping // structure, and returns it. func ParseYAML(source []byte) (map[string]interface{}, error) { diff --git a/client/client_mock_test.go b/client/client_mock_test.go index 0ab935d536..e75c3ecbfc 100644 --- a/client/client_mock_test.go +++ b/client/client_mock_test.go @@ -9,6 +9,14 @@ import ( "github.com/docker/docker/api/types" ) +// transportFunc allows us to inject a mock transport for testing. We define it +// here so we can detect the tlsconfig and return nil for only this type. +type transportFunc func(*http.Request) (*http.Response, error) + +func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) { + return tf(req) +} + func newMockClient(doer func(*http.Request) (*http.Response, error)) *http.Client { return &http.Client{ Transport: transportFunc(doer), diff --git a/client/transport.go b/client/transport.go index 401ab15d30..73f6ef7b4d 100644 --- a/client/transport.go +++ b/client/transport.go @@ -5,14 +5,6 @@ import ( "net/http" ) -// transportFunc allows us to inject a mock transport for testing. We define it -// here so we can detect the tlsconfig and return nil for only this type. -type transportFunc func(*http.Request) (*http.Response, error) - -func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) { - return tf(req) -} - // resolveTLSConfig attempts to resolve the TLS configuration from the // RoundTripper. func resolveTLSConfig(transport http.RoundTripper) *tls.Config { diff --git a/gometalinter.json b/gometalinter.json index c3ae185dbd..053fd2c155 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -4,5 +4,11 @@ "Exclude": ["cli/compose/schema/bindata.go"], "DisableAll": true, - "Enable": ["gofmt", "vet", "golint", "goimports"] + "Enable": [ + "gofmt", + "vet", + "golint", + "goimports", + "deadcode" + ] } From 08af0f28c5a77058489bd1ef02c666c6259e0fa0 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 2 May 2017 16:14:43 -0400 Subject: [PATCH 4/5] Add gocycle lint Whitelist some existing offenders, and use a high limit for now. This limit should decrese over time. Signed-off-by: Daniel Nephin --- cli/command/container/exec.go | 1 + cli/command/container/hijack.go | 1 + cli/command/container/opts.go | 1 + cli/command/container/opts_test.go | 3 +++ cli/command/container/run.go | 1 + cli/command/container/start.go | 1 + cli/command/container/stats.go | 1 + cli/command/image/build.go | 1 + cli/command/image/trust.go | 1 + cli/command/network/create.go | 1 + cli/command/service/progress/progress.go | 2 ++ cli/command/service/update.go | 2 ++ cli/command/system/info.go | 1 + client/request.go | 1 + gometalinter.json | 7 +++++-- 15 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cli/command/container/exec.go b/cli/command/container/exec.go index 351fec3cc2..964d5c5ba2 100644 --- a/cli/command/container/exec.go +++ b/cli/command/container/exec.go @@ -62,6 +62,7 @@ func NewExecCommand(dockerCli *command.DockerCli) *cobra.Command { return cmd } +// nolint: gocyclo func runExec(dockerCli *command.DockerCli, opts *execOptions, container string, execCmd []string) error { execConfig, err := parseExec(opts, execCmd) // just in case the ParseExec does not exit diff --git a/cli/command/container/hijack.go b/cli/command/container/hijack.go index a119e81b3c..952e31998d 100644 --- a/cli/command/container/hijack.go +++ b/cli/command/container/hijack.go @@ -14,6 +14,7 @@ import ( // holdHijackedConnection handles copying input to and output from streams to the // connection +// nolint: gocyclo func holdHijackedConnection(ctx context.Context, streams command.Streams, tty bool, inputStream io.ReadCloser, outputStream, errorStream io.Writer, resp types.HijackedResponse) error { var ( err error diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 7480bfaced..30c356a050 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -298,6 +298,7 @@ type containerConfig struct { // parse parses the args for the specified command and generates a Config, // a HostConfig and returns them with the specified command. // If the specified args are not valid, it will return an error. +// nolint: gocyclo func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, error) { var ( attachStdin = copts.attach.Get("stdin") diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index 2d0049768a..429fee7c51 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -86,6 +86,7 @@ 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) @@ -129,6 +130,7 @@ func TestParseRunAttach(t *testing.T) { } } +// nolint: gocyclo func TestParseRunVolumes(t *testing.T) { // A single volume @@ -614,6 +616,7 @@ func TestParseEntryPoint(t *testing.T) { // This tests the cases for binds which are generated through // DecodeContainerConfig rather than Parse() +// nolint: gocyclo func TestDecodeContainerConfigVolumes(t *testing.T) { // Root to root diff --git a/cli/command/container/run.go b/cli/command/container/run.go index c6b85059df..9cd0b1d812 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -93,6 +93,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions return runContainer(dockerCli, opts, copts, containerConfig) } +// nolint: gocyclo func runContainer(dockerCli *command.DockerCli, opts *runOptions, copts *containerOptions, containerConfig *containerConfig) error { config := containerConfig.Config hostConfig := containerConfig.HostConfig diff --git a/cli/command/container/start.go b/cli/command/container/start.go index 08d8023f55..efc83e78f0 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -52,6 +52,7 @@ func NewStartCommand(dockerCli *command.DockerCli) *cobra.Command { return cmd } +// nolint: gocyclo func runStart(dockerCli *command.DockerCli, opts *startOptions) error { ctx, cancelFun := context.WithCancel(context.Background()) diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index 2b01367fb3..da6a6d059b 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -48,6 +48,7 @@ func NewStatsCommand(dockerCli *command.DockerCli) *cobra.Command { // runStats displays a live stream of resource usage statistics for one or more containers. // This shows real-time information on CPU usage, memory usage, and network I/O. +// nolint: gocyclo func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { showAll := len(opts.containers) == 0 closeChan := make(chan error) diff --git a/cli/command/image/build.go b/cli/command/image/build.go index 88f9405957..93e6f194b8 100644 --- a/cli/command/image/build.go +++ b/cli/command/image/build.go @@ -143,6 +143,7 @@ func (out *lastProgressOutput) WriteProgress(prog progress.Progress) error { return out.output.WriteProgress(prog) } +// nolint: gocyclo func runBuild(dockerCli *command.DockerCli, options buildOptions) error { var ( buildCtx io.ReadCloser diff --git a/cli/command/image/trust.go b/cli/command/image/trust.go index 9f0f6c70d4..282fcffa3d 100644 --- a/cli/command/image/trust.go +++ b/cli/command/image/trust.go @@ -41,6 +41,7 @@ func trustedPush(ctx context.Context, cli *command.DockerCli, repoInfo *registry } // PushTrustedReference pushes a canonical reference to the trust server. +// nolint: gocyclo func PushTrustedReference(cli *command.DockerCli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, in io.Reader) error { // If it is a trusted push we would like to find the target entry which match the // tag provided in the function and then do an AddTarget later. diff --git a/cli/command/network/create.go b/cli/command/network/create.go index 3a18aa9d7e..bd8721ce57 100644 --- a/cli/command/network/create.go +++ b/cli/command/network/create.go @@ -113,6 +113,7 @@ func runCreate(dockerCli *command.DockerCli, opts createOptions) error { // possible to correlate the various related parameters and consolidate them. // consolidateIpam consolidates subnets, ip-ranges, gateways and auxiliary addresses into // structured ipam data. +// nolint: gocyclo func consolidateIpam(subnets, ranges, gateways []string, auxaddrs map[string]string) ([]network.IPAMConfig, error) { if len(subnets) < len(ranges) || len(subnets) < len(gateways) { return nil, errors.Errorf("every ip-range or gateway must have a corresponding subnet") diff --git a/cli/command/service/progress/progress.go b/cli/command/service/progress/progress.go index 2c2ea98b3f..61c040df5e 100644 --- a/cli/command/service/progress/progress.go +++ b/cli/command/service/progress/progress.go @@ -59,6 +59,7 @@ func stateToProgress(state swarm.TaskState, rollback bool) int64 { } // ServiceProgress outputs progress information for convergence of a service. +// nolint: gocyclo func ServiceProgress(ctx context.Context, client client.APIClient, serviceID string, progressWriter io.WriteCloser) error { defer progressWriter.Close() @@ -240,6 +241,7 @@ type replicatedProgressUpdater struct { done bool } +// nolint: gocyclo func (u *replicatedProgressUpdater) update(service swarm.Service, tasks []swarm.Task, activeNodes map[string]swarm.Node, rollback bool) (bool, error) { if service.Spec.Mode.Replicated == nil || service.Spec.Mode.Replicated.Replicas == nil { return false, errors.New("no replica count") diff --git a/cli/command/service/update.go b/cli/command/service/update.go index 0686850c94..d960fab5ea 100644 --- a/cli/command/service/update.go +++ b/cli/command/service/update.go @@ -97,6 +97,7 @@ func newListOptsVar() *opts.ListOpts { return opts.NewListOptsRef(&[]string{}, nil) } +// nolint: gocyclo func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *serviceOptions, serviceID string) error { apiClient := dockerCli.Client() ctx := context.Background() @@ -211,6 +212,7 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *service return waitOnService(ctx, dockerCli, serviceID, opts) } +// nolint: gocyclo func updateService(ctx context.Context, apiClient client.APIClient, flags *pflag.FlagSet, spec *swarm.ServiceSpec) error { updateString := func(flag string, field *string) { if flags.Changed(flag) { diff --git a/cli/command/system/info.go b/cli/command/system/info.go index c37584bd42..8c5dec3f5a 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -54,6 +54,7 @@ func runInfo(dockerCli *command.DockerCli, opts *infoOptions) error { return formatInfo(dockerCli, info, opts.format) } +// nolint: gocyclo func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error { fmt.Fprintf(dockerCli.Out(), "Containers: %d\n", info.Containers) fmt.Fprintf(dockerCli.Out(), " Running: %d\n", info.ContainersRunning) diff --git a/client/request.go b/client/request.go index 6457b316a3..16c5c24bf8 100644 --- a/client/request.go +++ b/client/request.go @@ -121,6 +121,7 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u return cli.doRequest(ctx, req) } +// nolint: gocyclo func (cli *Client) doRequest(ctx context.Context, req *http.Request) (serverResponse, error) { serverResp := serverResponse{statusCode: -1} diff --git a/gometalinter.json b/gometalinter.json index 053fd2c155..a04fd837b3 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -9,6 +9,9 @@ "vet", "golint", "goimports", - "deadcode" - ] + "deadcode", + "gocyclo" + ], + + "Cyclo": 19 } From b86533c479c3ca9b32713521be914eaeb13d97da Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 2 May 2017 16:22:13 -0400 Subject: [PATCH 5/5] Add ineffassign linter. Signed-off-by: Daniel Nephin --- cli/command/formatter/history.go | 7 ++----- cli/command/service/logs.go | 4 ++-- cli/command/task/print.go | 2 +- cli/config/config_test.go | 3 +++ gometalinter.json | 11 ++++++----- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/cli/command/formatter/history.go b/cli/command/formatter/history.go index 2b7de399a0..ed2af4637e 100644 --- a/cli/command/formatter/history.go +++ b/cli/command/formatter/history.go @@ -99,13 +99,10 @@ func (c *historyContext) CreatedBy() string { } func (c *historyContext) Size() string { - size := "" if c.human { - size = units.HumanSizeWithPrecision(float64(c.h.Size), 3) - } else { - size = strconv.FormatInt(c.h.Size, 10) + return units.HumanSizeWithPrecision(float64(c.h.Size), 3) } - return size + return strconv.FormatInt(c.h.Size, 10) } func (c *historyContext) Comment() string { diff --git a/cli/command/service/logs.go b/cli/command/service/logs.go index f64911d7fd..c4ac557021 100644 --- a/cli/command/service/logs.go +++ b/cli/command/service/logs.go @@ -92,7 +92,7 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { if !client.IsErrServiceNotFound(err) { return err } - task, _, err := cli.TaskInspectWithRaw(ctx, opts.target) + task, _, _ := cli.TaskInspectWithRaw(ctx, opts.target) tty = task.Spec.ContainerSpec.TTY // TODO(dperny) hot fix until we get a nice details system squared away, // ignores details (including task context) if we have a TTY log @@ -112,7 +112,7 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { return err } maxLength = getMaxLength(task.Slot) - responseBody, err = cli.TaskLogs(ctx, opts.target, options) + responseBody, _ = cli.TaskLogs(ctx, opts.target, options) } else { tty = service.Spec.TaskTemplate.ContainerSpec.TTY // TODO(dperny) hot fix until we get a nice details system squared away, diff --git a/cli/command/task/print.go b/cli/command/task/print.go index 658c0e5510..2376ecf803 100644 --- a/cli/command/task/print.go +++ b/cli/command/task/print.go @@ -59,7 +59,7 @@ func Print(ctx context.Context, dockerCli command.Cli, tasks []swarm.Task, resol return err } - name := "" + var name string if task.Slot != 0 { name = fmt.Sprintf("%v.%v", serviceName, task.Slot) } else { diff --git a/cli/config/config_test.go b/cli/config/config_test.go index 41be45ffd9..7eab2efaa3 100644 --- a/cli/config/config_test.go +++ b/cli/config/config_test.go @@ -9,6 +9,7 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/docker/pkg/homedir" + "github.com/stretchr/testify/require" ) func TestEmptyConfigDir(t *testing.T) { @@ -543,6 +544,7 @@ func TestJSONSaveWithNoFile(t *testing.T) { "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}" }` config, err := LoadFromReader(strings.NewReader(js)) + require.NoError(t, err) err = config.Save() if err == nil { t.Fatalf("Expected error. File should not have been able to save with no file name.") @@ -583,6 +585,7 @@ func TestLegacyJSONSaveWithNoFile(t *testing.T) { js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"user@example.com"}}` config, err := LegacyLoadFromReader(strings.NewReader(js)) + require.NoError(t, err) err = config.Save() if err == nil { t.Fatalf("Expected error. File should not have been able to save with no file name.") diff --git a/gometalinter.json b/gometalinter.json index a04fd837b3..80d60b063f 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -5,12 +5,13 @@ "DisableAll": true, "Enable": [ - "gofmt", - "vet", - "golint", - "goimports", "deadcode", - "gocyclo" + "gocyclo", + "gofmt", + "goimports", + "golint", + "ineffassign", + "vet" ], "Cyclo": 19