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 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