From a341a91279e7f333a70f745777e6e074d4c579ee Mon Sep 17 00:00:00 2001 From: Hau Nguyen Date: Mon, 28 Nov 2022 10:55:16 +0700 Subject: [PATCH] refactor: no need importNameAndPath --- internal/imports/formatter.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/internal/imports/formatter.go b/internal/imports/formatter.go index 513ec83..9d49d4e 100644 --- a/internal/imports/formatter.go +++ b/internal/imports/formatter.go @@ -354,12 +354,20 @@ func (ft *Formatter) formatImportSpecs( } for _, spec := range specs { - result = append(result, &ast.ImportSpec{ + newSpec := &ast.ImportSpec{ Path: &ast.BasicLit{ - Value: ft.importNameAndPath(spec), - Kind: token.IMPORT, + Value: spec.Path.Value, + Kind: token.STRING, }, - }) + } + + if spec.Name != nil { + newSpec.Name = &ast.Ident{ + Name: spec.Name.Name, + } + } + + result = append(result, newSpec) } } } @@ -431,15 +439,3 @@ func (ft *Formatter) moduleName(path string) (string, error) { return result, nil } - -func (ft *Formatter) importNameAndPath(importSpec *ast.ImportSpec) string { - if importSpec == nil { - return "" - } - - if importSpec.Name != nil { - return importSpec.Name.String() + " " + importSpec.Path.Value - } - - return importSpec.Path.Value -}