diff --git a/hclwrite/ast.go b/hclwrite/ast.go index 8bf7331..7620b83 100644 --- a/hclwrite/ast.go +++ b/hclwrite/ast.go @@ -19,8 +19,12 @@ func (f *File) Body() *Body { } // WriteTo writes the tokens underlying the receiving file to the given writer. +// +// The tokens first have a simple formatting pass applied that adjusts only +// the spaces between them. func (f *File) WriteTo(wr io.Writer) (int, error) { tokens := f.inTree.children.BuildTokens(nil) + format(tokens) return tokens.WriteTo(wr) } diff --git a/hclwrite/ast_body.go b/hclwrite/ast_body.go index b0c257c..d0d79fd 100644 --- a/hclwrite/ast_body.go +++ b/hclwrite/ast_body.go @@ -10,10 +10,6 @@ type Body struct { inTree items nodeSet - - // indentLevel is the number of spaces that should appear at the start - // of lines added within this body. - indentLevel int } func (b *Body) appendItem(c nodeContent) *node { diff --git a/hclwrite/parser.go b/hclwrite/parser.go index 75afe2c..d83d3e5 100644 --- a/hclwrite/parser.go +++ b/hclwrite/parser.go @@ -185,9 +185,7 @@ func parseBody(nativeBody *hclsyntax.Body, from inputTokens) (inputTokens, *node body := &Body{ inTree: newInTree(), - - indentLevel: 0, // TODO: deal with this - items: newNodeSet(), + items: newNodeSet(), } remain := within diff --git a/hclwrite/public.go b/hclwrite/public.go index b4d7f15..4d5ce2a 100644 --- a/hclwrite/public.go +++ b/hclwrite/public.go @@ -10,8 +10,8 @@ import ( // added t it. func NewFile() *File { body := &Body{ - inTree: newInTree(), - indentLevel: 0, + inTree: newInTree(), + items: newNodeSet(), } file := &File{ inTree: newInTree(),