Skip to content

cmd/gofmt: extra indentations when adding comments  #32480

@a8m

Description

@a8m

I encounter an issue with gofmt, where adding a comment to the first line causes extra indentation to the rest of the lines.

For example, giving this block of code:

func main() {
	t1 := foo.Bar().
		Baz().
		Qux()
}

Adding a comment (//) after Bar() adds extra indentations to the lines below:

func main() {
	t1 := foo.Bar(). //
				Baz().
				Qux()
}

Playground

Same for this case:

func main() {
	t1 := foo.Bar(). // bar
				Baz(). // baz
				Qux()  // qux
}

Playground

Maybe I miss something, but I expect the formatting to be as follow:

func main() {
	t1 := foo.Bar(). // 
		Baz().
		Qux()
}

func main() {
	t1 := foo.Bar(). // bar
		Baz().   // baz
		Qux()    // qux
}

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