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

Anonymous imports get pushed into a separate import declaration #358

Open
reillywatson opened this issue May 10, 2022 · 0 comments · May be fixed by #359
Open

Anonymous imports get pushed into a separate import declaration #358

reillywatson opened this issue May 10, 2022 · 0 comments · May be fixed by #359

Comments

@reillywatson
Copy link

reillywatson commented May 10, 2022

Describe the bug

If I have an anonymous import in a package that uses Wire, that import gets copied to wire_gen.go, but it gets copied in some separate import declaration instead of being part of the rest of the imports.

To Reproduce

The PkgImport test has an example of this behavior:

import (
	"example.com/bar"
)

import (
	_ "example.com/anon1"
	_ "example.com/anon2"
)

This is legal, but not really idiomatic. In particular goimports doesn't care for it, and it doesn't match any other Go code I've seen in the wild.

Expected behavior

Imports being all part of the same import declaration, like most Go code:

import (
	_ "example.com/anon1"
	_ "example.com/anon2"
	"example.com/bar"
)

Version

0.5.0

Additional context

This is causing issues with the goimports check in our CI.

reillywatson added a commit to reillywatson/wire that referenced this issue May 10, 2022
Anonymous imports were being special-cased and written out separately. They're not that special though, we can just count them as regular imports with the name "_".

This causes them to get grouped together with the other imports like one would expect, and simplifies the generator a bit.

Fixes google#358.
@reillywatson reillywatson linked a pull request May 10, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant