From 446e00520c1f8005700494fd70204a8d371ae56b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 10 Dec 2024 10:30:37 +0100 Subject: [PATCH] format code with gofumpt Format the code with gofumpt to prevent my IDE from reformatting every time I open a file. gofumpt provides a superset of gofmt, so should not impact users that are not using gofumpt. Signed-off-by: Sebastiaan van Stijn --- cmd/cmdtrace/cmd_span_test.go | 1 - cmd/compose/config.go | 1 - cmd/compose/create.go | 6 ++++-- cmd/compose/scale.go | 1 - cmd/compose/up_test.go | 1 - cmd/formatter/ansi.go | 11 +++++++++++ cmd/formatter/colors.go | 10 ++++++---- cmd/formatter/shortcut.go | 9 ++++++--- internal/variables.go | 6 ++---- pkg/api/api.go | 1 - pkg/api/dryrunclient.go | 4 ++-- pkg/compose/build.go | 1 - pkg/compose/compose.go | 2 -- pkg/compose/convergence.go | 11 ++++++----- pkg/compose/convergence_test.go | 1 - pkg/compose/cp.go | 1 - pkg/compose/create.go | 12 +++++------- pkg/compose/dependencies.go | 1 - pkg/compose/down_test.go | 3 ++- pkg/compose/envresolver.go | 6 ++---- pkg/compose/generate.go | 5 ++--- pkg/compose/images.go | 1 - pkg/compose/kill_test.go | 3 ++- pkg/compose/logs.go | 1 - pkg/compose/pause.go | 2 -- pkg/compose/ps_test.go | 9 ++++++--- pkg/compose/pull.go | 3 ++- pkg/compose/scale.go | 1 - pkg/compose/start.go | 3 ++- pkg/compose/watch.go | 4 ++-- pkg/compose/watch_test.go | 3 +-- pkg/e2e/build_test.go | 8 -------- pkg/e2e/compose_test.go | 2 -- pkg/e2e/framework.go | 1 - pkg/e2e/logs_test.go | 1 - pkg/e2e/networks_test.go | 3 --- pkg/e2e/pull_test.go | 1 - pkg/e2e/up_test.go | 1 - pkg/e2e/watch_test.go | 2 -- pkg/progress/json.go | 4 ++-- pkg/progress/noop.go | 3 +-- pkg/progress/tty.go | 4 +--- pkg/utils/writer_test.go | 1 - pkg/watch/notify.go | 7 ++----- 44 files changed, 69 insertions(+), 93 deletions(-) diff --git a/cmd/cmdtrace/cmd_span_test.go b/cmd/cmdtrace/cmd_span_test.go index 7ee88656e..3d661eda8 100644 --- a/cmd/cmdtrace/cmd_span_test.go +++ b/cmd/cmdtrace/cmd_span_test.go @@ -60,5 +60,4 @@ func TestGetFlags(t *testing.T) { } }) } - } diff --git a/cmd/compose/config.go b/cmd/compose/config.go index 5e1dd3ffd..c401c0335 100644 --- a/cmd/compose/config.go +++ b/cmd/compose/config.go @@ -348,7 +348,6 @@ func runHash(ctx context.Context, dockerCli command.Cli, opts configOptions) err } hash, err := compose.ServiceHash(s) - if err != nil { return err } diff --git a/cmd/compose/create.go b/cmd/compose/create.go index 856b911fc..54e6060e8 100644 --- a/cmd/compose/create.go +++ b/cmd/compose/create.go @@ -198,7 +198,9 @@ func applyScaleOpts(project *types.Project, opts []string) error { } func (opts createOptions) isPullPolicyValid() bool { - pullPolicies := []string{types.PullPolicyAlways, types.PullPolicyNever, types.PullPolicyBuild, - types.PullPolicyMissing, types.PullPolicyIfNotPresent} + pullPolicies := []string{ + types.PullPolicyAlways, types.PullPolicyNever, types.PullPolicyBuild, + types.PullPolicyMissing, types.PullPolicyIfNotPresent, + } return slices.Contains(pullPolicies, opts.Pull) } diff --git a/cmd/compose/scale.go b/cmd/compose/scale.go index 22e8e71dd..628fca441 100644 --- a/cmd/compose/scale.go +++ b/cmd/compose/scale.go @@ -92,7 +92,6 @@ func parseServicesReplicasArgs(args []string) (map[string]int, error) { return nil, fmt.Errorf("invalid scale specifier: %s", arg) } intValue, err := strconv.Atoi(val) - if err != nil { return nil, fmt.Errorf("invalid scale specifier: can't parse replica value as int: %v", arg) } diff --git a/cmd/compose/up_test.go b/cmd/compose/up_test.go index cf41d2d8f..9019a40ff 100644 --- a/cmd/compose/up_test.go +++ b/cmd/compose/up_test.go @@ -47,5 +47,4 @@ func TestApplyScaleOpt(t *testing.T) { assert.NilError(t, err) assert.Equal(t, *bar.Scale, 3) assert.Equal(t, *bar.Deploy.Replicas, 3) - } diff --git a/cmd/formatter/ansi.go b/cmd/formatter/ansi.go index c6e4d33a3..fb7ebaa2d 100644 --- a/cmd/formatter/ansi.go +++ b/cmd/formatter/ansi.go @@ -27,42 +27,49 @@ var disableAnsi bool func ansi(code string) string { return fmt.Sprintf("\033%s", code) } + func SaveCursor() { if disableAnsi { return } fmt.Print(ansi("7")) } + func RestoreCursor() { if disableAnsi { return } fmt.Print(ansi("8")) } + func HideCursor() { if disableAnsi { return } fmt.Print(ansi("[?25l")) } + func ShowCursor() { if disableAnsi { return } fmt.Print(ansi("[?25h")) } + func MoveCursor(y, x int) { if disableAnsi { return } fmt.Print(ansi(fmt.Sprintf("[%d;%dH", y, x))) } + func MoveCursorX(pos int) { if disableAnsi { return } fmt.Print(ansi(fmt.Sprintf("[%dG", pos))) } + func ClearLine() { if disableAnsi { return @@ -70,6 +77,7 @@ func ClearLine() { // Does not move cursor from its current position fmt.Print(ansi("[2K")) } + func MoveCursorUp(lines int) { if disableAnsi { return @@ -77,6 +85,7 @@ func MoveCursorUp(lines int) { // Does not add new lines fmt.Print(ansi(fmt.Sprintf("[%dA", lines))) } + func MoveCursorDown(lines int) { if disableAnsi { return @@ -84,10 +93,12 @@ func MoveCursorDown(lines int) { // Does not add new lines fmt.Print(ansi(fmt.Sprintf("[%dB", lines))) } + func NewLine() { // Like \n fmt.Print("\012") } + func lenAnsi(s string) int { // len has into consideration ansi codes, if we want // the len of the actual len(string) we need to strip diff --git a/cmd/formatter/colors.go b/cmd/formatter/colors.go index a2f57f438..cc13bc209 100644 --- a/cmd/formatter/colors.go +++ b/cmd/formatter/colors.go @@ -104,10 +104,12 @@ func makeColorFunc(code string) colorFunc { } } -var nextColor = rainbowColor -var rainbow []colorFunc -var currentIndex = 0 -var mutex sync.Mutex +var ( + nextColor = rainbowColor + rainbow []colorFunc + currentIndex = 0 + mutex sync.Mutex +) func rainbowColor() colorFunc { mutex.Lock() diff --git a/cmd/formatter/shortcut.go b/cmd/formatter/shortcut.go index 0d8516975..d6674e8d1 100644 --- a/cmd/formatter/shortcut.go +++ b/cmd/formatter/shortcut.go @@ -110,8 +110,10 @@ type LogKeyboard struct { signalChannel chan<- os.Signal } -var KeyboardManager *LogKeyboard -var eg multierror.Group +var ( + KeyboardManager *LogKeyboard + eg multierror.Group +) func NewKeyboardManager(ctx context.Context, isDockerDesktopActive, isWatchConfigured bool, sc chan<- os.Signal, @@ -206,7 +208,7 @@ func (lk *LogKeyboard) navigationMenu() string { if openDDInfo != "" || openDDUI != "" { watchInfo = navColor(" ") } - var isEnabled = " Enable" + isEnabled := " Enable" if lk.Watch.Watching { isEnabled = " Disable" } @@ -260,6 +262,7 @@ func (lk *LogKeyboard) openDDComposeUI(ctx context.Context, project *types.Proje }), ) } + func (lk *LogKeyboard) openDDWatchDocs(ctx context.Context, project *types.Project) { eg.Go(tracing.EventWrapFuncForErrGroup(ctx, "menu/gui/watch", tracing.SpanOptions{}, func(ctx context.Context) error { diff --git a/internal/variables.go b/internal/variables.go index 876b3d3ca..28b701cc2 100644 --- a/internal/variables.go +++ b/internal/variables.go @@ -16,7 +16,5 @@ package internal -var ( - // Version is the version of the CLI injected in compilation time - Version = "dev" -) +// Version is the version of the CLI injected in compilation time +var Version = "dev" diff --git a/pkg/api/api.go b/pkg/api/api.go index f0e813803..8d2d12803 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -431,7 +431,6 @@ func (e Event) String() string { attr = append(attr, fmt.Sprintf("%s=%s", k, v)) } return fmt.Sprintf("%s container %s %s (%s)\n", t, e.Status, e.Container, strings.Join(attr, ", ")) - } // ListOptions group options of the ls API diff --git a/pkg/api/dryrunclient.go b/pkg/api/dryrunclient.go index 0470ead56..ef6269af5 100644 --- a/pkg/api/dryrunclient.go +++ b/pkg/api/dryrunclient.go @@ -101,7 +101,8 @@ func (d *DryRunClient) ContainerAttach(ctx context.Context, container string, op } func (d *DryRunClient) ContainerCreate(ctx context.Context, config *containerType.Config, hostConfig *containerType.HostConfig, - networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (containerType.CreateResponse, error) { + networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string, +) (containerType.CreateResponse, error) { d.containers = append(d.containers, moby.Container{ ID: containerName, Names: []string{containerName}, @@ -229,7 +230,6 @@ func (d *DryRunClient) ImageInspectWithRaw(ctx context.Context, imageName string default: return d.apiClient.ImageInspectWithRaw(ctx, imageName) } - } func (d *DryRunClient) ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) { diff --git a/pkg/compose/build.go b/pkg/compose/build.go index 4390f5c54..6a47a5cf1 100644 --- a/pkg/compose/build.go +++ b/pkg/compose/build.go @@ -134,7 +134,6 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti fmt.Sprintf("building with %q instance using %s driver", b.Name, b.Driver), fmt.Sprintf("%s:%s", b.Driver, b.Name), )) - if err != nil { return nil, err } diff --git a/pkg/compose/compose.go b/pkg/compose/compose.go index fb0088428..18769e645 100644 --- a/pkg/compose/compose.go +++ b/pkg/compose/compose.go @@ -187,7 +187,6 @@ func (s *composeService) projectFromName(containers Containers, projectName stri Image: c.Image, Labels: c.Labels, } - } service.Scale = increment(service.Scale) set[serviceLabel] = service @@ -321,7 +320,6 @@ func (s *composeService) RuntimeVersion(ctx context.Context) (string, error) { runtimeVersion.val = version.APIVersion }) return runtimeVersion.val, runtimeVersion.err - } func (s *composeService) isDesktopIntegrationActive() bool { diff --git a/pkg/compose/convergence.go b/pkg/compose/convergence.go index ee7284196..c6abb6ce1 100644 --- a/pkg/compose/convergence.go +++ b/pkg/compose/convergence.go @@ -581,11 +581,11 @@ func nextContainerNumber(containers []moby.Container) int { } } return maxNumber + 1 - } func (s *composeService) createContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, - name string, number int, opts createOptions) (container moby.Container, err error) { + name string, number int, opts createOptions, +) (container moby.Container, err error) { w := progress.ContextWriter(ctx) eventName := "Container " + name w.Event(progress.CreatingEvent(eventName)) @@ -598,7 +598,8 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro } func (s *composeService) recreateContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, - replaced moby.Container, inherit bool, timeout *time.Duration) (moby.Container, error) { + replaced moby.Container, inherit bool, timeout *time.Duration, +) (moby.Container, error) { var created moby.Container w := progress.ContextWriter(ctx) w.Event(progress.NewEvent(getContainerProgressName(replaced), progress.Working, "Recreate")) @@ -667,7 +668,6 @@ func (s *composeService) createMobyContainer(ctx context.Context, ) (moby.Container, error) { var created moby.Container cfgs, err := s.getCreateConfigs(ctx, project, service, number, inherit, opts) - if err != nil { return created, err } @@ -850,7 +850,8 @@ func (s *composeService) isServiceCompleted(ctx context.Context, containers Cont func (s *composeService) startService(ctx context.Context, project *types.Project, service types.ServiceConfig, containers Containers, listener api.ContainerEventListener, - timeout time.Duration) error { + timeout time.Duration, +) error { if service.Deploy != nil && service.Deploy.Replicas != nil && *service.Deploy.Replicas == 0 { return nil } diff --git a/pkg/compose/convergence_test.go b/pkg/compose/convergence_test.go index dc981fdaf..0f15afc57 100644 --- a/pkg/compose/convergence_test.go +++ b/pkg/compose/convergence_test.go @@ -432,5 +432,4 @@ func TestCreateMobyContainer(t *testing.T) { }, progress.ContextWriter(context.TODO())) assert.NilError(t, err) }) - } diff --git a/pkg/compose/cp.go b/pkg/compose/cp.go index f65e79196..3b6e5f00d 100644 --- a/pkg/compose/cp.go +++ b/pkg/compose/cp.go @@ -139,7 +139,6 @@ func (s *composeService) listContainersTargetedForCopy(ctx context.Context, proj } if direction == fromService { return containers[:1], err - } return containers, err } diff --git a/pkg/compose/create.go b/pkg/compose/create.go index 13466756b..e26937ee5 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -205,7 +205,6 @@ func (s *composeService) ensureProjectVolumes(ctx context.Context, project *type } return nil }() - if err != nil { progress.ContextWriter(ctx).TailMsgf("Failed to prepare Synchronized file shares: %v", err) } @@ -259,7 +258,7 @@ func (s *composeService) getCreateConfigs(ctx context.Context, if err != nil { return createConfigs{}, err } - var containerConfig = container.Config{ + containerConfig := container.Config{ Hostname: service.Hostname, Domainname: service.DomainName, User: service.User, @@ -892,7 +891,7 @@ func requireMountAPI(bind *types.ServiceVolumeBind) bool { } func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) { - var mounts = map[string]mount.Mount{} + mounts := map[string]mount.Mount{} if inherit != nil { for _, m := range inherit.Mounts { if m.Type == "tmpfs" { @@ -978,7 +977,7 @@ func fillBindMounts(p types.Project, s types.ServiceConfig, m map[string]mount.M } func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount.Mount, error) { - var mounts = map[string]mount.Mount{} + mounts := map[string]mount.Mount{} configsBaseDir := "/" for _, config := range s.Configs { @@ -1028,7 +1027,7 @@ func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount } func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount.Mount, error) { - var mounts = map[string]mount.Mount{} + mounts := map[string]mount.Mount{} secretsDir := "/run/secrets/" for _, secret := range s.Secrets { @@ -1392,7 +1391,6 @@ func (s *composeService) resolveExternalNetwork(ctx context.Context, n *types.Ne networks, err := s.apiClient().NetworkList(ctx, network.ListOptions{ Filters: filters.NewArgs(filters.Arg("name", n.Name)), }) - if err != nil { return "", err } @@ -1467,7 +1465,7 @@ func (s *composeService) ensureVolume(ctx context.Context, name string, volume t } actual, ok := inspected.Labels[api.ConfigHashLabel] if ok && actual != expected { - var confirm = assumeYes + confirm := assumeYes if !assumeYes { msg := fmt.Sprintf("Volume %q exists but doesn't match configuration in compose file. Recreate (data will be lost)?", volume.Name) confirm, err = prompt.NewPrompt(s.stdin(), s.stdout()).Confirm(msg, false) diff --git a/pkg/compose/dependencies.go b/pkg/compose/dependencies.go index 3d644f78e..a664deab3 100644 --- a/pkg/compose/dependencies.go +++ b/pkg/compose/dependencies.go @@ -438,7 +438,6 @@ func (g *Graph) HasCycles() (bool, error) { if !utils.StringContains(discovered, vertex.Key) && !utils.StringContains(finished, vertex.Key) { var err error discovered, finished, err = g.visit(vertex.Key, path, discovered, finished) - if err != nil { return true, err } diff --git a/pkg/compose/down_test.go b/pkg/compose/down_test.go index 184d45d0e..996e479a8 100644 --- a/pkg/compose/down_test.go +++ b/pkg/compose/down_test.go @@ -211,7 +211,8 @@ func TestDownRemoveOrphans(t *testing.T) { { Name: "myProject_default", Labels: map[string]string{compose.NetworkLabel: "default"}, - }}, nil) + }, + }, nil) stopOptions := containerType.StopOptions{} api.EXPECT().ContainerStop(gomock.Any(), "123", stopOptions).Return(nil) diff --git a/pkg/compose/envresolver.go b/pkg/compose/envresolver.go index 0d12c3dc5..a86d93519 100644 --- a/pkg/compose/envresolver.go +++ b/pkg/compose/envresolver.go @@ -21,10 +21,8 @@ import ( "strings" ) -var ( - // isCaseInsensitiveEnvVars is true on platforms where environment variable names are treated case-insensitively. - isCaseInsensitiveEnvVars = (runtime.GOOS == "windows") -) +// isCaseInsensitiveEnvVars is true on platforms where environment variable names are treated case-insensitively. +var isCaseInsensitiveEnvVars = (runtime.GOOS == "windows") // envResolver returns resolver for environment variables suitable for the current platform. // Expected to be used with `MappingWithEquals.Resolve`. diff --git a/pkg/compose/generate.go b/pkg/compose/generate.go index 5f2d5436a..ec72f03e0 100644 --- a/pkg/compose/generate.go +++ b/pkg/compose/generate.go @@ -92,7 +92,6 @@ func (s *composeService) createProjectFromContainers(containers []moby.Container Image: c.Image, Labels: c.Labels, } - } service.Scale = increment(service.Scale) @@ -172,7 +171,8 @@ func (s *composeService) toComposeHealthCheck(healthConfig *containerType.Health } func (s *composeService) toComposeVolumes(volumes []moby.MountPoint) (map[string]types.VolumeConfig, - []types.ServiceVolumeConfig, map[string]types.SecretConfig, []types.ServiceSecretConfig) { + []types.ServiceVolumeConfig, map[string]types.SecretConfig, []types.ServiceSecretConfig, +) { volumeConfigs := make(map[string]types.VolumeConfig) secretConfigs := make(map[string]types.SecretConfig) var serviceVolumeConfigs []types.ServiceVolumeConfig @@ -227,7 +227,6 @@ func (s *composeService) toComposeNetwork(networks map[string]*network.EndpointS networkConfigs[name] = types.NetworkConfig{ Internal: inspect.Internal, } - } serviceNetworkConfigs[name] = &types.ServiceNetworkConfig{ Aliases: net.Aliases, diff --git a/pkg/compose/images.go b/pkg/compose/images.go index 88fd56ba6..91c3e718e 100644 --- a/pkg/compose/images.go +++ b/pkg/compose/images.go @@ -48,7 +48,6 @@ func (s *composeService) Images(ctx context.Context, projectName string, options for _, c := range allContainers { if utils.StringContains(options.Services, c.Labels[api.ServiceLabel]) { containers = append(containers, c) - } } } else { diff --git a/pkg/compose/kill_test.go b/pkg/compose/kill_test.go index c51b603eb..69a4c480d 100644 --- a/pkg/compose/kill_test.go +++ b/pkg/compose/kill_test.go @@ -123,7 +123,8 @@ func containerLabels(service string, oneOff bool) map[string]string { compose.ServiceLabel: service, compose.ConfigFilesLabel: composefile, compose.WorkingDirLabel: workingdir, - compose.ProjectLabel: strings.ToLower(testProject)} + compose.ProjectLabel: strings.ToLower(testProject), + } if oneOff { labels[compose.OneoffLabel] = "True" } diff --git a/pkg/compose/logs.go b/pkg/compose/logs.go index c5ac1d749..dee4b8bf3 100644 --- a/pkg/compose/logs.go +++ b/pkg/compose/logs.go @@ -39,7 +39,6 @@ func (s *composeService) Logs( consumer api.LogConsumer, options api.LogOptions, ) error { - var containers Containers var err error diff --git a/pkg/compose/pause.go b/pkg/compose/pause.go index 575222846..1032539f8 100644 --- a/pkg/compose/pause.go +++ b/pkg/compose/pause.go @@ -54,7 +54,6 @@ func (s *composeService) pause(ctx context.Context, projectName string, options } return err }) - }) return eg.Wait() } @@ -86,7 +85,6 @@ func (s *composeService) unPause(ctx context.Context, projectName string, option } return err }) - }) return eg.Wait() } diff --git a/pkg/compose/ps_test.go b/pkg/compose/ps_test.go index 681200b76..c4b5ffe63 100644 --- a/pkg/compose/ps_test.go +++ b/pkg/compose/ps_test.go @@ -55,7 +55,8 @@ func TestPs(t *testing.T) { containers, err := tested.Ps(ctx, strings.ToLower(testProject), compose.PsOptions{}) expected := []compose.ContainerSummary{ - {ID: "123", Name: "123", Names: []string{"/123"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service1", + { + ID: "123", Name: "123", Names: []string{"/123"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service1", State: "running", Health: "healthy", Publishers: []compose.PortPublisher{}, Labels: map[string]string{ compose.ProjectLabel: strings.ToLower(testProject), @@ -64,7 +65,8 @@ func TestPs(t *testing.T) { compose.ServiceLabel: "service1", }, }, - {ID: "456", Name: "456", Names: []string{"/456"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service1", + { + ID: "456", Name: "456", Names: []string{"/456"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service1", State: "running", Health: "", Publishers: []compose.PortPublisher{{URL: "localhost", TargetPort: 90, PublishedPort: 80}}, Labels: map[string]string{ @@ -74,7 +76,8 @@ func TestPs(t *testing.T) { compose.ServiceLabel: "service1", }, }, - {ID: "789", Name: "789", Names: []string{"/789"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service2", + { + ID: "789", Name: "789", Names: []string{"/789"}, Image: "foo", Project: strings.ToLower(testProject), Service: "service2", State: "exited", Health: "", ExitCode: 130, Publishers: []compose.PortPublisher{}, Labels: map[string]string{ compose.ProjectLabel: strings.ToLower(testProject), diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index a4f37eae7..03a885a1e 100644 --- a/pkg/compose/pull.go +++ b/pkg/compose/pull.go @@ -175,7 +175,8 @@ func getUnwrappedErrorMessage(err error) string { } func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, - configFile driver.Auth, w progress.Writer, quietPull bool, defaultPlatform string) (string, error) { + configFile driver.Auth, w progress.Writer, quietPull bool, defaultPlatform string, +) (string, error) { w.Event(progress.Event{ ID: service.Name, Status: progress.Working, diff --git a/pkg/compose/scale.go b/pkg/compose/scale.go index 985cc129d..0f3cd6951 100644 --- a/pkg/compose/scale.go +++ b/pkg/compose/scale.go @@ -31,6 +31,5 @@ func (s *composeService) Scale(ctx context.Context, project *types.Project, opti return err } return s.start(ctx, project.Name, api.StartOptions{Project: project, Services: options.Services}, nil) - }), s.stdinfo()) } diff --git a/pkg/compose/start.go b/pkg/compose/start.go index f5dbd9101..c45de4aed 100644 --- a/pkg/compose/start.go +++ b/pkg/compose/start.go @@ -180,7 +180,8 @@ type containerWatchFn func(container moby.Container, t time.Time) error // watchContainers uses engine events to capture container start/die and notify ContainerEventListener func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo projectName string, services, required []string, - listener api.ContainerEventListener, containers Containers, onStart, onRecreate containerWatchFn) error { + listener api.ContainerEventListener, containers Containers, onStart, onRecreate containerWatchFn, +) error { if len(containers) == 0 { return nil } diff --git a/pkg/compose/watch.go b/pkg/compose/watch.go index cc22106f4..0a070058b 100644 --- a/pkg/compose/watch.go +++ b/pkg/compose/watch.go @@ -69,6 +69,7 @@ func (s *composeService) getSyncImplementation(project *types.Project) (sync.Syn return sync.NewTar(project.Name, tarDockerClient{s: s}), nil } + func (s *composeService) shouldWatch(project *types.Project) bool { var shouldWatch bool for i := range project.Services { @@ -84,6 +85,7 @@ func (s *composeService) shouldWatch(project *types.Project) bool { func (s *composeService) Watch(ctx context.Context, project *types.Project, services []string, options api.WatchOptions) error { return s.watch(ctx, nil, project, services, options) } + func (s *composeService) watch(ctx context.Context, syncChannel chan bool, project *types.Project, services []string, options api.WatchOptions) error { //nolint: gocyclo var err error if project, err = project.WithSelectedServices(services); err != nil { @@ -553,7 +555,6 @@ func (s *composeService) rebuild(ctx context.Context, project *types.Project, se // restrict the build to ONLY this service, not any of its dependencies options.Build.Services = []string{serviceName} imageNameToIdMap, err := s.build(ctx, project, *options.Build, nil) - if err != nil { options.LogTo.Log(api.WatchLogger, fmt.Sprintf("Build failed. Error: %v", err)) return err @@ -626,7 +627,6 @@ func (s *composeService) pruneDanglingImagesOnRebuild(ctx context.Context, proje filters.Arg("label", api.ProjectLabel+"="+projectName), ), }) - if err != nil { logrus.Debugf("Failed to list images: %v", err) return diff --git a/pkg/compose/watch_test.go b/pkg/compose/watch_test.go index 0bd1ee16f..036e1677b 100644 --- a/pkg/compose/watch_test.go +++ b/pkg/compose/watch_test.go @@ -50,7 +50,7 @@ func TestDebounceBatching(t *testing.T) { matcher := watch.EmptyMatcher{} eventBatchCh := batchDebounceEvents(ctx, clock, quietPeriod, ch) for i := 0; i < 100; i++ { - var path = "/a" + path := "/a" if i%2 == 0 { path = "/b" } @@ -121,7 +121,6 @@ func (s stdLogger) Status(container, msg string) { } func (s stdLogger) Register(container string) { - } func TestWatch_Sync(t *testing.T) { diff --git a/pkg/e2e/build_test.go b/pkg/e2e/build_test.go index 3cbfb0825..3e19f2acb 100644 --- a/pkg/e2e/build_test.go +++ b/pkg/e2e/build_test.go @@ -32,7 +32,6 @@ import ( ) func TestLocalComposeBuild(t *testing.T) { - for _, env := range []string{"DOCKER_BUILDKIT=0", "DOCKER_BUILDKIT=1", "DOCKER_BUILDKIT=1,COMPOSE-BAKE=1"} { c := NewCLI(t, WithEnv(strings.Split(env, ",")...)) @@ -135,7 +134,6 @@ func TestLocalComposeBuild(t *testing.T) { c.RunDockerOrExitError(t, "rmi", "-f", "custom-nginx") }) } - } func TestBuildSSH(t *testing.T) { @@ -150,7 +148,6 @@ func TestBuildSSH(t *testing.T) { ExitCode: 1, Err: "invalid empty ssh agent socket: make sure SSH_AUTH_SOCK is set", }) - }) t.Run("build succeed with ssh from Compose file", func(t *testing.T) { @@ -218,7 +215,6 @@ func TestBuildTags(t *testing.T) { c := NewParallelCLI(t) t.Run("build with tags", func(t *testing.T) { - // ensure local test run does not reuse previously build image c.RunDockerOrExitError(t, "rmi", "build-test-tags") @@ -318,7 +314,6 @@ func TestBuildPlatformsWithCorrectBuildxConfig(t *testing.T) { assert.NilError(t, res.Error, res.Stderr()) res.Assert(t, icmd.Expected{Out: "I am building for linux/arm64"}) res.Assert(t, icmd.Expected{Out: "I am building for linux/amd64"}) - }) t.Run("multi-arch multi service builds ok", func(t *testing.T) { @@ -355,7 +350,6 @@ func TestBuildPlatformsWithCorrectBuildxConfig(t *testing.T) { assert.NilError(t, res.Error, res.Stderr()) res.Assert(t, icmd.Expected{Out: "I am building for linux/386"}) }) - } func TestBuildPrivileged(t *testing.T) { @@ -445,7 +439,6 @@ Switch to a different driver, or turn on the containerd image store, and try aga Err: "the classic builder doesn't support privileged mode, set DOCKER_BUILDKIT=1 to use BuildKit", }) }) - } func TestBuildBuilder(t *testing.T) { @@ -472,7 +465,6 @@ func TestBuildBuilder(t *testing.T) { Err: fmt.Sprintf(`no builder %q found`, "unknown-builder"), }) }) - } func TestBuildEntitlements(t *testing.T) { diff --git a/pkg/e2e/compose_test.go b/pkg/e2e/compose_test.go index 81f5dfe0b..0717bffe1 100644 --- a/pkg/e2e/compose_test.go +++ b/pkg/e2e/compose_test.go @@ -83,7 +83,6 @@ func TestLocalComposeUp(t *testing.T) { t.Run("check user labels", func(t *testing.T) { res := c.RunDockerCmd(t, "inspect", projectName+"-web-1") res.Assert(t, icmd.Expected{Out: `"my-label": "test"`}) - }) t.Run("check healthcheck output", func(t *testing.T) { @@ -391,7 +390,6 @@ func TestNestedDotEnv(t *testing.T) { ExitCode: 0, Out: "root sub win=sub", }) - } func TestUnnecessaryResources(t *testing.T) { diff --git a/pkg/e2e/framework.go b/pkg/e2e/framework.go index cb795e261..40156d092 100644 --- a/pkg/e2e/framework.go +++ b/pkg/e2e/framework.go @@ -133,7 +133,6 @@ func copyLocalConfig(t testing.TB, configDir string) { // initializePlugins copies the necessary plugin files to the temporary config // directory for the test. func initializePlugins(t testing.TB, configDir string) { - t.Cleanup(func() { if t.Failed() { if conf, err := os.ReadFile(filepath.Join(configDir, "config.json")); err == nil { diff --git a/pkg/e2e/logs_test.go b/pkg/e2e/logs_test.go index 01abed8f4..de5c22ffe 100644 --- a/pkg/e2e/logs_test.go +++ b/pkg/e2e/logs_test.go @@ -128,6 +128,5 @@ func expectOutput(res *icmd.Result, expected string) func(t poll.LogT) poll.Resu return poll.Success() } return poll.Continue("condition not met") - } } diff --git a/pkg/e2e/networks_test.go b/pkg/e2e/networks_test.go index 87495b783..c74687adc 100644 --- a/pkg/e2e/networks_test.go +++ b/pkg/e2e/networks_test.go @@ -142,9 +142,7 @@ func TestNetworkModes(t *testing.T) { t.Run("run with service mode dependency", func(t *testing.T) { res := c.RunDockerComposeCmd(t, "-f", "./fixtures/network-test/compose.yaml", "--project-name", projectName, "run", "-T", "mydb", "echo", "success") res.Assert(t, icmd.Expected{Out: "success"}) - }) - } func TestNetworkConfigChanged(t *testing.T) { @@ -182,5 +180,4 @@ func TestMacAddress(t *testing.T) { }) res := c.RunDockerCmd(t, "inspect", fmt.Sprintf("%s-test-1", projectName), "-f", "{{ (index .NetworkSettings.Networks \"network_mac_address_default\" ).MacAddress }}") res.Assert(t, icmd.Expected{Out: "00:e0:84:35:d0:e8"}) - } diff --git a/pkg/e2e/pull_test.go b/pkg/e2e/pull_test.go index dc7545f61..8534a8bde 100644 --- a/pkg/e2e/pull_test.go +++ b/pkg/e2e/pull_test.go @@ -89,5 +89,4 @@ func TestComposePull(t *testing.T) { res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull", "--ignore-pull-failures") res.Assert(t, icmd.Expected{Err: "Some service image(s) must be built from source by running:"}) }) - } diff --git a/pkg/e2e/up_test.go b/pkg/e2e/up_test.go index 5f4fb9c0c..4d7202c14 100644 --- a/pkg/e2e/up_test.go +++ b/pkg/e2e/up_test.go @@ -152,7 +152,6 @@ func TestScaleDoesntRecreate(t *testing.T) { res := c.RunDockerComposeCmd(t, "-f", "fixtures/simple-composefile/compose.yaml", "--project-name", projectName, "up", "--scale", "simple=2", "-d") assert.Check(t, !strings.Contains(res.Combined(), "Recreated")) - } func TestUpWithDependencyNotRequired(t *testing.T) { diff --git a/pkg/e2e/watch_test.go b/pkg/e2e/watch_test.go index 53d9a3ced..7c7011b24 100644 --- a/pkg/e2e/watch_test.go +++ b/pkg/e2e/watch_test.go @@ -35,7 +35,6 @@ import ( ) func TestWatch(t *testing.T) { - services := []string{"alpine", "busybox", "debian"} for _, svcName := range services { t.Run(svcName, func(t *testing.T) { @@ -133,7 +132,6 @@ func TestRebuildOnDotEnvWithExternalNetwork(t *testing.T) { } }) testComplete.Store(true) - } // NOTE: these tests all share a single Compose file but are safe to run diff --git a/pkg/progress/json.go b/pkg/progress/json.go index aa7e9fb99..219eac9b2 100644 --- a/pkg/progress/json.go +++ b/pkg/progress/json.go @@ -51,7 +51,7 @@ func (p *jsonWriter) Start(ctx context.Context) error { } func (p *jsonWriter) Event(e Event) { - var message = &jsonMessage{ + message := &jsonMessage{ DryRun: p.dryRun, Tail: false, ID: e.ID, @@ -75,7 +75,7 @@ func (p *jsonWriter) Events(events []Event) { } func (p *jsonWriter) TailMsgf(msg string, args ...interface{}) { - var message = &jsonMessage{ + message := &jsonMessage{ DryRun: p.dryRun, Tail: true, ID: "", diff --git a/pkg/progress/noop.go b/pkg/progress/noop.go index 98852705c..5ef92b611 100644 --- a/pkg/progress/noop.go +++ b/pkg/progress/noop.go @@ -20,8 +20,7 @@ import ( "context" ) -type noopWriter struct { -} +type noopWriter struct{} func (p *noopWriter) Start(ctx context.Context) error { return nil diff --git a/pkg/progress/tty.go b/pkg/progress/tty.go index e4ec1bf05..aa345ab53 100644 --- a/pkg/progress/tty.go +++ b/pkg/progress/tty.go @@ -345,6 +345,4 @@ func lenAnsi(s string) int { return length } -var ( - percentChars = strings.Split("⠀⡀⣀⣄⣤⣦⣶⣷⣿", "") -) +var percentChars = strings.Split("⠀⡀⣀⣄⣤⣦⣶⣷⣿", "") diff --git a/pkg/utils/writer_test.go b/pkg/utils/writer_test.go index 7383a3e87..bb7aed037 100644 --- a/pkg/utils/writer_test.go +++ b/pkg/utils/writer_test.go @@ -36,5 +36,4 @@ func TestSplitWriter(t *testing.T) { w.Write([]byte("\n")) w.Write([]byte("world!\n")) assert.DeepEqual(t, lines, []string{"hello", "world!"}) - } diff --git a/pkg/watch/notify.go b/pkg/watch/notify.go index 61b6b16ec..653d536dd 100644 --- a/pkg/watch/notify.go +++ b/pkg/watch/notify.go @@ -28,9 +28,7 @@ import ( "github.com/tilt-dev/fsnotify" ) -var ( - numberOfWatches = expvar.NewInt("watch.naive.numberOfWatches") -) +var numberOfWatches = expvar.NewInt("watch.naive.numberOfWatches") type FileEvent struct { path string @@ -76,8 +74,7 @@ type PathMatcher interface { MatchesEntireDir(file string) (bool, error) } -type EmptyMatcher struct { -} +type EmptyMatcher struct{} func (EmptyMatcher) Matches(f string) (bool, error) { return false, nil } func (EmptyMatcher) MatchesEntireDir(f string) (bool, error) { return false, nil }