Skip to content

x/tools/cmd/goimports: treat import paths as standard library only if they are in goroot #12419

@kr

Description

@kr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions