From d956386b2d0cc28f2f9732aee5ba3c5ab2036d6c Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 26 Sep 2017 12:33:35 -0400 Subject: [PATCH] Update gometalinter The update includes bug fixes in gometalinter and updates to linters, which discovered more linter problems. Signed-off-by: Daniel Nephin --- cli/command/container/hijack.go | 1 + cli/command/container/opts_test.go | 1 + cli/command/image/trust_test.go | 2 ++ cli/command/stack/deploy.go | 5 ++--- cli/command/stack/ps_test.go | 1 + cli/command/swarm/unlock.go | 8 ++------ cli/command/trust/revoke_test.go | 2 ++ cli/command/trust/sign_test.go | 17 ++++++++++++++--- cli/command/trust/view.go | 4 +++- cli/trust/trust_test.go | 2 ++ dockerfiles/Dockerfile.lint | 2 +- docs/yaml/yaml.go | 9 ++++----- gometalinter.json | 8 ++++++-- 13 files changed, 41 insertions(+), 21 deletions(-) diff --git a/cli/command/container/hijack.go b/cli/command/container/hijack.go index 3653f1f9b4..b3ca2e6ad5 100644 --- a/cli/command/container/hijack.go +++ b/cli/command/container/hijack.go @@ -185,6 +185,7 @@ func setRawTerminal(streams command.Streams) error { return streams.Out().SetRawTerminal() } +// nolint: unparam func restoreTerminal(streams command.Streams, in io.Closer) error { streams.In().RestoreTerminal() streams.Out().RestoreTerminal() diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index 08c1d07da3..0aa043839c 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -43,6 +43,7 @@ func TestValidateAttach(t *testing.T) { } } +// nolint: unparam func parseRun(args []string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) { flags := pflag.NewFlagSet("run", pflag.ContinueOnError) flags.SetOutput(ioutil.Discard) diff --git a/cli/command/image/trust_test.go b/cli/command/image/trust_test.go index d173973d88..6356438a3a 100644 --- a/cli/command/image/trust_test.go +++ b/cli/command/image/trust_test.go @@ -12,6 +12,7 @@ import ( "github.com/docker/notary/passphrase" "github.com/docker/notary/trustpinning" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func unsetENV() { @@ -67,6 +68,7 @@ func TestAddTargetToAllSignableRolesError(t *testing.T) { defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) + require.NoError(t, err) target := client.Target{} err = AddTargetToAllSignableRoles(notaryRepo, &target) assert.EqualError(t, err, "client is offline") diff --git a/cli/command/stack/deploy.go b/cli/command/stack/deploy.go index 8e14b70d2f..a6f9ef6377 100644 --- a/cli/command/stack/deploy.go +++ b/cli/command/stack/deploy.go @@ -104,13 +104,12 @@ func checkDaemonIsSwarmManager(ctx context.Context, dockerCli command.Cli) error } // pruneServices removes services that are no longer referenced in the source -func pruneServices(ctx context.Context, dockerCli command.Cli, namespace convert.Namespace, services map[string]struct{}) bool { +func pruneServices(ctx context.Context, dockerCli command.Cli, namespace convert.Namespace, services map[string]struct{}) { client := dockerCli.Client() oldServices, err := getServices(ctx, client, namespace.Name()) if err != nil { fmt.Fprintf(dockerCli.Err(), "Failed to list services: %s", err) - return true } pruneServices := []swarm.Service{} @@ -119,5 +118,5 @@ func pruneServices(ctx context.Context, dockerCli command.Cli, namespace convert pruneServices = append(pruneServices, service) } } - return removeServices(ctx, dockerCli, pruneServices) + removeServices(ctx, dockerCli, pruneServices) } diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index 3bb22609b5..fb7055f09c 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -59,6 +59,7 @@ func TestStackPsEmptyStack(t *testing.T) { }) cmd := newPsCommand(fakeCli) cmd.SetArgs([]string{"foo"}) + cmd.SetOutput(ioutil.Discard) assert.Error(t, cmd.Execute()) assert.EqualError(t, cmd.Execute(), "nothing found in stack: foo") diff --git a/cli/command/swarm/unlock.go b/cli/command/swarm/unlock.go index dd999a7f4b..700a8ed533 100644 --- a/cli/command/swarm/unlock.go +++ b/cli/command/swarm/unlock.go @@ -15,24 +15,20 @@ import ( "golang.org/x/net/context" ) -type unlockOptions struct{} - func newUnlockCommand(dockerCli command.Cli) *cobra.Command { - opts := unlockOptions{} - cmd := &cobra.Command{ Use: "unlock", Short: "Unlock swarm", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return runUnlock(dockerCli, opts) + return runUnlock(dockerCli) }, } return cmd } -func runUnlock(dockerCli command.Cli, opts unlockOptions) error { +func runUnlock(dockerCli command.Cli) error { client := dockerCli.Client() ctx := context.Background() diff --git a/cli/command/trust/revoke_test.go b/cli/command/trust/revoke_test.go index 43c68a30d1..5a6e105b16 100644 --- a/cli/command/trust/revoke_test.go +++ b/cli/command/trust/revoke_test.go @@ -11,6 +11,7 @@ import ( "github.com/docker/notary/passphrase" "github.com/docker/notary/trustpinning" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestTrustRevokeCommandErrors(t *testing.T) { @@ -140,6 +141,7 @@ func TestGetSignableRolesForTargetAndRemoveError(t *testing.T) { defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) + require.NoError(t, err) target := client.Target{} err = getSignableRolesForTargetAndRemove(target, notaryRepo) assert.EqualError(t, err, "client is offline") diff --git a/cli/command/trust/sign_test.go b/cli/command/trust/sign_test.go index d75e212a91..66ed800ba9 100644 --- a/cli/command/trust/sign_test.go +++ b/cli/command/trust/sign_test.go @@ -17,6 +17,7 @@ import ( "github.com/docker/notary/trustpinning" "github.com/docker/notary/tuf/data" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) const passwd = "password" @@ -151,6 +152,7 @@ func TestAddStageSigners(t *testing.T) { NewThreshold: notary.MinThreshold, AddKeys: data.KeyList([]data.PublicKey{userKey}), }) + require.NoError(t, err) expectedChange := changelist.NewTUFChange( changelist.ActionCreate, userRole, @@ -165,6 +167,7 @@ func TestAddStageSigners(t *testing.T) { expectedJSON, err = json.Marshal(&changelist.TUFDelegation{ AddPaths: []string{""}, }) + require.NoError(t, err) expectedChange = changelist.NewTUFChange( changelist.ActionCreate, userRole, @@ -182,6 +185,7 @@ func TestAddStageSigners(t *testing.T) { NewThreshold: notary.MinThreshold, AddKeys: data.KeyList([]data.PublicKey{userKey}), }) + require.NoError(t, err) expectedChange = changelist.NewTUFChange( changelist.ActionCreate, releasesRole, @@ -196,6 +200,7 @@ func TestAddStageSigners(t *testing.T) { expectedJSON, err = json.Marshal(&changelist.TUFDelegation{ AddPaths: []string{""}, }) + require.NoError(t, err) expectedChange = changelist.NewTUFChange( changelist.ActionCreate, releasesRole, @@ -268,18 +273,24 @@ func TestPrettyPrintExistingSignatureInfo(t *testing.T) { assert.Contains(t, fakeCli.OutBuffer().String(), "Existing signatures for tag tagName digest abc123 from:\nAlice, Bob, Carol") } -func TestChangeList(t *testing.T) { +func TestSignCommandChangeListIsCleanedOnError(t *testing.T) { tmpDir, err := ioutil.TempDir("", "docker-sign-test-") assert.NoError(t, err) defer os.RemoveAll(tmpDir) + config.SetDir(tmpDir) - cmd := newSignCommand( - test.NewFakeCli(&fakeClient{})) + cli := test.NewFakeCli(&fakeClient{}) + cli.SetNotaryClient(getLoadedNotaryRepository) + cmd := newSignCommand(cli) cmd.SetArgs([]string{"ubuntu:latest"}) cmd.SetOutput(ioutil.Discard) + err = cmd.Execute() + require.Error(t, err) + notaryRepo, err := client.NewFileCachedRepository(tmpDir, "docker.io/library/ubuntu", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) assert.NoError(t, err) cl, err := notaryRepo.GetChangelist() + require.NoError(t, err) assert.Equal(t, len(cl.List()), 0) } diff --git a/cli/command/trust/view.go b/cli/command/trust/view.go index 18d07585eb..383c03d1ae 100644 --- a/cli/command/trust/view.go +++ b/cli/command/trust/view.go @@ -113,7 +113,9 @@ func lookupTrustInfo(cli command.Cli, remote string) error { // If we do not have additional signers, do not display if len(signerRoleToKeyIDs) > 0 { fmt.Fprintf(cli.Out(), "\nList of signers and their keys for %s:\n\n", strings.Split(remote, ":")[0]) - printSignerInfo(cli.Out(), signerRoleToKeyIDs) + if err := printSignerInfo(cli.Out(), signerRoleToKeyIDs); err != nil { + return err + } } // This will always have the root and targets information diff --git a/cli/trust/trust_test.go b/cli/trust/trust_test.go index 5cd339d358..da9c3a8688 100644 --- a/cli/trust/trust_test.go +++ b/cli/trust/trust_test.go @@ -11,6 +11,7 @@ import ( "github.com/docker/notary/trustpinning" digest "github.com/opencontainers/go-digest" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGetTag(t *testing.T) { @@ -53,6 +54,7 @@ func TestGetSignableRolesError(t *testing.T) { defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) + require.NoError(t, err) target := client.Target{} _, err = GetSignableRoles(notaryRepo, &target) assert.EqualError(t, err, "client is offline") diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 4b3cccf085..9cef6ea1a9 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -2,7 +2,7 @@ FROM golang:1.8.3-alpine RUN apk add -U git -ARG GOMETALINTER_SHA=4306381615a2ba2a207f8fcea02c08c6b2b0803f +ARG GOMETALINTER_SHA=8eca55135021737bbc65ed68b548b3336853274c RUN go get -d github.com/alecthomas/gometalinter && \ cd /go/src/github.com/alecthomas/gometalinter && \ git checkout -q "$GOMETALINTER_SHA" && \ diff --git a/docs/yaml/yaml.go b/docs/yaml/yaml.go index 2dbe406bdb..528eefbbb3 100644 --- a/docs/yaml/yaml.go +++ b/docs/yaml/yaml.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v2" ) type cmdOption struct { @@ -46,18 +46,17 @@ type cmdDoc struct { // GenYamlTree creates yaml structured ref files func GenYamlTree(cmd *cobra.Command, dir string) error { - identity := func(s string) string { return s } emptyStr := func(s string) string { return "" } - return GenYamlTreeCustom(cmd, dir, emptyStr, identity) + return GenYamlTreeCustom(cmd, dir, emptyStr) } // GenYamlTreeCustom creates yaml structured ref files -func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error { +func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string) string) error { for _, c := range cmd.Commands() { if !c.IsAvailableCommand() || c.IsHelpCommand() { continue } - if err := GenYamlTreeCustom(c, dir, filePrepender, linkHandler); err != nil { + if err := GenYamlTreeCustom(c, dir, filePrepender); err != nil { return err } } diff --git a/gometalinter.json b/gometalinter.json index b5956dca60..1f2131dd4d 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -1,8 +1,12 @@ { "Vendor": true, "Deadline": "2m", - "Sort": ["linter", "severity", "path"], - "Exclude": ["cli/compose/schema/bindata.go"], + "Sort": ["linter", "severity", "path", "line"], + "Exclude": [ + "cli/compose/schema/bindata.go", + "parameter .* always receives" + ], + "EnableGC": true, "DisableAll": true, "Enable": [