Skip to content

Commit

Permalink
Add new imports to the resolver files in stable order
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed Jan 24, 2024
1 parent 3674eb5 commit bc7c179
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go/token"
"os"
"path/filepath"
"slices"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -305,10 +306,16 @@ func transformResolverFile(fset *token.FileSet, node *ast.File, filePath, apiGro
}
gd.Specs = newSpecs

for path, name := range importMap {
newImportKeys := make([]string, 0, len(importMap))
for k := range importMap {
newImportKeys = append(newImportKeys, k)
}
slices.Sort(newImportKeys)

for _, path := range newImportKeys {
gd.Specs = append(gd.Specs, &ast.ImportSpec{
Name: &ast.Ident{
Name: name,
Name: importMap[path],
},
Path: &ast.BasicLit{
Kind: token.STRING,
Expand Down

0 comments on commit bc7c179

Please sign in to comment.