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

format code with gofumpt #12365

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion cmd/cmdtrace/cmd_span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,4 @@ func TestGetFlags(t *testing.T) {
}
})
}

}
1 change: 0 additions & 1 deletion cmd/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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)
}
1 change: 0 additions & 1 deletion cmd/compose/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion cmd/compose/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
11 changes: 11 additions & 0 deletions cmd/formatter/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,67 +27,78 @@ 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
}
// Does not move cursor from its current position
fmt.Print(ansi("[2K"))
}

func MoveCursorUp(lines int) {
if disableAnsi {
return
}
// Does not add new lines
fmt.Print(ansi(fmt.Sprintf("[%dA", lines)))
}

func MoveCursorDown(lines int) {
if disableAnsi {
return
}
// 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
Expand Down
10 changes: 6 additions & 4 deletions cmd/formatter/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions cmd/formatter/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions internal/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 0 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,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
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/dryrunclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions pkg/compose/convergence.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,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))
Expand All @@ -557,7 +557,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"))
Expand Down Expand Up @@ -626,7 +627,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
}
Expand Down Expand Up @@ -809,7 +809,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
}
Expand Down
1 change: 0 additions & 1 deletion pkg/compose/convergence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,5 +432,4 @@ func TestCreateMobyContainer(t *testing.T) {
}, progress.ContextWriter(context.TODO()))
assert.NilError(t, err)
})

}
1 change: 0 additions & 1 deletion pkg/compose/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func (s *composeService) listContainersTargetedForCopy(ctx context.Context, proj
}
if direction == fromService {
return containers[:1], err

}
return containers, err
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,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)
}
Expand Down Expand Up @@ -255,7 +254,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,
Expand Down Expand Up @@ -883,7 +882,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" {
Expand Down Expand Up @@ -969,7 +968,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 {
Expand Down Expand Up @@ -1019,7 +1018,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 {
Expand Down Expand Up @@ -1383,7 +1382,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
}
Expand Down
1 change: 0 additions & 1 deletion pkg/compose/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/compose/down_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions pkg/compose/envresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 2 additions & 3 deletions pkg/compose/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func (s *composeService) createProjectFromContainers(containers []moby.Container
Image: c.Image,
Labels: c.Labels,
}

}
service.Scale = increment(service.Scale)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion pkg/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading
Loading