Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2962971
opts/throttledevice.go:51:5: SA4003: unsigned values are never < 0 (s…
silvin-lubecki Apr 2, 2019
8018a85
cli/command/trust/inspect_pretty_test.go:399:24: SA4010: this result …
silvin-lubecki Apr 2, 2019
7da9360
cli/command/container/stats.go:211:21: SA1015: using time.Tick leaks …
silvin-lubecki Apr 2, 2019
3a42820
SA1019: httputil.ErrPersistEOF is deprecated: No longer used. (stati…
silvin-lubecki Apr 2, 2019
f5e8387
cli/command/trust/key_generate.go:112:9: nilness: impossible conditio…
silvin-lubecki Apr 2, 2019
85cfd4e
cli/command/stack/kubernetes/list.go:32:47: nilness: tautological con…
silvin-lubecki Apr 2, 2019
9afeb6f
cli/command/container/start.go:157:20: nilness: nil dereference in ty…
silvin-lubecki Apr 2, 2019
5ceed30
cli/registry/client/fetcher.go:106:9: nilness: impossible condition: …
silvin-lubecki Apr 2, 2019
1bfe813
cli/compose/types/types.go:106:2: structtag: struct field tag `yaml:"…
silvin-lubecki Apr 2, 2019
b3d4c6a
opts/ulimit_test.go:11:13: composites: `*github.com/docker/cli/vendor…
silvin-lubecki Apr 2, 2019
584da37
cli/command/container/attach.go:141:15: nilness: impossible condition…
silvin-lubecki Apr 2, 2019
e1c0c79
unchecked errors
silvin-lubecki Apr 2, 2019
70bd64d
cli/command/image/build/context_test.go:244:38: `createTestTempDir` -…
silvin-lubecki Apr 2, 2019
0ce2eae
cli/command/image/build/context_test.go:252:71: `createTestTempFile` …
silvin-lubecki Apr 2, 2019
28ac2f8
cli/command/image/build_buildkit.go:450:56: parseSSH - result 1 (erro…
silvin-lubecki Apr 2, 2019
75c60c1
cli/command/image/build_session.go:133:45: getBuildSharedKey - result…
silvin-lubecki Apr 2, 2019
ab1aeed
cli/command/plugin/list_test.go:61:31: `TestList$1` - `filter` is unu…
silvin-lubecki Apr 2, 2019
a3c7cb4
cli/command/stack/kubernetes/deploy_test.go:65:68: `checkOwnerReferen…
silvin-lubecki Apr 2, 2019
47741f8
cli/command/system/info.go:116:68: prettyPrintClientInfo - result 0 (…
silvin-lubecki Apr 2, 2019
d640f44
cli/compose/convert: result 1 (error) is always nil (unparam)
silvin-lubecki Apr 2, 2019
6eb0c9c
disable unparam linter on these functions, as we need an error in the…
silvin-lubecki Apr 2, 2019
9118b2b
compose/loader: define type for transformer-functions
thaJeztah Oct 28, 2019
7d82343
Disable unparam linter: cli/required.go:102:16: `pluralize` - `word` …
silvin-lubecki Apr 2, 2019
f123e43
Disable unparam linter: e2e/image/push_test.go:299:27: `withNotaryPas…
silvin-lubecki Apr 2, 2019
0153624
cli/command/trust/sign_test.go:119:70: unnecessary conversion (unconv…
silvin-lubecki Apr 2, 2019
6047259
File is not `goimports`-ed (goimports)
silvin-lubecki Apr 2, 2019
c237379
cli/compose/convert/service_test.go:274:72: unnecessary conversion (u…
silvin-lubecki Apr 2, 2019
4be924a
cli/command/registry/login_test.go:66:25: unnecessary conversion (unc…
silvin-lubecki Apr 2, 2019
b83545e
cli/command/image/build/context_test.go:244:38: `createTestTempDir` -…
silvin-lubecki Apr 2, 2019
6205ef3
e2e/container: containerExistsWithStatus - t is unused (unparam)
thaJeztah Oct 29, 2019
34f5959
cli/compose/convert: driverObjectConfig - result 1 (error) is always …
thaJeztah Oct 29, 2019
1850a05
cli/command/secret: G101: Potential hardcoded credentials (gosec)
thaJeztah Oct 29, 2019
8d64c2a
cli/command/service: SA1012: do not pass a nil Context (staticcheck)
thaJeztah Oct 29, 2019
0e4bd30
cli/command/image/build: G107: Potential HTTP request made with varia…
thaJeztah Oct 29, 2019
f0614ca
cli/command/trust: SA1006: printf-style with no further arguments (st…
thaJeztah Oct 29, 2019
ea64a1c
cli/command/utils: SA1006: printf-style with no further arguments (st…
thaJeztah Oct 29, 2019
709728e
cli/command/image: SA1006: printf-style with no further arguments (st…
thaJeztah Oct 29, 2019
fe3cc6e
cli/context/store: SA5001: should check returned error before deferri…
thaJeztah Oct 29, 2019
9275e2c
cli/command/formatter: Error return value of `ImageWrite` is not chec…
thaJeztah Oct 29, 2019
008f6a2
cli/command: Error return value of `cli.Apply` is not checked (errcheck)
thaJeztah Oct 29, 2019
e74e2c7
cli/command/formatter: Error return value of `ContainerWrite` is not …
thaJeztah Oct 29, 2019
5a2a9d9
cli/config: Using the variable on range scope `tc` in function litera…
thaJeztah Oct 29, 2019
c828fa1
service/logs: Using the variable on range scope `testcase` in functio…
thaJeztah Oct 29, 2019
54d48de
templates: Using the variable on range scope `testCase` in function l…
thaJeztah Oct 29, 2019
96ec729
cli/compose/loader: Using a reference for the variable on range scope…
thaJeztah Oct 29, 2019
1736662
e2e/cli-plugins: Using the variable on range scope `args` in function…
thaJeztah Oct 29, 2019
a269e17
cli/command/context: Using the variable on range scope `c` in functio…
thaJeztah Oct 29, 2019
7c4b63b
cli/command/trust: Using the variable on range scope `keyBytes` in fu…
thaJeztah Oct 29, 2019
2ec424a
cli/command: Using the variable on range scope `testcase` in function…
thaJeztah Oct 29, 2019
612d83d
cli: remove unnecessary newlines (whitespace)
thaJeztah Oct 29, 2019
63e45e6
internal: remove unnecessary newlines (whitespace)
thaJeztah Oct 29, 2019
dd4d216
e2e: remove unnecessary trailing newline (whitespace)
thaJeztah Oct 29, 2019
79dc83e
cli/command/container: suppress dogsled warnings
thaJeztah Oct 29, 2019
aafe3df
cli/compose/template: Using the variable on range scope `tc` in funct…
thaJeztah Oct 29, 2019
cd3dca3
cli/manifest: Using the variable on range scope `testcase` in functio…
thaJeztah Oct 29, 2019
c2b069f
opts: Using the variable on range scope `tc` in function literal (sco…
thaJeztah Oct 29, 2019
754fc6f
cli/command/stack/kubernetes: Using a reference for the variable on r…
thaJeztah Oct 29, 2019
542f802
cli/command/container: Using the variable on range scope `c` in funct…
thaJeztah Oct 29, 2019
640305f
cli/command/stack/kubernetes: Using the variable on range scope `c` i…
thaJeztah Oct 29, 2019
1e77742
service: remove unused opts from newService() (unparam)
thaJeztah Oct 30, 2019
b7e06f2
Remove now obsolete gometalinter and use golangci-lint instead
silvin-lubecki Apr 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
linters:
enable:
- bodyclose
- deadcode
- dogsled
- gocyclo
- goimports
- golint
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- megacheck
- misspell
- nakedret
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

disable:
- errcheck

run:
timeout: 5m
skip-dirs:
- cli/command/stack/kubernetes/api/openapi
- cli/command/stack/kubernetes/api/client
skip-files:
- cli/compose/schema/bindata.go
- .*generated.*

linters-settings:
gocyclo:
min-complexity: 16
govet:
check-shadowing: false
lll:
line-length: 200
nakedret:
command: nakedret
pattern: ^(?P<path>.*?\\.go):(?P<line>\\d+)\\s*(?P<message>.*)$

issues:
# The default exclusion rules are a bit too permissive, so copying the relevant ones below
exclude-use-default: false

exclude:
- parameter .* always receives

exclude-rules:
# These are copied from the default exclude rules, except for "ineffective break statement"
# and GoDoc checks.
# https://github.com/golangci/golangci-lint/blob/0cc87df732aaf1d5ad9ce9ca538d38d916918b36/pkg/config/config.go#L36
- text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
linters:
- errcheck
- text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
linters:
- golint
- text: "G103: Use of unsafe calls should be audited"
linters:
- gosec
- text: "G104: Errors unhandled"
linters:
- gosec
- text: "G204: Subprocess launch(ed with (variable|function call)|ing should be audited)"
linters:
- gosec
- text: "(G301|G302): (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)"
linters:
- gosec
- text: "G304: Potential file inclusion via variable"
linters:
- gosec
- text: "(G201|G202): SQL string (formatting|concatenation)"
linters:
- gosec
6 changes: 5 additions & 1 deletion cli/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func TestInitializeFromClient(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase
t.Run(testcase.doc, func(t *testing.T) {
apiclient := &fakeClient{
pingFunc: testcase.pingFunc,
Expand Down Expand Up @@ -189,6 +190,7 @@ func TestExperimentalCLI(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase
t.Run(testcase.doc, func(t *testing.T) {
dir := fs.NewDir(t, testcase.doc, fs.WithFile("config.json", testcase.configfile))
defer dir.Remove()
Expand Down Expand Up @@ -242,6 +244,7 @@ func TestGetClientWithPassword(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase
t.Run(testcase.doc, func(t *testing.T) {
passRetriever := func(_, _ string, _ bool, attempts int) (passphrase string, giveup bool, err error) {
// Always return an invalid pass first to test iteration
Expand Down Expand Up @@ -294,11 +297,12 @@ func TestNewDockerCliAndOperators(t *testing.T) {
inbuf := bytes.NewBuffer([]byte("input"))
outbuf := bytes.NewBuffer(nil)
errbuf := bytes.NewBuffer(nil)
cli.Apply(
err = cli.Apply(
WithInputStream(ioutil.NopCloser(inbuf)),
WithOutputStream(outbuf),
WithErrorStream(errbuf),
)
assert.NilError(t, err)
// Check input stream
inputStream, err := ioutil.ReadAll(cli.In())
assert.NilError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions cli/command/config/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
3 changes: 1 addition & 2 deletions cli/command/config/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 1 addition & 9 deletions cli/command/container/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"net/http/httputil"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -142,10 +138,6 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error {
return err
}

if errAttach != nil {
return errAttach
}

return getExitStatus(errC, resultC)
}

Expand Down
3 changes: 3 additions & 0 deletions cli/command/container/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
},
}
for _, c := range cases {
c := c
pullCounter := 0

client := &fakeClient{
Expand Down Expand Up @@ -178,6 +179,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
},
}
for _, tc := range testCases {
tc := tc
cli := test.NewFakeCli(&fakeClient{
createContainerFunc: func(config *container.Config,
hostConfig *container.HostConfig,
Expand Down Expand Up @@ -236,6 +238,7 @@ func TestNewCreateCommandWithWarnings(t *testing.T) {
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
createContainerFunc: func(config *container.Config,
Expand Down
3 changes: 1 addition & 2 deletions cli/command/container/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
6 changes: 3 additions & 3 deletions cli/command/container/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
}

func parseMustError(t *testing.T, args string) {
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " "))
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) //nolint:dogsled
assert.ErrorContains(t, err, "", args)
}

Expand Down Expand Up @@ -539,7 +539,7 @@ func TestParseModes(t *testing.T) {
}

// uts ko
_, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"})
_, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"}) //nolint:dogsled
assert.ErrorContains(t, err, "--uts: invalid UTS mode")

// uts ok
Expand Down Expand Up @@ -600,7 +600,7 @@ func TestParseRestartPolicy(t *testing.T) {

func TestParseRestartPolicyAutoRemove(t *testing.T) {
expected := "Conflicting options: --restart and --rm"
_, _, _, err := parseRun([]string{"--rm", "--restart=always", "img", "cmd"})
_, _, _, err := parseRun([]string{"--rm", "--restart=always", "img", "cmd"}) //nolint:dogsled
if err == nil || err.Error() != expected {
t.Fatalf("Expected error %v, but got none", expected)
}
Expand Down
6 changes: 1 addition & 5 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"net/http/httputil"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -250,10 +249,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
}

Expand Down
8 changes: 2 additions & 6 deletions cli/command/container/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"net/http/httputil"
"strings"

"github.com/docker/cli/cli"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion cli/command/container/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions cli/command/context/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func TestCreateFromContext(t *testing.T) {
cli.SetCurrentContext("dummy")

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
cli.ResetOutputBuffers()
err := RunCreate(cli, &CreateOptions{
Expand Down Expand Up @@ -339,6 +340,7 @@ func TestCreateFromCurrent(t *testing.T) {
cli.SetCurrentContext("original")

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
cli.ResetOutputBuffers()
err := RunCreate(cli, &CreateOptions{
Expand Down
3 changes: 2 additions & 1 deletion cli/command/formatter/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) {
}

for _, context := range contexts {
ContainerWrite(context.context, containers)
err := ContainerWrite(context.context, containers)
assert.NilError(t, err)
assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer
out.Reset()
Expand Down
3 changes: 2 additions & 1 deletion cli/command/formatter/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ func TestImageContextWriteWithNoImage(t *testing.T) {
}

for _, context := range contexts {
ImageWrite(context.context, images)
err := ImageWrite(context.context, images)
assert.NilError(t, err)
assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer
out.Reset()
Expand Down
8 changes: 3 additions & 5 deletions cli/command/idresolver/idresolver_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
// should be just the image ID and we'll print that to stdout.
if options.quiet {
imageID = fmt.Sprintf("%s", buildBuff)
fmt.Fprintf(dockerCli.Out(), imageID)
_, _ = fmt.Fprint(dockerCli.Out(), imageID)
}

if options.imageIDFile != "" {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/image/build/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.Read
// getWithStatusError does an http.Get() and returns an error if the
// status code is 4xx or 5xx.
func getWithStatusError(url string) (resp *http.Response, err error) {
// #nosec G107
if resp, err = http.Get(url); err != nil {
return nil, err
}
Expand Down Expand Up @@ -344,7 +345,6 @@ func getDockerfileRelPath(absContextDir, givenDockerfile string) (string, error)
absDockerfile, err = filepath.EvalSymlinks(absDockerfile)
if err != nil {
return "", errors.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err)

}
}

Expand Down
Loading