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/imports: packages with non-standard names deleted unless imported with explicit name #9882

Closed
taruti opened this issue Feb 15, 2015 · 4 comments

Comments

@taruti
Copy link
Contributor

taruti commented Feb 15, 2015

Go imports deletes the termbox import in the following code:

package main

import "fmt"
import "github.com/nsf/termbox-go"

func main() {
    fmt.Println(termbox.Size())
}

A named import however works:

import termbox "github.com/nsf/termbox-go"

works fine.

If such package naming should be banned (could be a good idea) go vet could warn about them.

@minux
Copy link
Member

minux commented Feb 15, 2015

If you have installed termbox-go package in your GOPATH, then goimports
should be able to handle this correctly.

If that package is not installed, how could goimports know its real package
name?

@mikioh mikioh changed the title tools/imports: packages with non-standard names deleted unless imported with explicit name imports: packages with non-standard names deleted unless imported with explicit name Feb 15, 2015
@taruti
Copy link
Contributor Author

taruti commented Feb 15, 2015

Thus a workflow like:

  1. git checkout a repo
  2. use an editor with goimports to edit a source file (e.g. go-mode + hook)
  3. save a source file
  4. the imported package with non-standard name is not in $GOPATH and thus imports deletes the reference to it
  5. the source code is broken

Should go-imports delete imports for which the corresponding package is not fetched and thus the package name is not known?

@minux
Copy link
Member

minux commented Feb 15, 2015 via email

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title imports: packages with non-standard names deleted unless imported with explicit name x/tools/imports: packages with non-standard names deleted unless imported with explicit name Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-tools label Apr 14, 2015
@ALTree
Copy link
Member

ALTree commented Aug 10, 2017

This is a dup of #21143 and the reason goimports deletes the import is that goimports does not work well with imports containing - in a repository. The usecase is not supported and the fix is to use a named import.

@ALTree ALTree closed this as completed Aug 10, 2017
@golang golang locked and limited conversation to collaborators Aug 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants