diff --git a/imports/fix_test.go b/imports/fix_test.go index 6041f0a8..6fa0eff8 100644 --- a/imports/fix_test.go +++ b/imports/fix_test.go @@ -573,6 +573,49 @@ func main() { //var _ = bar.A var _ = qux.B } +`, + }, + + // Blank line can be added before all types of import declarations. + // golang.org/issue/7866 + { + name: "issue 7866", + in: `package main + +import ( + "fmt" + renamed_bar "github.com/foo/bar" + + . "github.com/foo/baz" + "io" + + _ "github.com/foo/qux" + "strings" +) + +func main() { + _, _, _, _, _ = fmt.Errorf, io.Copy, strings.Contains, renamed_bar.A, B +} +`, + out: `package main + +import ( + "fmt" + + renamed_bar "github.com/foo/bar" + + "io" + + . "github.com/foo/baz" + + "strings" + + _ "github.com/foo/qux" +) + +func main() { + _, _, _, _, _ = fmt.Errorf, io.Copy, strings.Contains, renamed_bar.A, B +} `, }, } diff --git a/imports/imports.go b/imports/imports.go index f42c3350..43830e10 100644 --- a/imports/imports.go +++ b/imports/imports.go @@ -238,7 +238,7 @@ func matchSpace(orig []byte, src []byte) []byte { return b.Bytes() } -var impLine = regexp.MustCompile(`^\s+(?:\w+\s+)?"(.+)"`) +var impLine = regexp.MustCompile(`^\s+(?:[\w\.]+\s+)?"(.+)"`) func addImportSpaces(r io.Reader, breaks []string) []byte { var out bytes.Buffer