From c22b957a750998243ba585f0b3b359cd4810cdcb Mon Sep 17 00:00:00 2001 From: Levi Buzolic Date: Fri, 2 Aug 2024 17:26:08 +1000 Subject: [PATCH 1/2] Add failing test for long call chain comment formatting issue --- test/fixtures/call.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/fixtures/call.rb b/test/fixtures/call.rb index eec717f0..04c855da 100644 --- a/test/fixtures/call.rb +++ b/test/fixtures/call.rb @@ -40,6 +40,15 @@ qux .quux % +result = + fooooooooooooooooo + .barrrrrrrrrrrrrrrrrrr + .bazzzzzzzzzzzzzzzzzzz + # long comment long comment long comment long comment long comment + # long comment long comment long comment long comment long comment + # long comment long comment long comment long comment long comment + .quxxxxxxxxxxxxxxxxxxx +% { a: 1, b: 2 }.fooooooooooooooooo.barrrrrrrrrrrrrrrrrrr.bazzzzzzzzzzzz.quxxxxxxxxxxxx - { a: 1, b: 2 }.fooooooooooooooooo From e8e387f95885d2d0df45c7ba75788c01bbe73dbb Mon Sep 17 00:00:00 2001 From: Levi Buzolic Date: Fri, 2 Aug 2024 17:26:47 +1000 Subject: [PATCH 2/2] Restructure conditional to eliminate duplicate check on last_child.operator --- lib/syntax_tree/node.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index 3b676552..314fdbcc 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -2849,9 +2849,10 @@ def format_chain(q, children) # to print the operator trailing in order to keep it working. last_child = children.last if last_child.is_a?(CallNode) && last_child.message != :call && + last_child.operator && ( - (last_child.message.comments.any? && last_child.operator) || - (last_child.operator && last_child.operator.comments.any?) + last_child.message.comments.any? || + last_child.operator.comments.any? ) q.format(CallOperatorFormatter.new(last_child.operator)) skip_operator = true