Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort tags in consistent order #53

Merged
merged 2 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only tags generated by protoc-gen-gotag are sorted in ascending order.

None int32 `json:"none,omitempty"`
}