func removeDuplicatedNewLine(tokens hclwrite.Tokens) hclwrite.Tokens {
	var removed hclwrite.Tokens
	beforeBefore := false
	before := false
	for _, token := range tokens {
		if token.Type != hclsyntax.TokenNewline {
			removed = append(removed, token)
			beforeBefore = false
			before = false
			continue
		}
		if before && beforeBefore {
			continue
		}
		removed = append(removed, token)
		beforeBefore = before
		before = true
	}
	return removed
}
removeDuplicatedNewLine removes duplicated newlines
Two consecutive blank lines should be removed.
In other words, if there are three consecutive TokenNewline tokens,
the third and subsequent TokenNewline tokens are removed.
package editor
import (
	"github.com/hashicorp/hcl/v2/hclsyntax"
	"github.com/hashicorp/hcl/v2/hclwrite"
)
type verticalFormatterFilter struct {
}
var _ Filter = (*verticalFormatterFilter)(nil)
func (f *verticalFormatterFilter) Filter(inFile *hclwrite.File) (*hclwrite.File, error) {
	tokens := inFile.BuildTokens(nil)
	vertical := verticalFormat(tokens)
	outFile := hclwrite.NewEmptyFile()
	outFile.Body().AppendUnstructuredTokens(vertical)
	return outFile, nil
}
func verticalFormat(tokens hclwrite.Tokens) hclwrite.Tokens {
	trimmed := trimLeadingNewLine(tokens)
	removed := removeDuplicatedNewLine(trimmed)
	return removed
}
func trimLeadingNewLine(tokens hclwrite.Tokens) hclwrite.Tokens {
	begin := 0
	for ; begin < len(tokens); begin++ {
		if tokens[begin].Type != hclsyntax.TokenNewline {
			break
		}
	}
	return tokens[begin:len(tokens)]
}