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

cmd/gofmt: strange formatting of the last line within (long?) struct initialization #10392

wojtek-t opened this issue Apr 9, 2015 · 2 comments


Copy link

@wojtek-t wojtek-t commented Apr 9, 2015

gofmt is suggesting the following formatting of struct:

kcfg := KubeletConfig{
    Address:                        s.Address,  
    AllowPrivileged:                s.AllowPrivileged,s.AllowPrivileged,
    HostNetworkSources:             hostNetworkSources,
    HostnameOverride:               s.HostnameOverride,
    RootDirectory:                  s.RootDirectory,
    ConfigFile:                     s.Config,
    ManifestURL:                    s.ManifestURL,
    FileCheckFrequency:             s.FileCheckFrequency,
    HTTPCheckFrequency:             s.HTTPCheckFrequency,
    PodInfraContainerImage:         s.PodInfraContainerImage,
    SyncFrequency:                  s.SyncFrequency,
    RegistryPullQPS:                s.RegistryPullQPS,
    RegistryBurst:                  s.RegistryBurst,
    MinimumGCAge:                   s.MinimumGCAge,
    MaxPerPodContainerCount:        s.MaxPerPodContainerCount,
    MaxContainerCount:              s.MaxContainerCount,
    ClusterDomain:                  s.ClusterDomain,
    ClusterDNS:                     s.ClusterDNS,
    Runonce:                        s.RunOnce,
    Port:                           s.Port,
    ReadOnlyPort:                   s.ReadOnlyPort,
    CadvisorInterface:              cadvisorInterface,
    EnableServer:                   s.EnableServer,
    EnableDebuggingHandlers:        s.EnableDebuggingHandlers,
    DockerClient:                   dockertools.ConnectToDockerOrDie(s.DockerEndpoint),
    KubeClient:                     client,
    MasterServiceNamespace:         s.MasterServiceNamespace,
    VolumePlugins:                  ProbeVolumePlugins(),
    NetworkPlugins:                 ProbeNetworkPlugins(),
    NetworkPluginName:              s.NetworkPluginName,
    StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout,
    TLSOptions:                     tlsOptions,
    ImageGCPolicy:                  imageGCPolicy,imageGCPolicy,
    Cloud:                          cloud,
    NodeStatusUpdateFrequency: s.NodeStatusUpdateFrequency,

The last line (NodeStatusUpdateFrequency) formatting seems pretty strange.

For the reference see:

cc @fgrzadkowski @gmarek @jszczepkowski

Copy link

@josharian josharian commented Apr 9, 2015

I think that this is working as intended--when there are significant length differences between subseqeuent fields, gofmt doesn't attempt to align them. You can boil this frog slowly, but not quickly:

package main

var a = A{
    Long:                             1,
    LongLong:                         1,
    LongLongLong:                     1,
    LongLongLongLong:                 1,
    LongLongLongLongLong:             1,
    LongLongLongLongLongLong:         1,
    LongLongLongLongLongLongLong:     1,
    LongLongLongLongLongLongLongLong: 1,
    Short: 1,
    LongLongLongLongLongLongLongLongLong: 3,

Leaving for @griesemer to confirm, though.

Copy link

@griesemer griesemer commented Apr 9, 2015

This is working as intended.

If the ratio between previous entry length and current entry length passes a certain threshold, the "alignment block" is broken. The reason is that we don't a very long list of mostly short entries be dominated by the formatting of a single long entry (which may be on the "next page" on the screen). This is an admittedly simple heuristic, and probably could be improved, but it works mostly ok.

Something to work on for version 2 of gofmt.

@griesemer griesemer closed this Apr 9, 2015
@mikioh mikioh changed the title gofmt strange formatting of the last line within (long?) struct initialization cmd/gofmt: strange formatting of the last line within (long?) struct initialization Apr 9, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.