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 <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-05-02 16:14:43 -04:00
parent 8f73a12f9b
commit 08af0f28c5
15 changed files with 23 additions and 2 deletions

View File

@ -62,6 +62,7 @@ func NewExecCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
// nolint: gocyclo
func runExec(dockerCli *command.DockerCli, opts *execOptions, container string, execCmd []string) error { func runExec(dockerCli *command.DockerCli, opts *execOptions, container string, execCmd []string) error {
execConfig, err := parseExec(opts, execCmd) execConfig, err := parseExec(opts, execCmd)
// just in case the ParseExec does not exit // just in case the ParseExec does not exit

View File

@ -14,6 +14,7 @@ import (
// holdHijackedConnection handles copying input to and output from streams to the // holdHijackedConnection handles copying input to and output from streams to the
// connection // connection
// nolint: gocyclo
func holdHijackedConnection(ctx context.Context, streams command.Streams, tty bool, inputStream io.ReadCloser, outputStream, errorStream io.Writer, resp types.HijackedResponse) error { func holdHijackedConnection(ctx context.Context, streams command.Streams, tty bool, inputStream io.ReadCloser, outputStream, errorStream io.Writer, resp types.HijackedResponse) error {
var ( var (
err error err error

View File

@ -298,6 +298,7 @@ type containerConfig struct {
// parse parses the args for the specified command and generates a Config, // parse parses the args for the specified command and generates a Config,
// a HostConfig and returns them with the specified command. // a HostConfig and returns them with the specified command.
// If the specified args are not valid, it will return an error. // If the specified args are not valid, it will return an error.
// nolint: gocyclo
func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, error) { func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, error) {
var ( var (
attachStdin = copts.attach.Get("stdin") attachStdin = copts.attach.Get("stdin")

View File

@ -86,6 +86,7 @@ func TestParseRunLinks(t *testing.T) {
} }
} }
// nolint: gocyclo
func TestParseRunAttach(t *testing.T) { func TestParseRunAttach(t *testing.T) {
if config, _ := mustParse(t, "-a stdin"); !config.AttachStdin || config.AttachStdout || config.AttachStderr { 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) 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) { func TestParseRunVolumes(t *testing.T) {
// A single volume // A single volume
@ -614,6 +616,7 @@ func TestParseEntryPoint(t *testing.T) {
// This tests the cases for binds which are generated through // This tests the cases for binds which are generated through
// DecodeContainerConfig rather than Parse() // DecodeContainerConfig rather than Parse()
// nolint: gocyclo
func TestDecodeContainerConfigVolumes(t *testing.T) { func TestDecodeContainerConfigVolumes(t *testing.T) {
// Root to root // Root to root

View File

@ -93,6 +93,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
return runContainer(dockerCli, opts, copts, containerConfig) return runContainer(dockerCli, opts, copts, containerConfig)
} }
// nolint: gocyclo
func runContainer(dockerCli *command.DockerCli, opts *runOptions, copts *containerOptions, containerConfig *containerConfig) error { func runContainer(dockerCli *command.DockerCli, opts *runOptions, copts *containerOptions, containerConfig *containerConfig) error {
config := containerConfig.Config config := containerConfig.Config
hostConfig := containerConfig.HostConfig hostConfig := containerConfig.HostConfig

View File

@ -52,6 +52,7 @@ func NewStartCommand(dockerCli *command.DockerCli) *cobra.Command {
return cmd return cmd
} }
// nolint: gocyclo
func runStart(dockerCli *command.DockerCli, opts *startOptions) error { func runStart(dockerCli *command.DockerCli, opts *startOptions) error {
ctx, cancelFun := context.WithCancel(context.Background()) ctx, cancelFun := context.WithCancel(context.Background())

View File

@ -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. // 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. // This shows real-time information on CPU usage, memory usage, and network I/O.
// nolint: gocyclo
func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { func runStats(dockerCli *command.DockerCli, opts *statsOptions) error {
showAll := len(opts.containers) == 0 showAll := len(opts.containers) == 0
closeChan := make(chan error) closeChan := make(chan error)

View File

@ -143,6 +143,7 @@ func (out *lastProgressOutput) WriteProgress(prog progress.Progress) error {
return out.output.WriteProgress(prog) return out.output.WriteProgress(prog)
} }
// nolint: gocyclo
func runBuild(dockerCli *command.DockerCli, options buildOptions) error { func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
var ( var (
buildCtx io.ReadCloser buildCtx io.ReadCloser

View File

@ -41,6 +41,7 @@ func trustedPush(ctx context.Context, cli *command.DockerCli, repoInfo *registry
} }
// PushTrustedReference pushes a canonical reference to the trust server. // 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 { 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 // 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. // tag provided in the function and then do an AddTarget later.

View File

@ -113,6 +113,7 @@ func runCreate(dockerCli *command.DockerCli, opts createOptions) error {
// possible to correlate the various related parameters and consolidate them. // possible to correlate the various related parameters and consolidate them.
// consolidateIpam consolidates subnets, ip-ranges, gateways and auxiliary addresses into // consolidateIpam consolidates subnets, ip-ranges, gateways and auxiliary addresses into
// structured ipam data. // structured ipam data.
// nolint: gocyclo
func consolidateIpam(subnets, ranges, gateways []string, auxaddrs map[string]string) ([]network.IPAMConfig, error) { func consolidateIpam(subnets, ranges, gateways []string, auxaddrs map[string]string) ([]network.IPAMConfig, error) {
if len(subnets) < len(ranges) || len(subnets) < len(gateways) { if len(subnets) < len(ranges) || len(subnets) < len(gateways) {
return nil, errors.Errorf("every ip-range or gateway must have a corresponding subnet") return nil, errors.Errorf("every ip-range or gateway must have a corresponding subnet")

View File

@ -59,6 +59,7 @@ func stateToProgress(state swarm.TaskState, rollback bool) int64 {
} }
// ServiceProgress outputs progress information for convergence of a service. // 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 { func ServiceProgress(ctx context.Context, client client.APIClient, serviceID string, progressWriter io.WriteCloser) error {
defer progressWriter.Close() defer progressWriter.Close()
@ -240,6 +241,7 @@ type replicatedProgressUpdater struct {
done bool done bool
} }
// nolint: gocyclo
func (u *replicatedProgressUpdater) update(service swarm.Service, tasks []swarm.Task, activeNodes map[string]swarm.Node, rollback bool) (bool, error) { 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 { if service.Spec.Mode.Replicated == nil || service.Spec.Mode.Replicated.Replicas == nil {
return false, errors.New("no replica count") return false, errors.New("no replica count")

View File

@ -97,6 +97,7 @@ func newListOptsVar() *opts.ListOpts {
return opts.NewListOptsRef(&[]string{}, nil) return opts.NewListOptsRef(&[]string{}, nil)
} }
// nolint: gocyclo
func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *serviceOptions, serviceID string) error { func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *serviceOptions, serviceID string) error {
apiClient := dockerCli.Client() apiClient := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
@ -211,6 +212,7 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *service
return waitOnService(ctx, dockerCli, serviceID, opts) return waitOnService(ctx, dockerCli, serviceID, opts)
} }
// nolint: gocyclo
func updateService(ctx context.Context, apiClient client.APIClient, flags *pflag.FlagSet, spec *swarm.ServiceSpec) error { func updateService(ctx context.Context, apiClient client.APIClient, flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
updateString := func(flag string, field *string) { updateString := func(flag string, field *string) {
if flags.Changed(flag) { if flags.Changed(flag) {

View File

@ -54,6 +54,7 @@ func runInfo(dockerCli *command.DockerCli, opts *infoOptions) error {
return formatInfo(dockerCli, info, opts.format) return formatInfo(dockerCli, info, opts.format)
} }
// nolint: gocyclo
func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error { func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error {
fmt.Fprintf(dockerCli.Out(), "Containers: %d\n", info.Containers) fmt.Fprintf(dockerCli.Out(), "Containers: %d\n", info.Containers)
fmt.Fprintf(dockerCli.Out(), " Running: %d\n", info.ContainersRunning) fmt.Fprintf(dockerCli.Out(), " Running: %d\n", info.ContainersRunning)

View File

@ -121,6 +121,7 @@ func (cli *Client) sendRequest(ctx context.Context, method, path string, query u
return cli.doRequest(ctx, req) return cli.doRequest(ctx, req)
} }
// nolint: gocyclo
func (cli *Client) doRequest(ctx context.Context, req *http.Request) (serverResponse, error) { func (cli *Client) doRequest(ctx context.Context, req *http.Request) (serverResponse, error) {
serverResp := serverResponse{statusCode: -1} serverResp := serverResponse{statusCode: -1}

View File

@ -9,6 +9,9 @@
"vet", "vet",
"golint", "golint",
"goimports", "goimports",
"deadcode" "deadcode",
] "gocyclo"
],
"Cyclo": 19
} }