Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
What does 'go version' print? go version 1.3.2 // According to fmt.Println(runtime.Version()) in playground. What steps reproduce the problem? If possible, include a link to a program on play.golang.org. 1. Open http://play.golang.org/p/E22kYjkJpS 2. Click button "Format" What happened? Comment at line 4 jumps to the right. What should have happened instead? Comment at line 4 should have probably stay where it was. Please provide any additional information below. My hypothesis is that gofmt wrongly computes the length of line 5 using also len() of the string literal as if it was a quoted string; in an attempt to align the comments at L4 and L7 as if they are adjacent. But the raw string literal has newlines embedded so they are not.
@cznic I believe your hypothesis is correct. The following example https://play.golang.org/p/-4qfL0qblf7 exhibits the same problem and the alignment of the 3rd foo is based on the string length of the raw string on the next line (the
The fix is probably to recognize newlines in escaped text sequences in the tabwriter and then flush the buffer contents up to the newline but keep the escape mode on: No matter the previous content, when the escaped text sequence containing a newline is written out, the resulting line break is going to break the existing formatting/column alignment.
This should probably only be done if enabled by a new flag in order to not break existing code that might rely on the current behavior.
go/printer then would simply have to set that flag.
Probably not too hard to do but requires thorough understanding of tabwriter internals (which is somewhat subtle).
Marking for 1.11 in case I find the muse to do it. Not urgent.