File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ impl Formatter {
137137 self . add_newlines_after_extends_statement ( )
138138 . fix_dangling_semicolons ( )
139139 . fix_dangling_commas ( )
140+ . fix_trailing_spaces ( )
140141 . remove_trailing_commas_from_preload ( )
141142 . postprocess_tree_sitter ( )
142143 }
@@ -223,6 +224,17 @@ impl Formatter {
223224 self
224225 }
225226
227+ /// This function removes trailing spaces at the end of lines.
228+ #[ inline( always) ]
229+ fn fix_trailing_spaces ( & mut self ) -> & mut Self {
230+ let re = RegexBuilder :: new ( r"[ \t]+$" )
231+ . multi_line ( true )
232+ . build ( )
233+ . expect ( "trailing spaces regex should compile" ) ;
234+ self . regex_replace_all_outside_strings ( re, "" ) ;
235+ self
236+ }
237+
226238 /// This function removes trailing commas from preload function calls.
227239 /// The GDScript parser doesn't support trailing commas in preload calls,
228240 /// but our formatter might add them for multi-line calls.
Original file line number Diff line number Diff line change 1+ ## This function is the best in the world.
2+ ##
3+ ## There are no mistakes in it.
4+ func best_function () -> String :
5+ var new_string : String = """
6+ This is a multi-line string with trailing spaces.
7+ """
8+
9+ return new_string
10+
11+ # EOF
Original file line number Diff line number Diff line change 1+ ## This function is the best in the world.
2+ ##
3+ ## There are no mistakes in it.
4+ func best_function () -> String :
5+ var new_string : String = """
6+ This is a multi-line string with trailing spaces.
7+ """
8+
9+ return new_string
10+
11+ # EOF
You can’t perform that action at this time.
0 commit comments