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: on every run, gofmt will add an extra level of indent to comment #9751

Closed
dmitshur opened this issue Feb 2, 2015 · 1 comment
Closed

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Feb 2, 2015

(This new issue extracts a sub-issue that was originally mentioned in #5128 (comment). After investigating the cause, I've realized this issue is different and smaller in scope than the original issue #5128, that's why I'm making this new issue.)

An instance of gofmt not being idempotent. Repeatedly invoking gofmt will add a level of indent to the b string line each time:

http://play.golang.org/p/Pwn4cOHtMN

I've identified the root cause in go/printer package (therefore the bug affects cmd/gofmt, go/format and go/printer packages). It's due to an unhandled edge case in stripCommonPrefix func.

It happens when a comment block consists of a first line with /*, 1 or more blank lines, last line with */. The internal prefix variable ends up never being set to a correct value before being used (it's not set at all, so it always has zero value, the empty string). See #5128 (comment) for more details.

I already have a fix and test cases done locally, I will submit a CL that closes this issue shortly.

@dmitshur
Copy link
Contributor Author

dmitshur commented Feb 2, 2015

CL is ready for review at https://go-review.googlesource.com/3684.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants