Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions blink/internal/fixer/rules/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,12 @@ func TestSingleBlankLineAtEndOfFile(t *testing.T) {
if _, changed := apply(t, SingleBlankLineAtEndOfFile{}, "<?php echo 1;\n"); changed {
t.Fatal("single newline should not change")
}
// a file ending in inline HTML gets no trailing newline added (php-cs-fixer
// skips T_INLINE_HTML / T_CLOSE_TAG endings)
if _, changed := apply(t, SingleBlankLineAtEndOfFile{}, "<?php echo 1; ?>\n</html>"); changed {
t.Fatal("inline-HTML ending must be left alone")
}
if _, changed := apply(t, SingleBlankLineAtEndOfFile{}, "<?php echo 1; ?>"); changed {
t.Fatal("close-tag ending must be left alone")
}
}
5 changes: 5 additions & 0 deletions blink/internal/fixer/rules/single_blank_line_at_eof.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func (SingleBlankLineAtEndOfFile) Fix(s *tokens.Stream) bool {
}
last := s.Len() - 1
t := s.At(last)
// a file ending in inline HTML or a tag is left alone (php-cs-fixer skips
// T_INLINE_HTML / T_CLOSE_TAG / T_OPEN_TAG), so a template keeps its ending
if t.Kind == token.InlineHTML || t.Kind == token.CloseTag || t.Kind == token.OpenTag {
return false
}
if t.Kind == token.Whitespace {
// the final whitespace token is entirely trailing; collapse to one \n
if t.Value != "\n" {
Expand Down
Loading