1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:54:43 -07:00
go/go
haya14busa 84a35ef54d go/ast/astutil: new third-party imports shouldn't go in the std group
Before this change, astutil would only do a prefix match of a new import
with all the existing ones, to try to place it in the correct group. If
none was found, the new import would be placed at the beginning of the
first import group.

This works well for new std imports, but it doesn't work well for new
third-party packages that don't share any prefix with any of the
existing imports.

Example:

	import (
		"time"

		"github.com/golang/snappy"
	)

When adding "golang.org/x/sys/unix" with astutil.AddImport, the import
is inserted as follows:

	import (
		"golang.org/x/sys/unix"
		"time"

		"github.com/golang/snappy"
	)

And goimports reorganizes the imports to separate std and third-party
packages:

	import (
		"time"

		"golang.org/x/sys/unix"

		"github.com/golang/snappy"
	)

We usually don't want to introduce a new import group; in most cases,
the desired behavior is separating std from third-party packages.

With this CL, new imports that don't share prefix with any existing ones
will be placed with the first group of third-party imports, if any
exist. If no third-party import group exists, a new one will be added.
In the case of our example above, this will be the new outcome:

	import (
		"time"

		"github.com/golang/snappy"
		"golang.org/x/sys/unix"
	)

Fixes golang/go#19190.

Change-Id: Id4630015c029bd815234a6c8726cb97f4af16f1c
Reviewed-on: https://go-review.googlesource.com/37552
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2017-08-15 00:39:00 +00:00
..
ast/astutil go/ast/astutil: new third-party imports shouldn't go in the std group 2017-08-15 00:39:00 +00:00
buildutil x/tools/go/buildutil: remove unused function 2017-03-01 14:53:57 +00:00
callgraph tools: updates for minimum Go version 1.6 2017-02-07 21:06:19 +00:00
gccgoexportdata go/gccgoexportdata: correctly handle archive files containing string tables 2016-11-09 21:28:38 +00:00
gcexportdata go/gcexportdata: fix test again (fix older builds) 2017-06-08 21:12:18 +00:00
gcimporter15 go/gcimporter: update to latest copy from master 2017-04-25 22:48:49 +00:00
internal/gccgoimporter x/tools/go/internal/gccgoimporter: remove unused method 2017-03-01 14:54:10 +00:00
loader go/loader: Fix thinko in FindPackage hook signature 2017-07-05 16:38:48 +00:00
pointer go/pointer: implement extended queries 2017-03-06 04:11:41 +00:00
ssa go/ssa: remove statement with no effect 2017-06-15 21:28:45 +00:00
types/typeutil tools: updates for minimum Go version 1.6 2017-02-07 21:06:19 +00:00
vcs go/vcs: allow go get on github.com/ import paths with Unicode letters 2017-04-28 05:47:26 +00:00