Skip to content

Commit 0b05872

Browse files
committed
Update to latest version of goimports code.
Apply fix of golang/tools@4f50f44.
1 parent 540b43e commit 0b05872

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

playground/imports/fix.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ func fixImports(fset *token.FileSet, f *ast.File) (added []string, err error) {
8484
})
8585
ast.Walk(visitor, f)
8686

87+
// Nil out any unused ImportSpecs, to be removed in following passes
88+
unusedImport := map[string]bool{}
89+
for pkg, is := range decls {
90+
if refs[pkg] == nil && pkg != "_" && pkg != "." {
91+
unusedImport[strings.Trim(is.Path.Value, `"`)] = true
92+
}
93+
}
94+
for ipath := range unusedImport {
95+
if ipath == "C" {
96+
// Don't remove cgo stuff.
97+
continue
98+
}
99+
astutil.DeleteImport(fset, f, ipath)
100+
}
101+
87102
// Search for imports matching potential package references.
88103
searches := 0
89104
type result struct {
@@ -121,21 +136,6 @@ func fixImports(fset *token.FileSet, f *ast.File) (added []string, err error) {
121136
}
122137
}
123138

124-
// Nil out any unused ImportSpecs, to be removed in following passes
125-
unusedImport := map[string]bool{}
126-
for pkg, is := range decls {
127-
if refs[pkg] == nil && pkg != "_" && pkg != "." {
128-
unusedImport[strings.Trim(is.Path.Value, `"`)] = true
129-
}
130-
}
131-
for ipath := range unusedImport {
132-
if ipath == "C" {
133-
// Don't remove cgo stuff.
134-
continue
135-
}
136-
astutil.DeleteImport(fset, f, ipath)
137-
}
138-
139139
return added, nil
140140
}
141141

0 commit comments

Comments
 (0)