Skip to content

Commit

Permalink
Move the vertical formatter to tfeditor package
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Feb 23, 2022
1 parent 2eb9b5a commit ac4b459
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion filter/awsv4upgrade/aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewAWSS3BucketFilter() editor.Filter {

// Remove redundant TokenNewLine tokens in the resource block after removing nested blocks.
// Since VerticalFormat clears tokens internally, we should call it at the end.
&verticalFormatterFilter{},
tfeditor.NewVerticalFormatterResourceFilter(),
}
return &AWSS3BucketFilter{filters: filters}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package awsv4upgrade
package tfeditor

import (
"github.com/minamijoyo/tfedit/tfeditor"
"github.com/minamijoyo/tfedit/tfwrite"
)

// verticalFormatterFilter is a Filter implementation to format HCL in vertical.
// VerticalFormatterFilter is a filter implementation to format HCL in vertical.
// At time of writing, the default hcl formatter does not support vertical
// formatting. However, it's useful in some cases such as removing a block
// because leading and trailing newline tokens don't belong to a block, so
// deleting a block leaves extra newline tokens.
type verticalFormatterFilter struct{}
type VerticalFormatterFilter struct{}

var _ tfeditor.ResourceFilter = (*verticalFormatterFilter)(nil)
var _ ResourceFilter = (*VerticalFormatterFilter)(nil)

// NewVerticalFormatterResourceFilter creates a new instance of VerticalFormatterFilter as ResourceFilter.
func NewVerticalFormatterResourceFilter() ResourceFilter {
return &VerticalFormatterFilter{}
}

// ResourceFilter reads HCL and writes formatted contents in vertical.
func (f *verticalFormatterFilter) ResourceFilter(inFile *tfwrite.File, resource *tfwrite.Resource) (*tfwrite.File, error) {
func (f *VerticalFormatterFilter) ResourceFilter(inFile *tfwrite.File, resource *tfwrite.Resource) (*tfwrite.File, error) {
resource.VerticalFormat()

return inFile, nil
Expand Down

0 comments on commit ac4b459

Please sign in to comment.