From 8464040d176b68308a9301e5565567009f6e8a2f Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 5 Oct 2026 14:17:01 +0200 Subject: [PATCH] Do not add a trailing newline to a file ending in inline HTML php-cs-fixer's SingleBlankLineAtEof skips a file whose last token is inline HTML, a close tag or an open tag, so a template ending in "" keeps no final newline. blink appended one unconditionally; now it leaves such endings alone. --- blink/internal/fixer/rules/rules_test.go | 8 ++++++++ blink/internal/fixer/rules/single_blank_line_at_eof.go | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/blink/internal/fixer/rules/rules_test.go b/blink/internal/fixer/rules/rules_test.go index 7fa2df6fe9..ed071534e3 100644 --- a/blink/internal/fixer/rules/rules_test.go +++ b/blink/internal/fixer/rules/rules_test.go @@ -381,4 +381,12 @@ func TestSingleBlankLineAtEndOfFile(t *testing.T) { if _, changed := apply(t, SingleBlankLineAtEndOfFile{}, "\n"); changed { + t.Fatal("inline-HTML ending must be left alone") + } + if _, changed := apply(t, SingleBlankLineAtEndOfFile{}, ""); changed { + t.Fatal("close-tag ending must be left alone") + } } diff --git a/blink/internal/fixer/rules/single_blank_line_at_eof.go b/blink/internal/fixer/rules/single_blank_line_at_eof.go index a48c0d5782..a7ba11a34e 100644 --- a/blink/internal/fixer/rules/single_blank_line_at_eof.go +++ b/blink/internal/fixer/rules/single_blank_line_at_eof.go @@ -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" {