From 29e4a56bfc842a0b2c59d0acf9a8f78337b5deb9 Mon Sep 17 00:00:00 2001 From: Alexey Yerin Date: Sat, 4 Jan 2025 17:15:14 +0300 Subject: [PATCH] Formatter: Remove trailing whitespace from comments Fixes #153 --- blueprintcompiler/formatter.py | 3 +++ tests/formatting/comment_in.blp | 4 +++- tests/formatting/comment_out.blp | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/blueprintcompiler/formatter.py b/blueprintcompiler/formatter.py index 60d87b4..f438675 100644 --- a/blueprintcompiler/formatter.py +++ b/blueprintcompiler/formatter.py @@ -193,6 +193,9 @@ def format(data, tab_size=2, insert_space=True): elif prev_line_type in require_extra_newline: newlines = 2 + current_line = "\n".join( + [line.rstrip() for line in current_line.split("\n")] + ) commit_current_line(LineType.COMMENT, newlines_before=newlines) else: # pragma: no cover diff --git a/tests/formatting/comment_in.blp b/tests/formatting/comment_in.blp index 32a907c..88b825a 100644 --- a/tests/formatting/comment_in.blp +++ b/tests/formatting/comment_in.blp @@ -1,2 +1,4 @@ using Gtk 4.0; -//comment \ No newline at end of file +//comment +// Trailing whitespace: +// diff --git a/tests/formatting/comment_out.blp b/tests/formatting/comment_out.blp index d5dca95..91e647a 100644 --- a/tests/formatting/comment_out.blp +++ b/tests/formatting/comment_out.blp @@ -1,2 +1,4 @@ using Gtk 4.0; // comment +// Trailing whitespace: +//