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

x/tools/cmd/goimports: unnecessary PackageName in ImportSpec #18027

Closed
mdempsky opened this issue Nov 23, 2016 · 5 comments
Closed

x/tools/cmd/goimports: unnecessary PackageName in ImportSpec #18027

mdempsky opened this issue Nov 23, 2016 · 5 comments
Milestone

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Nov 23, 2016

$ printf 'package p\nvar _ = sheets.SpreadsheetsReadonlyScope\n' | goimports
package p

import sheets "google.golang.org/api/sheets/v4"

var _ = sheets.SpreadsheetsReadonlyScope

The package name is already sheets, so there's no need to explicitly name it.

/cc @bradfitz

@mdempsky mdempsky added this to the Unreleased milestone Nov 23, 2016
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 23, 2016

Intentional.

It's more explicit. And it makes future goimports runs faster, not having to scan the "v4" directory to figure out what it means.

@bradfitz bradfitz closed this Nov 23, 2016
@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented Nov 23, 2016

Seems inconsistent that it leaves import "google.golang.org/api/sheets/v4" alone.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 23, 2016

I don't follow. You didn't say anything about that in your bug report.

@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented Nov 23, 2016

$ printf 'package p\nimport "google.golang.org/api/sheets/v4"\nvar _ = sheets.SpreadsheetsReadonlyScope\n' | goimports
package p

import "google.golang.org/api/sheets/v4"

var _ = sheets.SpreadsheetsReadonlyScope
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 23, 2016

I still think it's fine. That is: don't mess with people's existing imports if they wrote them by hand or tweaked them by hand. But if we're adding them automatically, then we get to remind them of convention. (dir name == package name) If they don't follow convention, we help readers out. If they don't like it, they can delete it or follow convention.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.