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

goimports will not automatically delete duplicate imports at certain case #30832

Closed
andyafter opened this issue Mar 14, 2019 · 2 comments
Closed

Comments

@andyafter
Copy link

Hey there I am working on go language version 1.12 darwin/amd64. I have saved my go import as the following:

import (
    "context"
    
    "some/package/aaa"

    "another/package"
    "some/package/aaa"
)

And in this case, only in this case, goimports will not be deleting duplicate imports automatically. I tried with terminal command, emacs and vscode.

@agnivade
Copy link
Contributor

Please see @rsc's comment here #26846 (comment).

We intentionally leave this to local custom - gofmt and goimports will never move imports across blank lines in the import block. So if I want path with the others, I can do that, and gofmt/goimports respect that. And if you want all your renamed imports together, you can do that, and gofmt/goimports respect that too.

i.e. imports separated by blank lines are considered separate and that is intentional. Hence gofmt/goimports will not dedup entries beyond a single import group.

@andyafter
Copy link
Author

Damn it I thought I finally got something

@golang golang locked and limited conversation to collaborators Mar 13, 2020
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