Skip to content

cmd/gofmt: extend column alignment to include assignments and declarations #23495

@savaki

Description

@savaki

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

Should apply to any version of go.

Does this issue reproduce with the latest release?

Yep. It's a formatting enhancement.

What operating system and processor architecture are you using (go env)?

Should happen in any environment.

What did you do?

Type the following and run it through gofmt:

  a.b.c = 123
  a.d = "def"
  a.e.f.g = 456
  h, i = 7, 8

  j := 123
  k.l := "def"
  k.m.n.o := 456
  p, q := 7, 8

  var r = "abc"
  var t, u = 1, 2
  var v int = 3

and nothing would change with the formatting

What did you expect to see?

I would like to see are the same rules gofmt currently applies to structs and maps to be more uniformly applied. Specifically to sequential assignments, sequential declarations with := and sequential declaration withs =.

So I'd like to see:

  a.b.c   = 123
  a.d     = "def"
  a.e.f.g = 456
  h, i    = 7, 8

  j       := 123
  k.l     := "def"
  k.m.n.o := 456
  p, q    := 7, 8

  var r     = "abc"
  var t, u  = 1, 2
  var v int = 3

What did you see instead?

Saw the original code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions