Skip to content

Commit a3af07c

Browse files
committed
Don't alias imports if the alias would be ineffective
Fixes stuff like `context "context"` and `http "net/http"`. Signed-off-by: Brad Davidson <[email protected]>
1 parent 2b36238 commit a3af07c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

v2/generator/import_tracker.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ func NewImportTrackerForPackage(local string, typesToAdd ...*types.Type) *namer.
4747
tracker := namer.NewDefaultImportTracker(types.Name{Package: local})
4848
tracker.IsInvalidType = func(*types.Type) bool { return false }
4949
tracker.LocalName = func(name types.Name) string { return goTrackerLocalName(&tracker, local, name) }
50-
tracker.PrintImport = func(path, name string) string { return name + " \"" + path + "\"" }
50+
tracker.PrintImport = func(path, name string) string {
51+
dirs := strings.Split(path, namer.GoSeperator)
52+
if len(dirs) > 0 && name == dirs[len(dirs)-1] {
53+
return "\"" + path + "\""
54+
}
55+
return name + " \"" + path + "\""
56+
}
5157

5258
tracker.AddTypes(typesToAdd...)
5359
return &tracker

0 commit comments

Comments
 (0)