lint: add `nolintlint` and clean up `nolint` directives (#9738)

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
This commit is contained in:
Milas Bowman 2022-08-09 16:43:58 -04:00 committed by GitHub
parent 12ad0fddab
commit 27227a8824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 41 additions and 39 deletions

View File

@ -18,6 +18,7 @@ linters:
- lll - lll
- misspell - misspell
- nakedret - nakedret
- nolintlint
- staticcheck - staticcheck
- structcheck - structcheck
- typecheck - typecheck

View File

@ -89,7 +89,7 @@ func (l *logConsumer) Log(container, service, message string) {
} }
p := l.getPresenter(container) p := l.getPresenter(container)
for _, line := range strings.Split(message, "\n") { for _, line := range strings.Split(message, "\n") {
fmt.Fprintf(l.writer, "%s%s\n", p.prefix, line) //nolint:errcheck fmt.Fprintf(l.writer, "%s%s\n", p.prefix, line)
} }
} }

View File

@ -29,7 +29,6 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
buildx "github.com/docker/buildx/build" buildx "github.com/docker/buildx/build"
"github.com/docker/cli/cli/command/image/build" "github.com/docker/cli/cli/command/image/build"
"github.com/docker/compose/v2/pkg/api"
dockertypes "github.com/docker/docker/api/types" dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
@ -40,6 +39,8 @@ import (
"github.com/docker/docker/pkg/urlutil" "github.com/docker/docker/pkg/urlutil"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/docker/compose/v2/pkg/api"
) )
func (s *composeService) doBuildClassic(ctx context.Context, project *types.Project, opts map[string]buildx.Options) (map[string]string, error) { func (s *composeService) doBuildClassic(ctx context.Context, project *types.Project, opts map[string]buildx.Options) (map[string]string, error) {
@ -65,7 +66,7 @@ func (s *composeService) doBuildClassic(ctx context.Context, project *types.Proj
return nameDigests, errs return nameDigests, errs
} }
// nolint: gocyclo //nolint:gocyclo
func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options buildx.Options) (string, error) { func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options buildx.Options) (string, error) {
var ( var (
buildCtx io.ReadCloser buildCtx io.ReadCloser

View File

@ -30,13 +30,13 @@ const (
// ContainerRunning running status // ContainerRunning running status
ContainerRunning = "running" ContainerRunning = "running"
// ContainerRemoving removing status // ContainerRemoving removing status
ContainerRemoving = "removing" //nolint ContainerRemoving = "removing"
// ContainerPaused paused status // ContainerPaused paused status
ContainerPaused = "paused" //nolint ContainerPaused = "paused"
// ContainerExited exited status // ContainerExited exited status
ContainerExited = "exited" //nolint ContainerExited = "exited"
// ContainerDead dead status // ContainerDead dead status
ContainerDead = "dead" //nolint ContainerDead = "dead"
) )
var _ io.ReadCloser = ContainerStdout{} var _ io.ReadCloser = ContainerStdout{}

View File

@ -21,7 +21,7 @@ import (
"testing" "testing"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"gotest.tools/v3/assert" "github.com/stretchr/testify/require"
) )
var project = types.Project{ var project = types.Project{
@ -45,25 +45,27 @@ var project = types.Project{
} }
func TestInDependencyUpCommandOrder(t *testing.T) { func TestInDependencyUpCommandOrder(t *testing.T) {
order := make(chan string) ctx, cancel := context.WithCancel(context.Background())
//nolint:errcheck, unparam t.Cleanup(cancel)
go InDependencyOrder(context.TODO(), &project, func(ctx context.Context, config string) error {
order <- config var order []string
err := InDependencyOrder(ctx, &project, func(ctx context.Context, service string) error {
order = append(order, service)
return nil return nil
}) })
assert.Equal(t, <-order, "test3") require.NoError(t, err, "Error during iteration")
assert.Equal(t, <-order, "test2") require.Equal(t, []string{"test3", "test2", "test1"}, order)
assert.Equal(t, <-order, "test1")
} }
func TestInDependencyReverseDownCommandOrder(t *testing.T) { func TestInDependencyReverseDownCommandOrder(t *testing.T) {
order := make(chan string) ctx, cancel := context.WithCancel(context.Background())
//nolint:errcheck, unparam t.Cleanup(cancel)
go InReverseDependencyOrder(context.TODO(), &project, func(ctx context.Context, config string) error {
order <- config var order []string
err := InReverseDependencyOrder(ctx, &project, func(ctx context.Context, service string) error {
order = append(order, service)
return nil return nil
}) })
assert.Equal(t, <-order, "test1") require.NoError(t, err, "Error during iteration")
assert.Equal(t, <-order, "test2") require.Equal(t, []string{"test1", "test2", "test3"}, order)
assert.Equal(t, <-order, "test3")
} }

View File

@ -21,11 +21,12 @@ import (
"io" "io"
"strings" "strings"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
) )
func (s *composeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error { func (s *composeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {
@ -95,7 +96,7 @@ func (s *composeService) logContainers(ctx context.Context, consumer api.LogCons
if err != nil { if err != nil {
return err return err
} }
defer r.Close() //nolint errcheck defer r.Close() //nolint:errcheck
name := getContainerNameWithoutProject(c) name := getContainerNameWithoutProject(c)
w := utils.GetWriter(func(line string) { w := utils.GetWriter(func(line string) {

View File

@ -134,7 +134,7 @@ func TestDownComposefileInParentFolder(t *testing.T) {
tmpFolder, err := os.MkdirTemp("fixtures/simple-composefile", "test-tmp") tmpFolder, err := os.MkdirTemp("fixtures/simple-composefile", "test-tmp")
assert.NilError(t, err) assert.NilError(t, err)
defer os.Remove(tmpFolder) // nolint: errcheck defer os.Remove(tmpFolder) //nolint:errcheck
projectName := filepath.Base(tmpFolder) projectName := filepath.Base(tmpFolder)
res := c.RunDockerComposeCmd(t, "--project-directory", tmpFolder, "up", "-d") res := c.RunDockerComposeCmd(t, "--project-directory", tmpFolder, "up", "-d")

View File

@ -172,12 +172,12 @@ func CopyFile(t testing.TB, sourceFile string, destinationFile string) {
src, err := os.Open(sourceFile) src, err := os.Open(sourceFile)
require.NoError(t, err, "Failed to open source file: %s") require.NoError(t, err, "Failed to open source file: %s")
//nolint: errcheck //nolint:errcheck
defer src.Close() defer src.Close()
dst, err := os.OpenFile(destinationFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755) dst, err := os.OpenFile(destinationFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755)
require.NoError(t, err, "Failed to open destination file: %s", destinationFile) require.NoError(t, err, "Failed to open destination file: %s", destinationFile)
//nolint: errcheck //nolint:errcheck
defer dst.Close() defer dst.Close()
_, err = io.Copy(dst, src) _, err = io.Copy(dst, src)

View File

@ -50,7 +50,6 @@ func TestLocalComposeVolume(t *testing.T) {
t.Run("check container volume specs", func(t *testing.T) { t.Run("check container volume specs", func(t *testing.T) {
res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx2-1", "--format", "{{ json .Mounts }}") res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx2-1", "--format", "{{ json .Mounts }}")
output := res.Stdout() output := res.Stdout()
//nolint
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"z","RW":true,"Propagation":""`), output) assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"z","RW":true,"Propagation":""`), output)
assert.Assert(t, strings.Contains(output, `"Destination":"/myconfig","Mode":"","RW":false,"Propagation":"rprivate"`), output) assert.Assert(t, strings.Contains(output, `"Destination":"/myconfig","Mode":"","RW":false,"Propagation":"rprivate"`), output)
}) })
@ -68,7 +67,6 @@ func TestLocalComposeVolume(t *testing.T) {
t.Run("check container bind-mounts specs", func(t *testing.T) { t.Run("check container bind-mounts specs", func(t *testing.T) {
res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx-1", "--format", "{{ json .Mounts }}") res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx-1", "--format", "{{ json .Mounts }}")
output := res.Stdout() output := res.Stdout()
//nolint
assert.Assert(t, strings.Contains(output, `"Type":"bind"`)) assert.Assert(t, strings.Contains(output, `"Type":"bind"`))
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/share/nginx/html"`)) assert.Assert(t, strings.Contains(output, `"Destination":"/usr/share/nginx/html"`))
}) })

View File

@ -164,14 +164,12 @@ func (w *ttyWriter) print() {
continue continue
} }
line := lineText(event, "", terminalWidth, statusPadding, runtime.GOOS != "windows") line := lineText(event, "", terminalWidth, statusPadding, runtime.GOOS != "windows")
//nolint: errcheck
fmt.Fprint(w.out, line) fmt.Fprint(w.out, line)
numLines++ numLines++
for _, v := range w.eventIDs { for _, v := range w.eventIDs {
ev := w.events[v] ev := w.events[v]
if ev.ParentID == event.ID { if ev.ParentID == event.ID {
line := lineText(ev, " ", terminalWidth, statusPadding, runtime.GOOS != "windows") line := lineText(ev, " ", terminalWidth, statusPadding, runtime.GOOS != "windows")
//nolint: errcheck
fmt.Fprint(w.out, line) fmt.Fprint(w.out, line)
numLines++ numLines++
} }

View File

@ -22,18 +22,19 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
//nolint:errcheck
func TestSplitWriter(t *testing.T) { func TestSplitWriter(t *testing.T) {
var lines []string var lines []string
w := GetWriter(func(line string) { w := GetWriter(func(line string) {
lines = append(lines, line) lines = append(lines, line)
}) })
w.Write([]byte("h")) //nolint: errcheck w.Write([]byte("h"))
w.Write([]byte("e")) //nolint: errcheck w.Write([]byte("e"))
w.Write([]byte("l")) //nolint: errcheck w.Write([]byte("l"))
w.Write([]byte("l")) //nolint: errcheck w.Write([]byte("l"))
w.Write([]byte("o")) //nolint: errcheck w.Write([]byte("o"))
w.Write([]byte("\n")) //nolint: errcheck w.Write([]byte("\n"))
w.Write([]byte("world!\n")) //nolint: errcheck w.Write([]byte("world!\n"))
assert.DeepEqual(t, lines, []string{"hello", "world!"}) assert.DeepEqual(t, lines, []string{"hello", "world!"})
} }