You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deiz opened this issue
Apr 5, 2021
· 2 comments
· May be fixed by golang/tools#299
Labels
NeedsFixThe path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.
package main
import (
"errors""github.com/pkg/errors""github.com/juju/errors"
)
funcmain() {
}
This file has three imported errors packages, none of them are referenced outside of the import block, so they should all be removed, resulting in this output:
package main
funcmain() {
}
What did you see instead?
Only one errors package is removed per iteration - seemingly always the last one to appear. Because we have three imported packages, we need to run imports.Process three times to prune all the unused imports.
Iteration 1:
package main
import (
"errors""github.com/pkg/errors"
)
funcmain() {
}
Iteration 2:
package main
import (
"errors"
)
funcmain() {
}
Iteration 3:
package main
funcmain() {
}
The text was updated successfully, but these errors were encountered:
gopherbot
added
the
Tools
This label describes issues relating to any tools in the x/tools repository.
label
Apr 5, 2021
Track imports per identifier as a slice to accommodate duplicates. This
allows us to generate multiple import fixes per import identifier.
Fixesgolang/go#45398
I just hit this issue and came up with the same fix independently.
@heschi I know there's an open question on what happens for used identifiers but would be great if we could fix this case and look at that one later as currently goimports and all tools which use the x/tools/imports package is unstable due to this issue.
dmitshur
changed the title
x/tools/imports: imports.Process does not remove all unused imports sharing a package name
x/tools/imports: Process does not remove all unused imports sharing a package name
Oct 1, 2022
dmitshur
added
NeedsFix
The path to resolution is known, but the work has not been done.
and removed
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
labels
Nov 29, 2023
NeedsFixThe path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
See https://play.golang.org/p/yv78HSm0AX6 for a full example, and https://play.golang.org/p/GmUF-tayOgI for an interactive example (hit "Format" with imports enabled).
What did you expect to see?
This file has three imported
errors
packages, none of them are referenced outside of the import block, so they should all be removed, resulting in this output:What did you see instead?
Only one
errors
package is removed per iteration - seemingly always the last one to appear. Because we have three imported packages, we need to runimports.Process
three times to prune all the unused imports.Iteration 1:
Iteration 2:
Iteration 3:
The text was updated successfully, but these errors were encountered: