From f7c9dc36a3d60c90a8d2411f123913b37319dc11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20Mari=C3=A9?= Date: Fri, 25 Nov 2022 13:36:28 +0100 Subject: [PATCH] Format binary << operator ### Why was this change necessary? The << operator would not collapse in expressions like: ``` do_keyword << whitespace? << parameters.aka(:parameters).maybe << code.aka(:body) << end_keyword.maybe ``` ### How does it address the problem? We remove the condition for which << would not break ### Are there any side effects? I'm not sure, maybe this condition was here for a good reason but it wasn't covered by the tests. --- lib/syntax_tree/node.rb | 15 +++++---------- test/fixtures/binary.rb | 5 +++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index 53fb3905..ccfa6c22 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -2095,16 +2095,11 @@ def format(q) q.group { q.format(left) } q.text(" ") unless power - if operator == :<< - q.text("<< ") - q.format(right) - else - q.group do - q.text(operator.name) - q.indent do - power ? q.breakable_empty : q.breakable_space - q.format(right) - end + q.group do + q.text(operator.name) + q.indent do + power ? q.breakable_empty : q.breakable_space + q.format(right) end end end diff --git a/test/fixtures/binary.rb b/test/fixtures/binary.rb index f8833cdc..beb03f6f 100644 --- a/test/fixtures/binary.rb +++ b/test/fixtures/binary.rb @@ -5,6 +5,11 @@ % foo**bar % +foo << barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr << barrrrrrrrrrrrr << barrrrrrrrrrrrrrrrrr +- +foo << barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr << barrrrrrrrrrrrr << + barrrrrrrrrrrrrrrrrr +% foo * barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr - foo *