diff --git a/imports/fix.go b/imports/fix.go index a241c2976..c74bdd2c0 100644 --- a/imports/fix.go +++ b/imports/fix.go @@ -462,6 +462,9 @@ func shouldTraverse(dir string, fi os.FileInfo) bool { if !ts.IsDir() { return false } + if skipDir(ts) { + return false + } realParent, err := filepath.EvalSymlinks(dir) if err != nil { diff --git a/imports/fix_test.go b/imports/fix_test.go index f75a1d630..f984fd410 100644 --- a/imports/fix_test.go +++ b/imports/fix_test.go @@ -889,6 +889,40 @@ var ( t.Fatalf("results differ\nGOT:\n%s\nWANT:\n%s\n", got, output) } }) + + // Add a .goimportsignore and ensure it is respected. + if err := ioutil.WriteFile(newGoPath+"/src/.goimportsignore", []byte("x/mypkg\n"), 0666); err != nil { + t.Fatal(err) + } + + withEmptyGoPath(func() { + build.Default.GOPATH = newGoPath + + input := `package p + +var ( + _ = fmt.Print + _ = mypkg.Foo +) +` + output := `package p + +import "fmt" + +var ( + _ = fmt.Print + _ = mypkg.Foo +) +` + buf, err := Process(newGoPath+"/src/myotherpkg/toformat.go", []byte(input), &Options{}) + if err != nil { + t.Fatal(err) + } + if got := string(buf); got != output { + t.Fatalf("ignored results differ\nGOT:\n%s\nWANT:\n%s\n", got, output) + } + }) + } // Test for correctly identifying the name of a vendored package when it