Skip to content

Commit

Permalink
🐛 Fix bug when value is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jun 8, 2022
1 parent 70b4d97 commit 0b2f5a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion internal/node/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@ import (
func Template(conf config.Config, n ast.Node) error {
switch n := n.(type) {
case *ast.MappingValueNode:
if comment := GetCommentTmpl(conf.Prefix, n.Value); comment != "" {
// Comment after value
comment := GetCommentTmpl(conf.Prefix, n.Value)

// Edge case where comment is set on key
if comment == "" {
if comment = GetCommentTmpl(conf.Prefix, n.Key); comment != "" {
// Move comment from key to value
if err := n.Value.SetComment(n.Key.GetComment()); err != nil {
return err
}
if err := n.Key.SetComment(nil); err != nil {
return err
}
}
}

if comment != "" {
newNode, err := templateComment(conf, comment, n.Value)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions internal/visitor/template_comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func TestTemplateComments_Visit(t *testing.T) {
{"mapping invalid variable error", args{failConf, "test: a #yampl {{ .z }}"}, "", true},
{"sequence invalid variable error", args{failConf, "- a #yampl {{ .z }}"}, "", true},
{"strip", args{stripConf, "test: a #yampl b"}, "test: b", false},
{"no value", args{defaultConf, "test: #yampl a"}, "test: a #yampl a", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 0b2f5a9

Please sign in to comment.