From 08af0f28c5a77058489bd1ef02c666c6259e0fa0 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 2 May 2017 16:14:43 -0400 Subject: [PATCH] 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 }