golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.62k stars 17.48k forks source link

cmd/gofmt: gofmt -r should preserve multiline formatting #18677

Open rogpeppe opened 7 years ago

rogpeppe commented 7 years ago

go version devel +ac05542 Wed Jan 11 01:39:54 2017 +0000 linux/amd64

gofmt -r does not work well when rewriting multi-line expressions.

Given this code:

package x

func f() {
    Foo{
        X: 99,
        Y: "hello",
    }
}

running:

gofmt -r 'Foo{X: a, Y: b} -> Foo{
    X: a,
    Y: []byte(b),
}'

results in:

package x

func f() {
    Foo{X: 99, Y: []byte(

        "hello")}

}

In general, if the replacement expression contains multiple lines, their placement is ignored.

rakyll commented 7 years ago

/cc @griesemer

griesemer commented 7 years ago

Unfortunate. Problem acknowledged but not high on the list of issues.