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: doesn't handle packages named "v1", etc #29041

Closed
mattmoor opened this issue Nov 30, 2018 · 10 comments
Closed

x/tools/cmd/goimports: doesn't handle packages named "v1", etc #29041

mattmoor opened this issue Nov 30, 2018 · 10 comments
Assignees
Milestone

Comments

@mattmoor
Copy link

@mattmoor mattmoor commented Nov 30, 2018

What version of Go are you using (go version)?

$ go version
go version go1.11 linux/amd64

I'm seeing a bad format with goimports at commit: 1c3d964

You can see the bad formatting turned into a PR here: knative/pkg#176

The comment run is what's in the PR description (minus the -s, it's WIP).

cc @bradfitz

@gopherbot gopherbot added this to the Unreleased milestone Nov 30, 2018
@mattmoor
Copy link
Author

@mattmoor mattmoor commented Nov 30, 2018

I see this with the head of release-branch.go1.11 as well.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 30, 2018

Don't name your packages v1, I guess?

@bradfitz bradfitz changed the title x/tools/goimports: strips necessary import x/tools/cmd/goimports: doesn't handle packages named "v1", etc Nov 30, 2018
@mattmoor
Copy link
Author

@mattmoor mattmoor commented Nov 30, 2018

Yeah this blows up on anything touching K8s :P

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 30, 2018

@bcmills
Copy link
Member

@bcmills bcmills commented Nov 30, 2018

See also #28435.

@bcmills
Copy link
Member

@bcmills bcmills commented Nov 30, 2018

Curious whether/how people think we should fix this.

If v1 is used as the Expr in a SelectorExpr, then goimports should not remove packages that end with the suffix v1. (It's fine if it doesn't add them, though: v1 is a terrible name for a package.)

We can compute the set of “names that might be package names” in an O(N) scan over the source file.

@bcmills
Copy link
Member

@bcmills bcmills commented Nov 30, 2018

As a workaround, what happens if you rename the package explicitly on import?

That is, change

import (
	"k8s.io/api/core/v1"
)

to

import (
	v1 "k8s.io/api/core/v1"
)

?

@heschik
Copy link
Contributor

@heschik heschik commented Nov 30, 2018

I haven't looked at this closely but I believe Bryan's suggestion will fix it, and my fix for #28428 will add the v1 automatically.

@heschik
Copy link
Contributor

@heschik heschik commented Nov 30, 2018

@heschik
Copy link
Contributor

@heschik heschik commented Dec 5, 2018

Confirmed that tip goimports now adds the v1 name to the import rather than deleting it.

@heschik heschik closed this Dec 5, 2018
negz added a commit to negz/crossplane that referenced this issue Mar 6, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
negz added a commit to negz/crossplane that referenced this issue Mar 6, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
negz added a commit to negz/crossplane that referenced this issue Mar 6, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
negz added a commit to negz/crossplane that referenced this issue Mar 6, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
negz added a commit to negz/crossplane that referenced this issue Mar 6, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
negz added a commit to negz/crossplane that referenced this issue Mar 6, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
jbw976 pushed a commit to jbw976/gcp-filter-test that referenced this issue Aug 19, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
jbw976 pushed a commit to jbw976/crossplane that referenced this issue Aug 20, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
jbw976 pushed a commit to jbw976/crossplane that referenced this issue Aug 20, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
jbw976 pushed a commit to jbw976/crossplane that referenced this issue Aug 20, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
hasheddan pushed a commit to hasheddan/crossplane-runtime-temp that referenced this issue Aug 20, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
raghavendra-talur added a commit to raghavendra-talur/heketi that referenced this issue Aug 23, 2019
There are 3 types of errors fixed:
a. one empty line is required before where third-party pkgs imports
b. packages can have dashes in import path but won't have in name[1],
explicitly name them on import.
c. packages that are just version numbers like "v1" need explicit naming
too[2].

[1] golang/go#17546
[2] golang/go#29041

Signed-off-by: Raghavendra Talur <rtalur@redhat.com>
phlogistonjohn added a commit to heketi/heketi that referenced this issue Aug 23, 2019
There are 3 types of errors fixed:
a. one empty line is required before where third-party pkgs imports
b. packages can have dashes in import path but won't have in name[1],
explicitly name them on import.
c. packages that are just version numbers like "v1" need explicit naming
too[2].

[1] golang/go#17546
[2] golang/go#29041

Signed-off-by: Raghavendra Talur <rtalur@redhat.com>
jbw976 pushed a commit to crossplane/provider-azure that referenced this issue Aug 30, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
jbw976 pushed a commit to crossplane/provider-aws that referenced this issue Sep 1, 2019
golang/go#29041

This is a slightly counterintuitive workaround for the above bug. The
alternative to this commit would be to disable goimports linting until the bug
is fixed. I think it's worth the workaround for the time being in exchange for
the value goimports linting brings.

Signed-off-by: Nic Cope <negz@rk0n.org>
@golang golang locked and limited conversation to collaborators Dec 5, 2019
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
5 participants
You can’t perform that action at this time.