Skip to content

Commit

Permalink
Merge pull request #53 from srikrsna/consistently-sort-tags
Browse files Browse the repository at this point in the history
sort tags in consistent order
  • Loading branch information
ucpr authored Aug 10, 2024
2 parents 1b215e0 + 477e210 commit dbf6758
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 2 additions & 0 deletions module/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package module
import (
"go/ast"
"go/token"
"sort"
"strings"

"github.com/fatih/structtag"
Expand Down Expand Up @@ -95,6 +96,7 @@ func (v retag) Visit(n ast.Node) ast.Visitor {
return nil
}

sort.Stable(newTags) // sort tags according to keys
for _, t := range newTags.Tags() {
oldTags.Set(t)
}
Expand Down
2 changes: 1 addition & 1 deletion module/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestRetag(t *testing.T) {
module.Retag(n, map[string]map[string]*structtag.Tags{
"Simple": {
"Single": tagMust(structtag.Parse(`sql:"-,omitempty"`)),
"Multiple": tagMust(structtag.Parse(`xml:"-,omitempty"`)),
"Multiple": tagMust(structtag.Parse(`xml:"-,omitempty" sql:"ke,op" bson:"ke,op"`)),
"None": tagMust(structtag.Parse(`json:"none,omitempty"`)),
},
})
Expand Down
1 change: 0 additions & 1 deletion module/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func (mod) Name() string {
}

func (m mod) Execute(targets map[string]pgs.File, packages map[string]pgs.Package) []pgs.Artifact {

xtv := m.Parameters().Str("xxx")

xtv = strings.Replace(xtv, "+", ":", -1)
Expand Down
2 changes: 1 addition & 1 deletion module/test/golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package main

type Simple struct {
Single string `json:"key,option" sql:"-,omitempty"`
Multiple *string `json:"ke,op" xml:"-,omitempty"`
Multiple *string `json:"ke,op" xml:"-,omitempty" bson:"ke,op" sql:"ke,op"`
None int32 `json:"none,omitempty"`
}

0 comments on commit dbf6758

Please sign in to comment.