Skip to content

Commit 27227a8

Browse files
authored
lint: add nolintlint and clean up nolint directives (docker#9738)
Signed-off-by: Milas Bowman <[email protected]>
1 parent 12ad0fd commit 27227a8

File tree

11 files changed

+41
-39
lines changed

11 files changed

+41
-39
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters:
1818
- lll
1919
- misspell
2020
- nakedret
21+
- nolintlint
2122
- staticcheck
2223
- structcheck
2324
- typecheck

cmd/formatter/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (l *logConsumer) Log(container, service, message string) {
8989
}
9090
p := l.getPresenter(container)
9191
for _, line := range strings.Split(message, "\n") {
92-
fmt.Fprintf(l.writer, "%s%s\n", p.prefix, line) //nolint:errcheck
92+
fmt.Fprintf(l.writer, "%s%s\n", p.prefix, line)
9393
}
9494
}
9595

pkg/compose/build_classic.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/compose-spec/compose-go/types"
3030
buildx "github.com/docker/buildx/build"
3131
"github.com/docker/cli/cli/command/image/build"
32-
"github.com/docker/compose/v2/pkg/api"
3332
dockertypes "github.com/docker/docker/api/types"
3433
"github.com/docker/docker/cli"
3534
"github.com/docker/docker/pkg/archive"
@@ -40,6 +39,8 @@ import (
4039
"github.com/docker/docker/pkg/urlutil"
4140
"github.com/hashicorp/go-multierror"
4241
"github.com/pkg/errors"
42+
43+
"github.com/docker/compose/v2/pkg/api"
4344
)
4445

4546
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
6566
return nameDigests, errs
6667
}
6768

68-
// nolint: gocyclo
69+
//nolint:gocyclo
6970
func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options buildx.Options) (string, error) {
7071
var (
7172
buildCtx io.ReadCloser

pkg/compose/container.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ const (
3030
// ContainerRunning running status
3131
ContainerRunning = "running"
3232
// ContainerRemoving removing status
33-
ContainerRemoving = "removing" //nolint
33+
ContainerRemoving = "removing"
3434
// ContainerPaused paused status
35-
ContainerPaused = "paused" //nolint
35+
ContainerPaused = "paused"
3636
// ContainerExited exited status
37-
ContainerExited = "exited" //nolint
37+
ContainerExited = "exited"
3838
// ContainerDead dead status
39-
ContainerDead = "dead" //nolint
39+
ContainerDead = "dead"
4040
)
4141

4242
var _ io.ReadCloser = ContainerStdout{}

pkg/compose/dependencies_test.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/compose-spec/compose-go/types"
24-
"gotest.tools/v3/assert"
24+
"github.com/stretchr/testify/require"
2525
)
2626

2727
var project = types.Project{
@@ -45,25 +45,27 @@ var project = types.Project{
4545
}
4646

4747
func TestInDependencyUpCommandOrder(t *testing.T) {
48-
order := make(chan string)
49-
//nolint:errcheck, unparam
50-
go InDependencyOrder(context.TODO(), &project, func(ctx context.Context, config string) error {
51-
order <- config
48+
ctx, cancel := context.WithCancel(context.Background())
49+
t.Cleanup(cancel)
50+
51+
var order []string
52+
err := InDependencyOrder(ctx, &project, func(ctx context.Context, service string) error {
53+
order = append(order, service)
5254
return nil
5355
})
54-
assert.Equal(t, <-order, "test3")
55-
assert.Equal(t, <-order, "test2")
56-
assert.Equal(t, <-order, "test1")
56+
require.NoError(t, err, "Error during iteration")
57+
require.Equal(t, []string{"test3", "test2", "test1"}, order)
5758
}
5859

5960
func TestInDependencyReverseDownCommandOrder(t *testing.T) {
60-
order := make(chan string)
61-
//nolint:errcheck, unparam
62-
go InReverseDependencyOrder(context.TODO(), &project, func(ctx context.Context, config string) error {
63-
order <- config
61+
ctx, cancel := context.WithCancel(context.Background())
62+
t.Cleanup(cancel)
63+
64+
var order []string
65+
err := InReverseDependencyOrder(ctx, &project, func(ctx context.Context, service string) error {
66+
order = append(order, service)
6467
return nil
6568
})
66-
assert.Equal(t, <-order, "test1")
67-
assert.Equal(t, <-order, "test2")
68-
assert.Equal(t, <-order, "test3")
69+
require.NoError(t, err, "Error during iteration")
70+
require.Equal(t, []string{"test1", "test2", "test3"}, order)
6971
}

pkg/compose/logs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import (
2121
"io"
2222
"strings"
2323

24-
"github.com/docker/compose/v2/pkg/api"
25-
"github.com/docker/compose/v2/pkg/utils"
2624
"github.com/docker/docker/api/types"
2725
"github.com/docker/docker/pkg/stdcopy"
2826
"golang.org/x/sync/errgroup"
27+
28+
"github.com/docker/compose/v2/pkg/api"
29+
"github.com/docker/compose/v2/pkg/utils"
2930
)
3031

3132
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
9596
if err != nil {
9697
return err
9798
}
98-
defer r.Close() //nolint errcheck
99+
defer r.Close() //nolint:errcheck
99100

100101
name := getContainerNameWithoutProject(c)
101102
w := utils.GetWriter(func(line string) {

pkg/e2e/compose_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func TestDownComposefileInParentFolder(t *testing.T) {
134134

135135
tmpFolder, err := os.MkdirTemp("fixtures/simple-composefile", "test-tmp")
136136
assert.NilError(t, err)
137-
defer os.Remove(tmpFolder) // nolint: errcheck
137+
defer os.Remove(tmpFolder) //nolint:errcheck
138138
projectName := filepath.Base(tmpFolder)
139139

140140
res := c.RunDockerComposeCmd(t, "--project-directory", tmpFolder, "up", "-d")

pkg/e2e/framework.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ func CopyFile(t testing.TB, sourceFile string, destinationFile string) {
172172

173173
src, err := os.Open(sourceFile)
174174
require.NoError(t, err, "Failed to open source file: %s")
175-
//nolint: errcheck
175+
//nolint:errcheck
176176
defer src.Close()
177177

178178
dst, err := os.OpenFile(destinationFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755)
179179
require.NoError(t, err, "Failed to open destination file: %s", destinationFile)
180-
//nolint: errcheck
180+
//nolint:errcheck
181181
defer dst.Close()
182182

183183
_, err = io.Copy(dst, src)

pkg/e2e/volumes_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func TestLocalComposeVolume(t *testing.T) {
5050
t.Run("check container volume specs", func(t *testing.T) {
5151
res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx2-1", "--format", "{{ json .Mounts }}")
5252
output := res.Stdout()
53-
//nolint
5453
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"z","RW":true,"Propagation":""`), output)
5554
assert.Assert(t, strings.Contains(output, `"Destination":"/myconfig","Mode":"","RW":false,"Propagation":"rprivate"`), output)
5655
})
@@ -68,7 +67,6 @@ func TestLocalComposeVolume(t *testing.T) {
6867
t.Run("check container bind-mounts specs", func(t *testing.T) {
6968
res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx-1", "--format", "{{ json .Mounts }}")
7069
output := res.Stdout()
71-
//nolint
7270
assert.Assert(t, strings.Contains(output, `"Type":"bind"`))
7371
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/share/nginx/html"`))
7472
})

pkg/progress/tty.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,12 @@ func (w *ttyWriter) print() {
164164
continue
165165
}
166166
line := lineText(event, "", terminalWidth, statusPadding, runtime.GOOS != "windows")
167-
//nolint: errcheck
168167
fmt.Fprint(w.out, line)
169168
numLines++
170169
for _, v := range w.eventIDs {
171170
ev := w.events[v]
172171
if ev.ParentID == event.ID {
173172
line := lineText(ev, " ", terminalWidth, statusPadding, runtime.GOOS != "windows")
174-
//nolint: errcheck
175173
fmt.Fprint(w.out, line)
176174
numLines++
177175
}

0 commit comments

Comments
 (0)