Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/gofmt: remove tabs from comments #7972

Closed
aleksc-google opened this issue May 12, 2014 · 6 comments
Closed

cmd/gofmt: remove tabs from comments #7972

aleksc-google opened this issue May 12, 2014 · 6 comments

Comments

@aleksc-google
Copy link

@aleksc-google aleksc-google commented May 12, 2014

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.
@minux
Copy link
Member

@minux minux commented May 12, 2014

Comment 1:

gofmt just doesn't modify the comments, and i think it's a good feature.
@aleksc-google
Copy link
Author

@aleksc-google aleksc-google commented May 12, 2014

Comment 2:

That's definitely a plausible answer. My counterargument is that Effective Go contains a
large section on commentary [1], 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.
[1] http://golang.org/doc/effective_go.html#commentary
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 12, 2014

Comment 3:

Pretty sure this is working-as-intended.  We don't encourage ASCII art in comments, but
we don't forbid it either.

Labels changed: added repo-main, release-none.

@aleksc-google
Copy link
Author

@aleksc-google aleksc-google commented May 12, 2014

Comment 4:

Fair enough. I'll just continue to manually replace tabs in comments with the
appropriate number of spaces. :)
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 12, 2014

Comment 5:

Status changed to WorkingAsIntended.

@griesemer
Copy link
Contributor

@griesemer griesemer commented May 12, 2014

Comment 6:

Yes, gofmt doesn't touch the "internals" of comments. It only tries to align them.
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.