mirror of
https://github.com/golang/go
synced 2024-11-18 16:04:44 -07:00
84a35ef54d
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> |
||
---|---|---|
.. | ||
fastwalk_dirent_fileno.go | ||
fastwalk_dirent_ino.go | ||
fastwalk_portable.go | ||
fastwalk_test.go | ||
fastwalk_unix.go | ||
fastwalk.go | ||
fix_test.go | ||
fix.go | ||
imports.go | ||
mkindex.go | ||
mkstdlib.go | ||
sortimports.go | ||
zstdlib.go |