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
x/tools/cmd/goimports: package clause insertion mangles comments #12097
Comments
The package main insertion is intentional. It was requested and done as a feature at Gophercon 1's hack day. The comment mangling of course is not. |
Edit: Moved out into #15432 (comment). |
Hard to say whether it is the same issue without looking into the fix. Good to have multiple test cases regardless. |
Ok, I'll delete the comment and move this into a separate issue then. In case the same fix resolves both issues, great, otherwise they can be looked at separately. |
Is anybody working on this issue yet? I'm looking for something to contribute and it seems like a good one to start. What's the expected output of the given example? |
I think the expected output would be: package main
import "fmt"
// a
// b
// c
func main() {
fmt.Println()
} (Unless that conflicts with some existing behaviors.) |
Welcome! I don't think anyone is working on it. I guess I'd expect the package and imports to be inserted at the beginning of the file, with a blank line between the imports and the first comment. But it's not obvious, so if there's a good reason to do otherwise, I'm open to it. Messing with the AST and comment positioning can be quite fiddly, so I recommend writing all your test cases first. Feel free to ask for help if needed. Note that the likely reviewers for this (Brad, Robert, me) are all going to be slow, for our own reasons. |
Great! I'll start working on this issue then. There is a better channel to talk to you if I need help or should I just write it on this thread? I promise I won't bug you without exhausting all my options first :) |
This is a good place to discuss |
Change https://golang.org/cl/93235 mentions this issue: |
Input:
gofmt fails appropriately:
goimports inserts a package clause and mangles the comments:
The text was updated successfully, but these errors were encountered: