diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000000..f90407270b64 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,35 @@ +run: + deadline: 3m + skip-dirs: + - cli/command/stack/kubernetes/api/openapi + - cli/command/stack/kubernetes/api/client + skip-files: + - cli/compose/schema/bindata.go + - .*generated.* + - parameter .* always receives +linters: + disable-all: true + enable: + - deadcode + - gocyclo + - gofmt + - goimports + - golint + - gosimple + - ineffassign + - interfacer + - lll + - misspell + - nakedret + - unconvert + - unparam + - unused + - vet +linters-settings: + nakedret: + command: nakedret + pattern: ^(?P.*?\\.go):(?P\\d+)\\s*(?P.*)$ + gocyclo: + min-complexity: 16 + lll: + line-length: 200 diff --git a/cli/command/config/inspect_test.go b/cli/command/config/inspect_test.go index 1b4f275ccb84..d174b0c502a4 100644 --- a/cli/command/config/inspect_test.go +++ b/cli/command/config/inspect_test.go @@ -7,10 +7,9 @@ import ( "time" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/config/ls_test.go b/cli/command/config/ls_test.go index d3055b4aa15c..4677b068e7fb 100644 --- a/cli/command/config/ls_test.go +++ b/cli/command/config/ls_test.go @@ -7,11 +7,10 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" is "gotest.tools/assert/cmp" "gotest.tools/golden" diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index de96a3b7d870..854aa7395224 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "net/http/httputil" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" @@ -103,10 +102,7 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error { } resp, errAttach := client.ContainerAttach(ctx, opts.container, options) - if errAttach != nil && errAttach != httputil.ErrPersistEOF { - // ContainerAttach returns an ErrPersistEOF (connection closed) - // means server met an error and put it in Hijacked connection - // keep the error and read detailed error message from hijacked connection later + if errAttach != nil { return errAttach } defer resp.Close() @@ -142,10 +138,6 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error { return err } - if errAttach != nil { - return errAttach - } - return getExitStatus(errC, resultC) } diff --git a/cli/command/container/list_test.go b/cli/command/container/list_test.go index 2bc1949a7fe7..310d78020a5c 100644 --- a/cli/command/container/list_test.go +++ b/cli/command/container/list_test.go @@ -7,9 +7,8 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/container/run.go b/cli/command/container/run.go index 2ce3f3679c59..76a2de5d4b9c 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "net/http/httputil" "os" "runtime" "strings" @@ -253,10 +252,7 @@ func attachContainer( } resp, errAttach := dockerCli.Client().ContainerAttach(ctx, containerID, options) - if errAttach != nil && errAttach != httputil.ErrPersistEOF { - // ContainerAttach returns an ErrPersistEOF (connection closed) - // means server met an error and put it in Hijacked connection - // keep the error and read detailed error message from hijacked connection later + if errAttach != nil { return nil, errAttach } diff --git a/cli/command/container/start.go b/cli/command/container/start.go index e38830284131..2693987fc5e9 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "net/http/httputil" "strings" "github.com/docker/cli/cli" @@ -98,10 +97,7 @@ func runStart(dockerCli command.Cli, opts *startOptions) error { } resp, errAttach := dockerCli.Client().ContainerAttach(ctx, c.ID, options) - if errAttach != nil && errAttach != httputil.ErrPersistEOF { - // ContainerAttach return an ErrPersistEOF (connection closed) - // means server met an error and already put it in Hijacked connection, - // we would keep the error and read the detailed error message from hijacked connection + if errAttach != nil { return errAttach } defer resp.Close() @@ -154,7 +150,7 @@ func runStart(dockerCli command.Cli, opts *startOptions) error { } } if attachErr := <-cErr; attachErr != nil { - if _, ok := err.(term.EscapeError); ok { + if _, ok := attachErr.(term.EscapeError); ok { // The user entered the detach escape sequence. return nil } diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index e8309e33246f..95afccf5cbc1 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -208,7 +208,9 @@ func runStats(dockerCli command.Cli, opts *statsOptions) error { } var err error - for range time.Tick(500 * time.Millisecond) { + ticker := time.NewTicker(500 * time.Millisecond) + defer ticker.Stop() + for range ticker.C { cleanScreen() ccstats := []StatsEntry{} cStats.mu.Lock() diff --git a/cli/command/idresolver/idresolver_test.go b/cli/command/idresolver/idresolver_test.go index f667b10641a9..4cb6355594d1 100644 --- a/cli/command/idresolver/idresolver_test.go +++ b/cli/command/idresolver/idresolver_test.go @@ -1,16 +1,14 @@ package idresolver import ( + "context" "testing" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" + "github.com/pkg/errors" "gotest.tools/assert" is "gotest.tools/assert/cmp" - // Import builders to get the builder function as package function - "context" - - . "github.com/docker/cli/internal/test/builders" - "github.com/pkg/errors" ) func TestResolveError(t *testing.T) { diff --git a/cli/command/image/build/context_test.go b/cli/command/image/build/context_test.go index de4d38f75d6c..622f8edbd148 100644 --- a/cli/command/image/build/context_test.go +++ b/cli/command/image/build/context_test.go @@ -24,12 +24,12 @@ var prepareEmpty = func(t *testing.T) (string, func()) { } var prepareNoFiles = func(t *testing.T) (string, func()) { - return createTestTempDir(t, "", "builder-context-test") + return createTestTempDir(t, "builder-context-test") } var prepareOneFile = func(t *testing.T) (string, func()) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + contextDir, cleanup := createTestTempDir(t, "builder-context-test") + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) return contextDir, cleanup } @@ -42,7 +42,7 @@ func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) (stri } func TestGetContextFromLocalDirNoDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() _, _, err := GetContextFromLocalDir(contextDir, "") @@ -50,7 +50,7 @@ func TestGetContextFromLocalDirNoDockerfile(t *testing.T) { } func TestGetContextFromLocalDirNotExistingDir(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() fakePath := filepath.Join(contextDir, "fake") @@ -60,7 +60,7 @@ func TestGetContextFromLocalDirNotExistingDir(t *testing.T) { } func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() fakePath := filepath.Join(contextDir, "fake") @@ -70,10 +70,10 @@ func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) { } func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) { - contextDir, dirCleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, dirCleanup := createTestTempDir(t, "builder-context-test") defer dirCleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) chdirCleanup := chdir(t, contextDir) defer chdirCleanup() @@ -86,10 +86,10 @@ func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) { } func TestGetContextFromLocalDirWithDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "") assert.NilError(t, err) @@ -99,11 +99,11 @@ func TestGetContextFromLocalDirWithDockerfile(t *testing.T) { } func TestGetContextFromLocalDirLocalFile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - testFilename := createTestTempFile(t, contextDir, "tmpTest", "test", 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) + testFilename := createTestTempFile(t, contextDir, "tmpTest", "test") absContextDir, relDockerfile, err := GetContextFromLocalDir(testFilename, "") @@ -121,13 +121,13 @@ func TestGetContextFromLocalDirLocalFile(t *testing.T) { } func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() chdirCleanup := chdir(t, contextDir) defer chdirCleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, DefaultDockerfileName) assert.NilError(t, err) @@ -173,10 +173,10 @@ func TestGetContextFromReaderString(t *testing.T) { } func TestGetContextFromReaderTar(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) tarStream, err := archive.Tar(contextDir, archive.Uncompressed) assert.NilError(t, err) @@ -241,17 +241,18 @@ func TestValidateContextDirectoryWithOneFileExcludes(t *testing.T) { // createTestTempDir creates a temporary directory for testing. // It returns the created path and a cleanup function which is meant to be used as deferred call. // When an error occurs, it terminates the test. -func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) { - path, err := ioutil.TempDir(dir, prefix) +//nolint: unparam +func createTestTempDir(t *testing.T, prefix string) (string, func()) { + path, err := ioutil.TempDir("", prefix) assert.NilError(t, err) return path, func() { assert.NilError(t, os.RemoveAll(path)) } } // createTestTempFile creates a temporary file within dir with specific contents and permissions. // When an error occurs, it terminates the test -func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.FileMode) string { +func createTestTempFile(t *testing.T, dir, filename, contents string) string { filePath := filepath.Join(dir, filename) - err := ioutil.WriteFile(filePath, []byte(contents), perm) + err := ioutil.WriteFile(filePath, []byte(contents), 0777) assert.NilError(t, err) return filePath } diff --git a/cli/command/image/build_buildkit.go b/cli/command/image/build_buildkit.go index 24367ce2779c..6f50cf43b766 100644 --- a/cli/command/image/build_buildkit.go +++ b/cli/command/image/build_buildkit.go @@ -438,16 +438,13 @@ func parseSecret(value string) (*secretsprovider.FileSource, error) { func parseSSHSpecs(sl []string) (session.Attachable, error) { configs := make([]sshprovider.AgentConfig, 0, len(sl)) for _, v := range sl { - c, err := parseSSH(v) - if err != nil { - return nil, err - } + c := parseSSH(v) configs = append(configs, *c) } return sshprovider.NewSSHAgentProvider(configs) } -func parseSSH(value string) (*sshprovider.AgentConfig, error) { +func parseSSH(value string) *sshprovider.AgentConfig { parts := strings.SplitN(value, "=", 2) cfg := sshprovider.AgentConfig{ ID: parts[0], @@ -455,5 +452,5 @@ func parseSSH(value string) (*sshprovider.AgentConfig, error) { if len(parts) > 1 { cfg.Paths = strings.Split(parts[1], ",") } - return &cfg, nil + return &cfg } diff --git a/cli/command/image/build_session.go b/cli/command/image/build_session.go index c19120758d80..aa7b3fe9bfb6 100644 --- a/cli/command/image/build_session.go +++ b/cli/command/image/build_session.go @@ -35,16 +35,13 @@ func isSessionSupported(dockerCli command.Cli, forStream bool) bool { } func trySession(dockerCli command.Cli, contextDir string, forStream bool) (*session.Session, error) { - var s *session.Session - if isSessionSupported(dockerCli, forStream) { - sharedKey, err := getBuildSharedKey(contextDir) - if err != nil { - return nil, errors.Wrap(err, "failed to get build shared key") - } - s, err = session.NewSession(context.Background(), filepath.Base(contextDir), sharedKey) - if err != nil { - return nil, errors.Wrap(err, "failed to create session") - } + if !isSessionSupported(dockerCli, forStream) { + return nil, nil + } + sharedKey := getBuildSharedKey(contextDir) + s, err := session.NewSession(context.Background(), filepath.Base(contextDir), sharedKey) + if err != nil { + return nil, errors.Wrap(err, "failed to create session") } return s, nil } @@ -130,10 +127,10 @@ func (bw *bufferedWriter) String() string { return fmt.Sprintf("%s", bw.Writer) } -func getBuildSharedKey(dir string) (string, error) { +func getBuildSharedKey(dir string) string { // build session is hash of build dir with node based randomness s := sha256.Sum256([]byte(fmt.Sprintf("%s:%s", tryNodeIdentifier(), dir))) - return hex.EncodeToString(s[:]), nil + return hex.EncodeToString(s[:]) } func tryNodeIdentifier() string { diff --git a/cli/command/node/demote_test.go b/cli/command/node/demote_test.go index 3f18d63d41f6..849cbdc93d9c 100644 --- a/cli/command/node/demote_test.go +++ b/cli/command/node/demote_test.go @@ -5,11 +5,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package functions "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/assert" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) func TestNodeDemoteErrors(t *testing.T) { diff --git a/cli/command/node/inspect_test.go b/cli/command/node/inspect_test.go index de343b0f494c..22be4f475fa5 100644 --- a/cli/command/node/inspect_test.go +++ b/cli/command/node/inspect_test.go @@ -6,11 +6,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package functions "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/node/list_test.go b/cli/command/node/list_test.go index 5dc11c961ad4..11e5ff3f60ea 100644 --- a/cli/command/node/list_test.go +++ b/cli/command/node/list_test.go @@ -6,14 +6,13 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/assert" is "gotest.tools/assert/cmp" "gotest.tools/golden" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) func TestNodeListErrorOnAPIFailure(t *testing.T) { diff --git a/cli/command/node/promote_test.go b/cli/command/node/promote_test.go index c6b534232083..528180ae004a 100644 --- a/cli/command/node/promote_test.go +++ b/cli/command/node/promote_test.go @@ -5,11 +5,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/assert" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) func TestNodePromoteErrors(t *testing.T) { diff --git a/cli/command/node/ps_test.go b/cli/command/node/ps_test.go index 74a1779b1fae..da4637da6187 100644 --- a/cli/command/node/ps_test.go +++ b/cli/command/node/ps_test.go @@ -8,11 +8,10 @@ import ( "time" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/node/update_test.go b/cli/command/node/update_test.go index 8b6ae807dabc..00c447b6b203 100644 --- a/cli/command/node/update_test.go +++ b/cli/command/node/update_test.go @@ -5,11 +5,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/assert" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) func TestNodeUpdateErrors(t *testing.T) { diff --git a/cli/command/plugin/list_test.go b/cli/command/plugin/list_test.go index fbde655316d1..75d0c8139ca8 100644 --- a/cli/command/plugin/list_test.go +++ b/cli/command/plugin/list_test.go @@ -58,7 +58,7 @@ func TestListErrors(t *testing.T) { } func TestList(t *testing.T) { - singlePluginListFunc := func(filter filters.Args) (types.PluginsListResponse, error) { + singlePluginListFunc := func(_ filters.Args) (types.PluginsListResponse, error) { return types.PluginsListResponse{ { ID: "id-foo", @@ -113,7 +113,7 @@ func TestList(t *testing.T) { "format": "{{ .ID }}", }, golden: "plugin-list-with-no-trunc-option.golden", - listFunc: func(filter filters.Args) (types.PluginsListResponse, error) { + listFunc: func(_ filters.Args) (types.PluginsListResponse, error) { return types.PluginsListResponse{ { ID: "xyg4z2hiSLO5yTnBJfg4OYia9gKA6Qjd", @@ -142,7 +142,7 @@ func TestList(t *testing.T) { "format": "{{ .Name }}", }, golden: "plugin-list-sort.golden", - listFunc: func(filter filters.Args) (types.PluginsListResponse, error) { + listFunc: func(_ filters.Args) (types.PluginsListResponse, error) { return types.PluginsListResponse{ { ID: "id-1", diff --git a/cli/command/registry/login_test.go b/cli/command/registry/login_test.go index 6cbf3570c614..283931c39f97 100644 --- a/cli/command/registry/login_test.go +++ b/cli/command/registry/login_test.go @@ -63,7 +63,7 @@ func TestLoginWithCredStoreCreds(t *testing.T) { } ctx := context.Background() for _, tc := range testCases { - cli := (*test.FakeCli)(test.NewFakeCli(&fakeClient{})) + cli := test.NewFakeCli(&fakeClient{}) errBuf := new(bytes.Buffer) cli.SetErr(errBuf) loginWithCredStoreCreds(ctx, cli, &tc.inputAuthConfig) @@ -145,7 +145,7 @@ func TestRunLogin(t *testing.T) { if tc.inputStoredCred != nil { cred := *tc.inputStoredCred - configfile.GetCredentialsStore(cred.ServerAddress).Store(cred) + assert.NilError(t, configfile.GetCredentialsStore(cred.ServerAddress).Store(cred)) } loginErr := runLogin(cli, tc.inputLoginOption) if tc.expectedErr != "" { diff --git a/cli/command/secret/inspect_test.go b/cli/command/secret/inspect_test.go index 67addaeadf9b..9224f9b796f5 100644 --- a/cli/command/secret/inspect_test.go +++ b/cli/command/secret/inspect_test.go @@ -7,10 +7,9 @@ import ( "time" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/secret/ls_test.go b/cli/command/secret/ls_test.go index e1417115ce95..1e6af25a0def 100644 --- a/cli/command/secret/ls_test.go +++ b/cli/command/secret/ls_test.go @@ -7,11 +7,10 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" is "gotest.tools/assert/cmp" "gotest.tools/golden" diff --git a/cli/command/service/client_test.go b/cli/command/service/client_test.go index 8d0d592cec13..97dd9d8c4c02 100644 --- a/cli/command/service/client_test.go +++ b/cli/command/service/client_test.go @@ -3,11 +3,10 @@ package service import ( "context" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) type fakeClient struct { diff --git a/cli/command/service/opts_test.go b/cli/command/service/opts_test.go index 9493a8230349..0a3d170e92a6 100644 --- a/cli/command/service/opts_test.go +++ b/cli/command/service/opts_test.go @@ -148,9 +148,9 @@ func TestToServiceNetwork(t *testing.T) { } nwo := opts.NetworkOpt{} - nwo.Set("zzz-network") - nwo.Set("mmm-network") - nwo.Set("aaa-network") + assert.NilError(t, nwo.Set("zzz-network")) + assert.NilError(t, nwo.Set("mmm-network")) + assert.NilError(t, nwo.Set("aaa-network")) o := newServiceOptions() o.mode = "replicated" diff --git a/cli/command/stack/kubernetes/deploy_test.go b/cli/command/stack/kubernetes/deploy_test.go index 85d1a5ff7d3a..366ba45ebea6 100644 --- a/cli/command/stack/kubernetes/deploy_test.go +++ b/cli/command/stack/kubernetes/deploy_test.go @@ -56,16 +56,16 @@ func TestCreateChildResourcesV1Beta1(t *testing.T) { secrets)) c, err := configs.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, c.ObjectMeta, "test", v1beta1.SchemeGroupVersion.String()) + checkOwnerReferences(t, c.ObjectMeta, v1beta1.SchemeGroupVersion.String()) s, err := secrets.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, s.ObjectMeta, "test", v1beta1.SchemeGroupVersion.String()) + checkOwnerReferences(t, s.ObjectMeta, v1beta1.SchemeGroupVersion.String()) } -func checkOwnerReferences(t *testing.T, objMeta metav1.ObjectMeta, stackName, stackVersion string) { +func checkOwnerReferences(t *testing.T, objMeta metav1.ObjectMeta, stackVersion string) { t.Helper() assert.Equal(t, len(objMeta.OwnerReferences), 1) - assert.Equal(t, objMeta.OwnerReferences[0].Name, stackName) + assert.Equal(t, objMeta.OwnerReferences[0].Name, "test") assert.Equal(t, objMeta.OwnerReferences[0].Kind, "Stack") assert.Equal(t, objMeta.OwnerReferences[0].APIVersion, stackVersion) } @@ -82,10 +82,10 @@ func TestCreateChildResourcesV1Beta2(t *testing.T) { secrets)) c, err := configs.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, c.ObjectMeta, "test", v1beta2.SchemeGroupVersion.String()) + checkOwnerReferences(t, c.ObjectMeta, v1beta2.SchemeGroupVersion.String()) s, err := secrets.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, s.ObjectMeta, "test", v1beta2.SchemeGroupVersion.String()) + checkOwnerReferences(t, s.ObjectMeta, v1beta2.SchemeGroupVersion.String()) } func TestCreateChildResourcesV1Alpha3(t *testing.T) { @@ -100,10 +100,10 @@ func TestCreateChildResourcesV1Alpha3(t *testing.T) { secrets)) c, err := configs.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, c.ObjectMeta, "test", v1alpha3.SchemeGroupVersion.String()) + checkOwnerReferences(t, c.ObjectMeta, v1alpha3.SchemeGroupVersion.String()) s, err := secrets.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, s.ObjectMeta, "test", v1alpha3.SchemeGroupVersion.String()) + checkOwnerReferences(t, s.ObjectMeta, v1alpha3.SchemeGroupVersion.String()) } func TestCreateChildResourcesWithStackCreationErrorV1Beta1(t *testing.T) { diff --git a/cli/command/stack/kubernetes/list.go b/cli/command/stack/kubernetes/list.go index 9706f4be567c..facd401bb999 100644 --- a/cli/command/stack/kubernetes/list.go +++ b/cli/command/stack/kubernetes/list.go @@ -29,7 +29,7 @@ func GetStacks(kubeCli *KubeCli, opts options.List) ([]*formatter.Stack, error) } func isAllNamespacesDisabled(kubeCliConfig *configfile.KubernetesConfig) bool { - return kubeCliConfig == nil || kubeCliConfig != nil && kubeCliConfig.AllNamespaces != "disabled" + return kubeCliConfig == nil || kubeCliConfig.AllNamespaces != "disabled" } func getStacks(kubeCli *KubeCli, opts options.List) ([]*formatter.Stack, error) { diff --git a/cli/command/stack/list_test.go b/cli/command/stack/list_test.go index 5fdc04bed3f7..8d792172ac7b 100644 --- a/cli/command/stack/list_test.go +++ b/cli/command/stack/list_test.go @@ -6,8 +6,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/internal/test" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index a3e68656fb9d..8e49d193bd89 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -7,8 +7,7 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" diff --git a/cli/command/stack/services_test.go b/cli/command/stack/services_test.go index 64a58b997069..431a675f9dcd 100644 --- a/cli/command/stack/services_test.go +++ b/cli/command/stack/services_test.go @@ -6,8 +6,7 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" diff --git a/cli/command/swarm/join_token_test.go b/cli/command/swarm/join_token_test.go index 1bd7ba2508bf..e34e7da5f0b4 100644 --- a/cli/command/swarm/join_token_test.go +++ b/cli/command/swarm/join_token_test.go @@ -6,11 +6,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/swarm/unlock_key_test.go b/cli/command/swarm/unlock_key_test.go index d28921a141eb..d313c6319f69 100644 --- a/cli/command/swarm/unlock_key_test.go +++ b/cli/command/swarm/unlock_key_test.go @@ -6,11 +6,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/swarm/update_test.go b/cli/command/swarm/update_test.go index 20a5624a897e..ebddeeec0d56 100644 --- a/cli/command/swarm/update_test.go +++ b/cli/command/swarm/update_test.go @@ -7,12 +7,10 @@ import ( "time" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/system/info.go b/cli/command/system/info.go index 7adf92bd50bd..d837ca5231bb 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -88,9 +88,7 @@ func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error func prettyPrintInfo(dockerCli command.Cli, info info) error { fmt.Fprintln(dockerCli.Out(), "Client:") if info.ClientInfo != nil { - if err := prettyPrintClientInfo(dockerCli, *info.ClientInfo); err != nil { - info.ClientErrors = append(info.ClientErrors, err.Error()) - } + prettyPrintClientInfo(dockerCli, *info.ClientInfo) } for _, err := range info.ClientErrors { fmt.Fprintln(dockerCli.Out(), "ERROR:", err) @@ -113,7 +111,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error { return nil } -func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) error { +func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) { fmt.Fprintln(dockerCli.Out(), " Debug Mode:", info.Debug) if len(info.Plugins) > 0 { @@ -134,8 +132,6 @@ func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) error { if len(info.Warnings) > 0 { fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n")) } - - return nil } // nolint: gocyclo diff --git a/cli/command/task/print_test.go b/cli/command/task/print_test.go index 6fa6e5865316..5b5c0a81c341 100644 --- a/cli/command/task/print_test.go +++ b/cli/command/task/print_test.go @@ -8,8 +8,7 @@ import ( "github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/idresolver" "github.com/docker/cli/internal/test" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "gotest.tools/assert" diff --git a/cli/command/trust/inspect_pretty_test.go b/cli/command/trust/inspect_pretty_test.go index 13d436d16873..d9ed38306a6a 100644 --- a/cli/command/trust/inspect_pretty_test.go +++ b/cli/command/trust/inspect_pretty_test.go @@ -393,11 +393,6 @@ func TestGetSignerRolesWithKeyIDs(t *testing.T) { "bob": {"key71", "key72"}, } - var roleWithSigs []client.RoleWithSignatures - for _, role := range roles { - roleWithSig := client.RoleWithSignatures{Role: role, Signatures: nil} - roleWithSigs = append(roleWithSigs, roleWithSig) - } signerRoleToKeyIDs := getDelegationRoleToKeyMap(roles) assert.Check(t, is.DeepEqual(expectedSignerRoleToKeyIDs, signerRoleToKeyIDs)) } diff --git a/cli/command/trust/key_generate.go b/cli/command/trust/key_generate.go index 47223c3d9d15..5e4661eafb6f 100644 --- a/cli/command/trust/key_generate.go +++ b/cli/command/trust/key_generate.go @@ -108,8 +108,7 @@ func generateKeyAndOutputPubPEM(keyName string, privKeyStore trustmanager.KeySto return pem.Block{}, err } - privKeyStore.AddKey(trustmanager.KeyInfo{Role: data.RoleName(keyName)}, privKey) - if err != nil { + if err := privKeyStore.AddKey(trustmanager.KeyInfo{Role: data.RoleName(keyName)}, privKey); err != nil { return pem.Block{}, err } diff --git a/cli/command/trust/sign_test.go b/cli/command/trust/sign_test.go index 31a56ea120b6..f197c7f59952 100644 --- a/cli/command/trust/sign_test.go +++ b/cli/command/trust/sign_test.go @@ -116,7 +116,7 @@ func TestGetOrGenerateNotaryKey(t *testing.T) { assert.Check(t, is.DeepEqual(rootKeyA.Public(), rootKeyB.Public())) // Now also try with a delegation key - releasesKey, err := getOrGenerateNotaryKey(notaryRepo, data.RoleName(trust.ReleasesRole)) + releasesKey, err := getOrGenerateNotaryKey(notaryRepo, trust.ReleasesRole) assert.NilError(t, err) assert.Check(t, releasesKey != nil) diff --git a/cli/command/volume/inspect_test.go b/cli/command/volume/inspect_test.go index 759042a5122a..c5baa9c62e84 100644 --- a/cli/command/volume/inspect_test.go +++ b/cli/command/volume/inspect_test.go @@ -6,10 +6,9 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/volume/list_test.go b/cli/command/volume/list_test.go index 9159eb89efae..9f07006f1649 100644 --- a/cli/command/volume/list_test.go +++ b/cli/command/volume/list_test.go @@ -6,12 +6,11 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" volumetypes "github.com/docker/docker/api/types/volume" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 21f4850c8792..05470fc91120 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -66,11 +66,7 @@ func Service( configs []*swarm.ConfigReference, ) (swarm.ServiceSpec, error) { name := namespace.Scope(service.Name) - - endpoint, err := convertEndpointSpec(service.Deploy.EndpointMode, service.Ports) - if err != nil { - return swarm.ServiceSpec{}, err - } + endpoint := convertEndpointSpec(service.Deploy.EndpointMode, service.Ports) mode, err := convertDeployMode(service.Deploy.Mode, service.Deploy.Replicas) if err != nil { @@ -103,10 +99,7 @@ func Service( return swarm.ServiceSpec{}, err } - dnsConfig, err := convertDNSConfig(service.DNS, service.DNSSearch) - if err != nil { - return swarm.ServiceSpec{}, err - } + dnsConfig := convertDNSConfig(service.DNS, service.DNSSearch) var privileges swarm.Privileges privileges.CredentialSpec, err = convertCredentialSpec(service.CredentialSpec) @@ -535,7 +528,7 @@ func convertResources(source composetypes.Resources) (*swarm.ResourceRequirement return resources, nil } -func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortConfig) (*swarm.EndpointSpec, error) { +func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortConfig) *swarm.EndpointSpec { portConfigs := []swarm.PortConfig{} for _, port := range source { portConfig := swarm.PortConfig{ @@ -554,7 +547,7 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC return &swarm.EndpointSpec{ Mode: swarm.ResolutionMode(strings.ToLower(endpointMode)), Ports: portConfigs, - }, nil + } } func convertEnvironment(source map[string]*string) []string { @@ -589,14 +582,14 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error) return serviceMode, nil } -func convertDNSConfig(DNS []string, DNSSearch []string) (*swarm.DNSConfig, error) { +func convertDNSConfig(DNS []string, DNSSearch []string) *swarm.DNSConfig { if DNS != nil || DNSSearch != nil { return &swarm.DNSConfig{ Nameservers: DNS, Search: DNSSearch, - }, nil + } } - return nil, nil + return nil } func convertCredentialSpec(spec composetypes.CredentialSpecConfig) (*swarm.CredentialSpec, error) { diff --git a/cli/compose/convert/service_test.go b/cli/compose/convert/service_test.go index d281e0e4529b..123272342d6d 100644 --- a/cli/compose/convert/service_test.go +++ b/cli/compose/convert/service_test.go @@ -177,7 +177,7 @@ func TestConvertEndpointSpec(t *testing.T) { Published: 80, }, } - endpoint, err := convertEndpointSpec("vip", source) + endpoint := convertEndpointSpec("vip", source) expected := swarm.EndpointSpec{ Mode: swarm.ResolutionMode(strings.ToLower("vip")), @@ -195,7 +195,6 @@ func TestConvertEndpointSpec(t *testing.T) { }, } - assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, *endpoint)) } @@ -271,13 +270,11 @@ func TestConvertServiceNetworksCustomDefault(t *testing.T) { } assert.NilError(t, err) - assert.Check(t, is.DeepEqual(expected, []swarm.NetworkAttachmentConfig(configs))) + assert.Check(t, is.DeepEqual(expected, configs)) } func TestConvertDNSConfigEmpty(t *testing.T) { - dnsConfig, err := convertDNSConfig(nil, nil) - - assert.NilError(t, err) + dnsConfig := convertDNSConfig(nil, nil) assert.Check(t, is.DeepEqual((*swarm.DNSConfig)(nil), dnsConfig)) } @@ -287,8 +284,7 @@ var ( ) func TestConvertDNSConfigAll(t *testing.T) { - dnsConfig, err := convertDNSConfig(nameservers, search) - assert.NilError(t, err) + dnsConfig := convertDNSConfig(nameservers, search) assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ Nameservers: nameservers, Search: search, @@ -296,8 +292,7 @@ func TestConvertDNSConfigAll(t *testing.T) { } func TestConvertDNSConfigNameservers(t *testing.T) { - dnsConfig, err := convertDNSConfig(nameservers, nil) - assert.NilError(t, err) + dnsConfig := convertDNSConfig(nameservers, nil) assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ Nameservers: nameservers, Search: nil, @@ -305,8 +300,7 @@ func TestConvertDNSConfigNameservers(t *testing.T) { } func TestConvertDNSConfigSearch(t *testing.T) { - dnsConfig, err := convertDNSConfig(nil, search) - assert.NilError(t, err) + dnsConfig := convertDNSConfig(nil, search) assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ Nameservers: nil, Search: search, diff --git a/cli/compose/loader/loader.go b/cli/compose/loader/loader.go index a3df518b312b..6c7e97896235 100644 --- a/cli/compose/loader/loader.go +++ b/cli/compose/loader/loader.go @@ -753,6 +753,7 @@ func transformServiceVolumeConfig(data interface{}) (interface{}, error) { } } +// nolint: unparam func transformServiceNetworkMap(value interface{}) (interface{}, error) { if list, ok := value.([]interface{}); ok { mapValue := map[interface{}]interface{}{} @@ -764,6 +765,7 @@ func transformServiceNetworkMap(value interface{}) (interface{}, error) { return value, nil } +// nolint: unparam func transformStringOrNumberList(value interface{}) (interface{}, error) { list := value.([]interface{}) result := make([]string, len(list)) diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go index 8185f836c840..dcd15858212b 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -103,7 +103,7 @@ type Config struct { Volumes map[string]VolumeConfig `yaml:",omitempty" json:"volumes,omitempty"` Secrets map[string]SecretConfig `yaml:",omitempty" json:"secrets,omitempty"` Configs map[string]ConfigObjConfig `yaml:",omitempty" json:"configs,omitempty"` - Extras map[string]interface{} `yaml:",inline", json:"-"` + Extras map[string]interface{} `yaml:",inline" json:"-"` } // MarshalJSON makes Config implement json.Marshaler diff --git a/cli/context/kubernetes/endpoint_test.go b/cli/context/kubernetes/endpoint_test.go index da124851a504..c419e6d26eaf 100644 --- a/cli/context/kubernetes/endpoint_test.go +++ b/cli/context/kubernetes/endpoint_test.go @@ -104,22 +104,22 @@ func TestSaveLoadContexts(t *testing.T) { rawNoTLSEP, err := rawNoTLS.WithTLSData(store, "raw-notls") assert.NilError(t, err) - checkClientConfig(t, store, rawNoTLSEP, "https://test", "test", nil, nil, nil, false) + checkClientConfig(t, rawNoTLSEP, "https://test", "test", nil, nil, nil, false) rawNoTLSSkipEP, err := rawNoTLSSkip.WithTLSData(store, "raw-notls-skip") assert.NilError(t, err) - checkClientConfig(t, store, rawNoTLSSkipEP, "https://test", "test", nil, nil, nil, true) + checkClientConfig(t, rawNoTLSSkipEP, "https://test", "test", nil, nil, nil, true) rawTLSEP, err := rawTLS.WithTLSData(store, "raw-tls") assert.NilError(t, err) - checkClientConfig(t, store, rawTLSEP, "https://test", "test", []byte("ca"), []byte("cert"), []byte("key"), true) + checkClientConfig(t, rawTLSEP, "https://test", "test", []byte("ca"), []byte("cert"), []byte("key"), true) embededDefaultEP, err := embededDefault.WithTLSData(store, "embed-default-context") assert.NilError(t, err) - checkClientConfig(t, store, embededDefaultEP, "https://server1", "namespace1", nil, []byte("cert"), []byte("key"), true) + checkClientConfig(t, embededDefaultEP, "https://server1", "namespace1", nil, []byte("cert"), []byte("key"), true) embededContext2EP, err := embededContext2.WithTLSData(store, "embed-context2") assert.NilError(t, err) - checkClientConfig(t, store, embededContext2EP, "https://server2", "namespace-override", []byte("ca"), []byte("cert"), []byte("key"), false) + checkClientConfig(t, embededContext2EP, "https://server2", "namespace-override", []byte("ca"), []byte("cert"), []byte("key"), false) } -func checkClientConfig(t *testing.T, s store.Store, ep Endpoint, server, namespace string, ca, cert, key []byte, skipTLSVerify bool) { +func checkClientConfig(t *testing.T, ep Endpoint, server, namespace string, ca, cert, key []byte, skipTLSVerify bool) { config := ep.KubernetesConfig() cfg, err := config.ClientConfig() assert.NilError(t, err) diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index e3d6cd60699d..2060f9912672 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -11,7 +11,7 @@ import ( "github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" distclient "github.com/docker/distribution/registry/client" "github.com/docker/docker/registry" digest "github.com/opencontainers/go-digest" @@ -103,9 +103,6 @@ func pullManifestSchemaV2ImageConfig(ctx context.Context, dgst digest.Digest, re } verifier := dgst.Verifier() - if err != nil { - return nil, err - } if _, err := verifier.Write(configJSON); err != nil { return nil, err } diff --git a/cli/required.go b/cli/required.go index 33a46735462d..cce81c86ab9f 100644 --- a/cli/required.go +++ b/cli/required.go @@ -99,6 +99,7 @@ func ExactArgs(number int) cobra.PositionalArgs { } } +//nolint: unparam func pluralize(word string, number int) string { if number == 1 { return word diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 6af611c92428..7e556fdbd0c0 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,18 +1,15 @@ -FROM golang:1.12.1-alpine +FROM golang:1.12.1 as build +ARG GOLANGCI_LINTER_SHA=v1.16.0 -RUN apk add -U git +ENV CGO_ENABLED=0 +RUN GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@$GOLANGCI_LINTER_SHA -ARG GOMETALINTER_SHA=v2.0.6 -RUN go get -d github.com/alecthomas/gometalinter && \ - cd /go/src/github.com/alecthomas/gometalinter && \ - git checkout -q "$GOMETALINTER_SHA" && \ - go build -v -o /usr/local/bin/gometalinter . && \ - gometalinter --install && \ - rm -rf /go/src/* /go/pkg/* +FROM golang:1.12.1-alpine as lint +COPY --from=build /go/bin/golangci-lint /usr/local/bin WORKDIR /go/src/github.com/docker/cli -ENV CGO_ENABLED=0 ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 -ENTRYPOINT ["/usr/local/bin/gometalinter"] -CMD ["--config=gometalinter.json", "./..."] +ENV CGO_ENABLED=0 +ENTRYPOINT ["/usr/local/bin/golangci-lint"] +CMD ["run", "--config=.golangci.yml"] COPY . . diff --git a/e2e/image/push_test.go b/e2e/image/push_test.go index 91dbc1cba8bb..1bcf02555652 100644 --- a/e2e/image/push_test.go +++ b/e2e/image/push_test.go @@ -296,6 +296,7 @@ func createImage(t *testing.T, registryPrefix, repo, tag string) string { return image } +//nolint: unparam func withNotaryPassphrase(pwd string) func(*icmd.Cmd) { return func(c *icmd.Cmd) { c.Env = append(c.Env, []string{ diff --git a/gometalinter.json b/gometalinter.json deleted file mode 100644 index a31a6a20ef6b..000000000000 --- a/gometalinter.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "Vendor": true, - "Deadline": "2m", - "Sort": ["linter", "severity", "path", "line"], - "Exclude": [ - "cli/compose/schema/bindata.go", - "cli/command/stack/kubernetes/api/openapi", - "cli/command/stack/kubernetes/api/client", - ".*generated.*", - "parameter .* always receives" - ], - "EnableGC": true, - "Linters": { - "nakedret": { - "Command": "nakedret", - "Pattern": "^(?P.*?\\.go):(?P\\d+)\\s*(?P.*)$" - } - }, - "WarnUnmatchedDirective": true, - - "DisableAll": true, - "Enable": [ - "deadcode", - "gocyclo", - "gofmt", - "goimports", - "golint", - "gosimple", - "ineffassign", - "interfacer", - "lll", - "misspell", - "nakedret", - "unconvert", - "unparam", - "unused", - "vet" - ], - - "Cyclo": 16, - "LineLength": 200 -} diff --git a/internal/containerizedengine/update.go b/internal/containerizedengine/update.go index 3cd7b31082c4..7c71da19e4c8 100644 --- a/internal/containerizedengine/update.go +++ b/internal/containerizedengine/update.go @@ -16,7 +16,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" ver "github.com/hashicorp/go-version" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" ) diff --git a/opts/throttledevice.go b/opts/throttledevice.go index 0959efae3583..0bf5dd666fdc 100644 --- a/opts/throttledevice.go +++ b/opts/throttledevice.go @@ -48,9 +48,6 @@ func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, error) { if err != nil { return nil, fmt.Errorf("invalid rate for device: %s. The correct format is :. Number must be a positive integer", val) } - if rate < 0 { - 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: rate}, nil } diff --git a/opts/ulimit_test.go b/opts/ulimit_test.go index 0aa3facdfb4c..8fc4d5c55582 100644 --- a/opts/ulimit_test.go +++ b/opts/ulimit_test.go @@ -8,7 +8,7 @@ import ( func TestUlimitOpt(t *testing.T) { ulimitMap := map[string]*units.Ulimit{ - "nofile": {"nofile", 1024, 512}, + "nofile": {Name: "nofile", Hard: 1024, Soft: 512}, } ulimitOpt := NewUlimitOpt(&ulimitMap)