Skip to content

Commit

Permalink
Fix unexpected format when files do not end with newline
Browse files Browse the repository at this point in the history
  • Loading branch information
Junya committed Jun 8, 2023
1 parent 918a16d commit 44bb74f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions editor/filter_vertical_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func trimTrailingDuplicatedNewLine(tokens hclwrite.Tokens) hclwrite.Tokens {
if tokens[end-1].Type == hclsyntax.TokenEOF {
// skip EOF
eof = tokens[end-1]
if tokens[end-2].Type != hclsyntax.TokenNewline {
break
}
continue
}
if tokens[end-1].Type == hclsyntax.TokenNewline &&
Expand Down
6 changes: 6 additions & 0 deletions editor/filter_vertical_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ b1 {
b2 l1 {}
`,
},
{
name: "non-POSIX style end of file",
src: `a0 = v0`,
ok: true,
want: `a0 = v0`,
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 44bb74f

Please sign in to comment.