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.
cmd/gofmt: remove tabs from comments #7972
What does 'go version' print? go version devel +f8b50ad4cac4 Mon Apr 21 17:00:27 2014 -0700 + linux/amd64 What steps reproduce the problem? If possible, include a link to a program on play.golang.org. 1. Use go/format's Source() to format a Go program containing a comment with embedded tabs, e.g. http://play.golang.org/p/4qP5vyn8or What happened? Source() did not modify the comment What should have happened instead? Source() should have modified the comment to use spaces instead of tabs Please provide any additional information below. go/format generally follows the rule that tabs are for indentation and spaces are for alignment. This ensures that source files will look correct for any possible tab width. However, go/format does not enforce this rule for comments. Since most editors will use a default tab width of 8 for .go files, this means that I will sometimes run into a program whose comments use tabs for alignment, with the assumption that every editor will use a tab width of 8. It's a judgment call, but I think the correct behavior is to apply text/tabwriter to comment nodes.
That's definitely a plausible answer. My counterargument is that Effective Go contains a large section on commentary , and godoc uses comments to generate documentation. Both of these suggest that the content of comments is not completely freeform, but rather is expected to conform to a certain style. For the same reason that go fmt enforces style in the other parts of Go programs, I believe that it's reasonable for go fmt to enforce style in comments.  http://golang.org/doc/effective_go.html#commentary