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: treat import paths as standard library only if they are in goroot #12419

Open
kr opened this issue Aug 31, 2015 · 3 comments
Open
Labels
Milestone

Comments

@kr
Copy link
Contributor

@kr kr commented Aug 31, 2015

The go tool sets a field to indicate whether a package is part of the standard library:

https://github.com/golang/go/blob/8d478e845c/src/cmd/go/pkg.go#L156

p.Standard = p.Goroot && p.ImportPath != "" && !strings.Contains(p.ImportPath, ".")

goimports uses a different rule:

https://github.com/golang/tools/blob/e21b7325f7/imports/fix.go#L32

if strings.Contains(importPath, ".") {

My feature request is to change the code to behave similar to the go tool:

if strings.Contains(importPath, ".") || !inGoroot(importPath) {

With an additional index of the standard library keyed by import path, I'd expect this to be reasonably fast.

If this is an acceptable idea, I'm happy to write a patch.

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Aug 31, 2015
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 31, 2015

@sheki
Copy link

@sheki sheki commented Jun 11, 2016

I looked at fixing this, but I would cause behavior changes

import (
"fmt"
"x/mypkg"
)

The first group would be standard libraries
The second group everything else

This would now lead to

import (
"fmt"

"x/mypkg"
)
@sheki
Copy link

@sheki sheki commented Jun 11, 2016

Is that acceptable ?

This bites us too as we have an import called "bright" and it gets merged in with the standard library imports which is a minor nuisance.

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

Successfully merging a pull request may close this issue.

None yet
4 participants