Skip to content

Commit 07a8450

Browse files
authored
[hcledit/create] fix broken test (#103)
1 parent 27437ce commit 07a8450

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal/handler/block.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package handler
22

33
import (
4-
"strings"
54
"fmt"
5+
"strings"
66

77
"github.com/hashicorp/hcl/v2/hclwrite"
88

@@ -26,7 +26,14 @@ func newBlockHandler(labels []string, comment string) (Handler, error) {
2626
}
2727

2828
func (h *blockHandler) HandleBody(body *hclwrite.Body, name string, _ []string) error {
29-
body.AppendUnstructuredTokens(beforeTokens(fmt.Sprintf("// %s", strings.TrimSpace(strings.TrimPrefix(h.comment, "//"))), false))
29+
if h.comment != "" {
30+
body.AppendUnstructuredTokens(
31+
beforeTokens(
32+
fmt.Sprintf("// %s", strings.TrimSpace(strings.TrimPrefix(h.comment, "//"))),
33+
false,
34+
),
35+
)
36+
}
3037

3138
body.AppendNewBlock(name, h.labels)
3239
return nil

0 commit comments

Comments
 (0)