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

go/format: repeated import remains if there is a blank line between them #10025

Closed
marcotmarcot opened this issue Feb 27, 2015 · 2 comments
Closed

Comments

@marcotmarcot
Copy link

For instance, goimports transforms [1] into [2], but keep [3] as it is.

1:

package main

import (
       "fmt"
       "fmt"
)

func main() {
     fmt.Print("Hello world!")
}

2:

package main

import (
       "fmt"
}

func main() {
     fmt.Print("Hello world!")
}

3:

package main

import (
       "fmt"

       "fmt"
}

func main() {
     fmt.Print("Hello world!")
}
@josharian josharian changed the title goimports keeps repeated import if there is a blank line between them go/format: repeated import remains if there is a blank line between them Feb 27, 2015
@josharian
Copy link
Contributor

Thanks for the report. I think that this is working as intended. Within a run of non-space-separated imports, go/format and goimports both sort and deduplicate. They do no sorting (and consequently no deduplication) across groups or blank lines. This leaves some amount of control to decide how to organize your imports. This is particularly important with magic imports such as used by cgo. If we were to rearrange all imports at will, that would prevent third parties from implementing a tool such as cgo, which would be a pity.

@marcotmarcot
Copy link
Author

Thanks for the comment.

@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

3 participants