From 374ecaeed1580a4df646341b27b75b4d27e9b711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Alet?= Date: Wed, 6 Jul 2022 14:57:57 +1100 Subject: [PATCH] Remove unnecessary blank line when last line had no EOL marker and contained only trailing spaces. --- yamlfixer/problemfixer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/yamlfixer/problemfixer.py b/yamlfixer/problemfixer.py index 62ffc2c..7c96b6d 100755 --- a/yamlfixer/problemfixer.py +++ b/yamlfixer/problemfixer.py @@ -113,7 +113,12 @@ def fix_newlineateof(self, left, right): # pylint: disable=unused-argument,no-s - no new line character at the end of file - wrong new line character: expected \n """ # noqa: D205, D208, D400 - # We simply ignore it, because we always add \n when dumping + if not (left or right): + # We came here because last line contained only trailing spaces + del self.ffixer.lines[self.linenum] + self.ffixer.loffset -= 1 + + # Else we simply ignore it, because we always add \n when dumping # and rely on universal newlines to handle them correctly. # FIXME : doesn't work when transcoding files for another OS.