From 96cbb1cbcfd68fa60df2e7ce0a780df9c54a42a9 Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Wed, 13 Jul 2022 03:10:48 +0200 Subject: [PATCH] Add "style" tag to gocritic Signed-off-by: Ulysses Souza --- .golangci.yml | 2 ++ cmd/compose/build.go | 10 +++++----- cmd/formatter/logs.go | 20 ++++++++++---------- pkg/compose/convergence.go | 2 +- pkg/compose/cp.go | 2 +- pkg/compose/create_test.go | 11 +++++------ pkg/compose/printer.go | 10 +++++----- pkg/utils/writer_test.go | 14 +++++++------- 8 files changed, 36 insertions(+), 35 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 05d61ece0..434b92875 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -39,9 +39,11 @@ linters-settings: enabled-tags: - diagnostic - opinionated + - style disabled-checks: - paramTypeCombine - unnamedResult + - whyNoLint gocyclo: min-complexity: 16 lll: diff --git a/cmd/compose/build.go b/cmd/compose/build.go index 298d3b675..c9bfd2a65 100644 --- a/cmd/compose/build.go +++ b/cmd/compose/build.go @@ -110,16 +110,16 @@ func buildCommand(p *projectOptions, backend api.Service) *cobra.Command { cmd.Flags().StringArrayVar(&opts.args, "build-arg", []string{}, "Set build-time variables for services.") cmd.Flags().StringVar(&opts.ssh, "ssh", "", "Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent)") cmd.Flags().Bool("parallel", true, "Build images in parallel. DEPRECATED") - cmd.Flags().MarkHidden("parallel") //nolint:errcheck + cmd.Flags().MarkHidden("parallel") // nolint:errcheck cmd.Flags().Bool("compress", true, "Compress the build context using gzip. DEPRECATED") - cmd.Flags().MarkHidden("compress") //nolint:errcheck + cmd.Flags().MarkHidden("compress") // nolint:errcheck cmd.Flags().Bool("force-rm", true, "Always remove intermediate containers. DEPRECATED") - cmd.Flags().MarkHidden("force-rm") //nolint:errcheck + cmd.Flags().MarkHidden("force-rm") // nolint:errcheck cmd.Flags().BoolVar(&opts.noCache, "no-cache", false, "Do not use cache when building the image") cmd.Flags().Bool("no-rm", false, "Do not remove intermediate containers after a successful build. DEPRECATED") - cmd.Flags().MarkHidden("no-rm") //nolint:errcheck + cmd.Flags().MarkHidden("no-rm") // nolint:errcheck cmd.Flags().StringVarP(&opts.memory, "memory", "m", "", "Set memory limit for the build container. Not supported on buildkit yet.") - cmd.Flags().MarkHidden("memory") //nolint:errcheck + cmd.Flags().MarkHidden("memory") // nolint:errcheck return cmd } diff --git a/cmd/formatter/logs.go b/cmd/formatter/logs.go index 2cc9c84e5..71bbb2ba8 100644 --- a/cmd/formatter/logs.go +++ b/cmd/formatter/logs.go @@ -27,6 +27,16 @@ import ( "github.com/docker/compose/v2/pkg/api" ) +// LogConsumer consume logs from services and format them +type logConsumer struct { + ctx context.Context + presenters sync.Map // map[string]*presenter + width int + writer io.Writer + color bool + prefix bool +} + // NewLogConsumer creates a new LogConsumer func NewLogConsumer(ctx context.Context, w io.Writer, color bool, prefix bool) api.LogConsumer { return &logConsumer{ @@ -101,16 +111,6 @@ func (l *logConsumer) computeWidth() { l.width = width + 1 } -// LogConsumer consume logs from services and format them -type logConsumer struct { - ctx context.Context - presenters sync.Map // map[string]*presenter - width int - writer io.Writer - color bool - prefix bool -} - type presenter struct { colors colorFunc name string diff --git a/pkg/compose/convergence.go b/pkg/compose/convergence.go index 1db3bc3db..25b021cd8 100644 --- a/pkg/compose/convergence.go +++ b/pkg/compose/convergence.go @@ -553,7 +553,7 @@ func (s composeService) getLinks(ctx context.Context, projectName string, servic containerName := getCanonicalContainerName(c) links = append(links, format(containerName, linkName), - format(containerName, strings.Join([]string{linkServiceName, strconv.Itoa(number)}, Separator)), + format(containerName, linkServiceName+Separator+strconv.Itoa(number)), format(containerName, strings.Join([]string{projectName, linkServiceName, strconv.Itoa(number)}, Separator)), ) } diff --git a/pkg/compose/cp.go b/pkg/compose/cp.go index 558de13e2..d7fcd89e5 100644 --- a/pkg/compose/cp.go +++ b/pkg/compose/cp.go @@ -263,7 +263,7 @@ func (s *composeService) copyFromContainer(ctx context.Context, containerID, src } preArchive := content - if len(srcInfo.RebaseName) != 0 { + if srcInfo.RebaseName != "" { _, srcBase := archive.SplitPathDirEntry(srcInfo.Path) preArchive = archive.RebaseArchiveEntries(content, srcBase, srcInfo.RebaseName) } diff --git a/pkg/compose/create_test.go b/pkg/compose/create_test.go index 6c6a4f198..7a0e95c6f 100644 --- a/pkg/compose/create_test.go +++ b/pkg/compose/create_test.go @@ -22,7 +22,6 @@ import ( "sort" "testing" - "github.com/compose-spec/compose-go/types" composetypes "github.com/compose-spec/compose-go/types" "github.com/docker/compose/v2/pkg/api" moby "github.com/docker/docker/api/types" @@ -66,17 +65,17 @@ func TestBuildVolumeMount(t *testing.T) { } func TestServiceImageName(t *testing.T) { - assert.Equal(t, getImageName(types.ServiceConfig{Image: "myImage"}, "myProject"), "myImage") - assert.Equal(t, getImageName(types.ServiceConfig{Name: "aService"}, "myProject"), "myProject_aService") + assert.Equal(t, getImageName(composetypes.ServiceConfig{Image: "myImage"}, "myProject"), "myImage") + assert.Equal(t, getImageName(composetypes.ServiceConfig{Name: "aService"}, "myProject"), "myProject_aService") } func TestPrepareNetworkLabels(t *testing.T) { - project := types.Project{ + project := composetypes.Project{ Name: "myProject", - Networks: types.Networks(map[string]types.NetworkConfig{"skynet": {}}), + Networks: composetypes.Networks(map[string]composetypes.NetworkConfig{"skynet": {}}), } prepareNetworks(&project) - assert.DeepEqual(t, project.Networks["skynet"].Labels, types.Labels(map[string]string{ + assert.DeepEqual(t, project.Networks["skynet"].Labels, composetypes.Labels(map[string]string{ "com.docker.compose.network": "skynet", "com.docker.compose.project": "myProject", "com.docker.compose.version": api.ComposeVersion, diff --git a/pkg/compose/printer.go b/pkg/compose/printer.go index 7942c5641..cb1507759 100644 --- a/pkg/compose/printer.go +++ b/pkg/compose/printer.go @@ -32,6 +32,11 @@ type logPrinter interface { Cancel() } +type printer struct { + queue chan api.ContainerEvent + consumer api.LogConsumer +} + // newLogPrinter builds a LogPrinter passing containers logs to LogConsumer func newLogPrinter(consumer api.LogConsumer) logPrinter { queue := make(chan api.ContainerEvent) @@ -48,11 +53,6 @@ func (p *printer) Cancel() { } } -type printer struct { - queue chan api.ContainerEvent - consumer api.LogConsumer -} - func (p *printer) HandleEvent(event api.ContainerEvent) { p.queue <- event } diff --git a/pkg/utils/writer_test.go b/pkg/utils/writer_test.go index 7eedb844f..a36ad4770 100644 --- a/pkg/utils/writer_test.go +++ b/pkg/utils/writer_test.go @@ -27,13 +27,13 @@ func TestSplitWriter(t *testing.T) { w := GetWriter(func(line string) { lines = append(lines, line) }) - w.Write([]byte("h")) //nolint: errcheck - w.Write([]byte("e")) //nolint: errcheck - w.Write([]byte("l")) //nolint: errcheck - w.Write([]byte("l")) //nolint: errcheck - w.Write([]byte("o")) //nolint: errcheck - w.Write([]byte("\n")) //nolint: errcheck - w.Write([]byte("world!\n")) //nolint: errcheck + w.Write([]byte("h")) // nolint: errcheck + w.Write([]byte("e")) // nolint: errcheck + w.Write([]byte("l")) // nolint: errcheck + w.Write([]byte("l")) // nolint: errcheck + w.Write([]byte("o")) // nolint: errcheck + w.Write([]byte("\n")) // nolint: errcheck + w.Write([]byte("world!\n")) // nolint: errcheck assert.DeepEqual(t, lines, []string{"hello", "world!"}) }