Skip to content

Commit

Permalink
Merge branch 'main' into lint-fix-1216
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso authored Dec 15, 2023
2 parents 218c8f1 + 9845bb3 commit aee4588
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/compile.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package compiler

import (
"cmp"
"fmt"
"go/ast"
"go/build/constraint"
Expand Down Expand Up @@ -402,6 +403,12 @@ func addImports(p *packages.Package, gen *ast.File) *ast.File {
})
}

// Imports don't require to be sorted but it helps with output
// stability. The format pass does not take care of this.
slices.SortFunc(importspecs, func(a, b ast.Spec) int {
return cmp.Compare(a.(*ast.ImportSpec).Name.Name, b.(*ast.ImportSpec).Name.Name)
})

gen.Decls = append([]ast.Decl{&ast.GenDecl{
Tok: token.IMPORT,
Specs: importspecs,
Expand Down

0 comments on commit aee4588

Please sign in to comment.