fix: force update ast decls when single import

main
sudo pacman -Syu 2022-11-27 00:23:28 +07:00
parent 30f79e9322
commit c0206fbef4
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
1 changed files with 4 additions and 11 deletions

View File

@ -66,7 +66,7 @@ func NewFormmater(opts ...FormatterOptionFn) (*Formatter, error) {
for _, stdPackage := range stdPackages {
ft.stdPackages[stdPackage.PkgPath] = struct{}{}
}
ft.log("NewFormmater: stdPackages: %+v\n", ft.stdPackages)
// ft.log("NewFormmater: stdPackages: %+v\n", ft.stdPackages)
ft.moduleNames = make(map[string]string)
ft.formattedPaths = make(map[string]struct{})
@ -193,9 +193,9 @@ func (ft *Formatter) formatImports(
ft.mustLogImportSpecs("formatImports: formattedImportSpecs: ", formattedImportSpecs)
// Combine multi import decl into one
isMultiImportDecl := false
isExistFirstImportDecl := false
decls := make([]ast.Decl, 0, len(astFile.Decls))
for _, decl := range astFile.Decls {
genDecl, ok := decl.(*ast.GenDecl)
if !ok {
@ -209,12 +209,6 @@ func (ft *Formatter) formatImports(
}
if isExistFirstImportDecl {
isMultiImportDecl = true
// TODO: explain this
storedGenDecl, ok := decls[len(decls)-1].(*ast.GenDecl)
if ok && storedGenDecl.Tok == token.IMPORT {
storedGenDecl.Rparen = genDecl.End()
}
continue
}
@ -224,9 +218,8 @@ func (ft *Formatter) formatImports(
decls = append(decls, genDecl)
}
if isMultiImportDecl {
// Update ast decls
astFile.Decls = decls
}
// Print formatted bytes from formatted ast
var formattedBytes []byte