3 ms·
gofmt doesn't do that. It doesn't touch user-inserted line breaks (not to mention comments!)
by pcwalton 9y ago
gofmt doesn't do that. It doesn't touch user-inserted line breaks (not to mention comments!)
- ngrilly 9y agoI don't get your point. Let's say I have this program (which was goformatted): package main import ( "fmt" ) // commenting... // commenting... func main() { fmt.Println("hello", "world") fmt.Println( "hello", "world", ) } And I had log.Print("test") at the end of main(): package main import ( "fmt" ) // commenting... // commenting... func main() { fmt.Println("hello", "world") fmt.Println( "hello", "world", ) log.Print("test") } Then I run goimports to automatically update the import directive (goimports parses the source to build an AST, then modifies the AST, then reconverts it to source code): package main import ( "fmt" "log" ) // commenting... // commenting... func main() { fmt.Println("hello", "world") fmt.Println( "hello", "world", ) log.Print("test") } Everything is kept exactly as-is, except the added line "log" in the import directive. This round-trip mechanism is the main benefit of gofmt.