@@ -84,6 +84,21 @@ func fixImports(fset *token.FileSet, f *ast.File) (added []string, err error) {
84
84
})
85
85
ast .Walk (visitor , f )
86
86
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
+
87
102
// Search for imports matching potential package references.
88
103
searches := 0
89
104
type result struct {
@@ -121,21 +136,6 @@ func fixImports(fset *token.FileSet, f *ast.File) (added []string, err error) {
121
136
}
122
137
}
123
138
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
-
139
139
return added , nil
140
140
}
141
141
0 commit comments