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: Report package name != base src directory #23184
Comments
We're not adding a flag. I'm pretty sure goimports already correctly handles this case, and we have tests for it too. Note that I suspect that goimports is unable to scan your $GOPATH so it's unable to learn that Fix your permission error and then let's see what happens. |
Couldn't figure out yet why there's a
Anyway, I worked around the
However, these lines don't seem enough that an IDE can (easily) act on to show the deletion reason at the former line Sidenote: The 3 lines above don't show up if you use the imported package correctly, e.g. like this:
Full output (from
|
Those lines are for people debugging goimports while developing goimports. They're not for users or IDEs. It looks like everything is happening properly: when you don't use the import it's removed, and when you do use it, it's not removed. You want to get warnings, but goimports isn't in the business of warnings. That is probably the job of a lint tool, as it's more of a style issue. I'm going to close this, as I see nothing for goimports to do. Let me know if I misunderstand, though. |
go version go1.9.2 darwin/amd64
golang.org/x/tools/cmd/goimports @ 64890f4
Using imported package
surprise
(in patha/packg
) aspackg
, notsurprise
.goimports
silently removes this import, so does Visual Studio Code (perhaps other IDEs as well).File
a/main.go
:and package file
a/packg/lib.go
:This silent removing confuses a lot (again a new colleague/Go newbie stumbled upon this). That's why
go build
explicitly shows the package name difference to the base of the import path since Go 1.2 (see #5957):What did you expect to see?
An error on
stderr
like this:and a flag
--no-rm-pkg-name-differ
(working title) to skip removing this import that IDEs can opt-in to show this error at this line instead.I think it should be a part of
goimports
because IDEs will first rungoimports
beforego build
to add maybe needed imports (neat feature 👍, btw) which will otherwise fail on build.Not using flags at all for
goimports
(see recent #23004 (comment)) and sticking to Go conventionwould mean that
goimports
should fail in this scenario (alsogo build
?!). This would makegoimports
backwards-incompatible and IDEs need to handle this. I think this is not the preferred way, so that's why I'm suggesting the flag and logging tostderr
instead.What did you see instead?
goimports -v main.go
output:The text was updated successfully, but these errors were encountered: