Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[19.03 backport] Replace gometalinter with Golangci lint [carry 1797] #2239

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d85a3b2
gometalinter: fix configuration
thaJeztah Oct 24, 2019
3bc713c
Gometalinter: raise deadline to 3 minutes
thaJeztah Oct 28, 2019
b71d5e3
compose/loader: fix TestIsAbs not testing all combinations
thaJeztah Oct 29, 2019
ad7bd82
opts/throttledevice.go:51:5: SA4003: unsigned values are never < 0 (s…
silvin-lubecki Apr 2, 2019
1ed4e67
cli/command/trust/inspect_pretty_test.go:399:24: SA4010: this result …
silvin-lubecki Apr 2, 2019
49ff9c8
cli/command/container/stats.go:211:21: SA1015: using time.Tick leaks …
silvin-lubecki Apr 2, 2019
60aa890
SA1019: httputil.ErrPersistEOF is deprecated: No longer used. (stati…
silvin-lubecki Apr 2, 2019
fe1a85f
cli/command/trust/key_generate.go:112:9: nilness: impossible conditio…
silvin-lubecki Apr 2, 2019
cdc9d10
cli/command/stack/kubernetes/list.go:32:47: nilness: tautological con…
silvin-lubecki Apr 2, 2019
c833341
cli/command/container/start.go:157:20: nilness: nil dereference in ty…
silvin-lubecki Apr 2, 2019
66b760d
cli/registry/client/fetcher.go:106:9: nilness: impossible condition: …
silvin-lubecki Apr 2, 2019
0f72909
cli/compose/types/types.go:106:2: structtag: struct field tag `yaml:"…
silvin-lubecki Apr 2, 2019
7d9b95d
opts/ulimit_test.go:11:13: composites: `*github.com/docker/cli/vendor…
silvin-lubecki Apr 2, 2019
c8c1420
cli/command/container/attach.go:141:15: nilness: impossible condition…
silvin-lubecki Apr 2, 2019
1f3468b
unchecked errors
silvin-lubecki Apr 2, 2019
6f91e46
cli/command/image/build/context_test.go:244:38: `createTestTempDir` -…
silvin-lubecki Apr 2, 2019
9c7b701
cli/command/image/build/context_test.go:252:71: `createTestTempFile` …
silvin-lubecki Apr 2, 2019
20ae2a6
cli/command/image/build_buildkit.go:450:56: parseSSH - result 1 (erro…
silvin-lubecki Apr 2, 2019
a3912a4
cli/command/image/build_session.go:133:45: getBuildSharedKey - result…
silvin-lubecki Apr 2, 2019
a1f67cc
cli/command/plugin/list_test.go:61:31: `TestList$1` - `filter` is unu…
silvin-lubecki Apr 2, 2019
7db8c83
cli/command/stack/kubernetes/deploy_test.go:65:68: `checkOwnerReferen…
silvin-lubecki Apr 2, 2019
9ac043b
cli/command/system/info.go:116:68: prettyPrintClientInfo - result 0 (…
silvin-lubecki Apr 2, 2019
67a7fe0
cli/compose/convert: result 1 (error) is always nil (unparam)
silvin-lubecki Apr 2, 2019
c77f525
disable unparam linter on these functions, as we need an error in the…
silvin-lubecki Apr 2, 2019
b49a07b
compose/loader: define type for transformer-functions
thaJeztah Oct 28, 2019
c749704
Disable unparam linter: cli/required.go:102:16: `pluralize` - `word` …
silvin-lubecki Apr 2, 2019
315715e
Disable unparam linter: e2e/image/push_test.go:299:27: `withNotaryPas…
silvin-lubecki Apr 2, 2019
03dbef8
cli/command/trust/sign_test.go:119:70: unnecessary conversion (unconv…
silvin-lubecki Apr 2, 2019
2441946
cli/compose/convert/service_test.go:274:72: unnecessary conversion (u…
silvin-lubecki Apr 2, 2019
b2f6b49
File is not `goimports`-ed (goimports)
silvin-lubecki Apr 2, 2019
44c8cec
cli/command/registry/login_test.go:66:25: unnecessary conversion (unc…
silvin-lubecki Apr 2, 2019
98d2661
cli/command/image/build/context_test.go:244:38: `createTestTempDir` -…
silvin-lubecki Apr 2, 2019
7467a6a
e2e/container: containerExistsWithStatus - t is unused (unparam)
thaJeztah Oct 29, 2019
1a57296
cli/compose/convert: driverObjectConfig - result 1 (error) is always …
thaJeztah Oct 29, 2019
c10bf24
cli/command/secret: G101: Potential hardcoded credentials (gosec)
thaJeztah Oct 29, 2019
f969531
cli/command/service: SA1012: do not pass a nil Context (staticcheck)
thaJeztah Oct 29, 2019
acec6cb
cli/command/image/build: G107: Potential HTTP request made with varia…
thaJeztah Oct 29, 2019
3bfa0f3
cli/command/trust: SA1006: printf-style with no further arguments (st…
thaJeztah Oct 29, 2019
50a23ed
cli/command/utils: SA1006: printf-style with no further arguments (st…
thaJeztah Oct 29, 2019
fbe24f3
cli/command/image: SA1006: printf-style with no further arguments (st…
thaJeztah Oct 29, 2019
98150ae
cli/context/store: SA5001: should check returned error before deferri…
thaJeztah Oct 29, 2019
49253c7
cli/command/formatter: Error return value of `ImageWrite` is not chec…
thaJeztah Oct 29, 2019
10fda07
cli/command: Error return value of `cli.Apply` is not checked (errcheck)
thaJeztah Oct 29, 2019
bd778fc
cli/command/formatter: Error return value of `ContainerWrite` is not …
thaJeztah Oct 29, 2019
43b4988
cli/config: Using the variable on range scope `tc` in function litera…
thaJeztah Oct 29, 2019
a087595
service/logs: Using the variable on range scope `testcase` in functio…
thaJeztah Oct 29, 2019
ae7b1f7
templates: Using the variable on range scope `testCase` in function l…
thaJeztah Oct 29, 2019
42ad244
cli/compose/loader: Using a reference for the variable on range scope…
thaJeztah Oct 29, 2019
0cab268
e2e/cli-plugins: Using the variable on range scope `args` in function…
thaJeztah Oct 29, 2019
bda413e
cli/command/context: Using the variable on range scope `c` in functio…
thaJeztah Oct 29, 2019
f7b23cf
cli/command/trust: Using the variable on range scope `keyBytes` in fu…
thaJeztah Oct 29, 2019
b083f62
cli: remove unnecessary newlines (whitespace)
thaJeztah Oct 29, 2019
be5a3cc
cli/command: Using the variable on range scope `testcase` in function…
thaJeztah Oct 29, 2019
09c9445
internal: remove unnecessary newlines (whitespace)
thaJeztah Oct 29, 2019
65e0d7c
e2e: remove unnecessary trailing newline (whitespace)
thaJeztah Oct 29, 2019
37ef1f5
cli/command/container: suppress dogsled warnings
thaJeztah Oct 29, 2019
fccc105
cli/compose/template: Using the variable on range scope `tc` in funct…
thaJeztah Oct 29, 2019
1b35214
cli/manifest: Using the variable on range scope `testcase` in functio…
thaJeztah Oct 29, 2019
201e449
opts: Using the variable on range scope `tc` in function literal (sco…
thaJeztah Oct 29, 2019
73dad43
cli/command/stack/kubernetes: Using a reference for the variable on r…
thaJeztah Oct 29, 2019
b320fef
cli/command/container: Using the variable on range scope `c` in funct…
thaJeztah Oct 29, 2019
e70edc3
cli/command/stack/kubernetes: Using the variable on range scope `c` i…
thaJeztah Oct 29, 2019
7374c0a
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
2 changes: 2 additions & 0 deletions cli/command/container/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,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 @@ -209,6 +210,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 @@ -248,10 +247,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 @@ -304,7 +304,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 @@ -474,7 +474,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