Skip to content

Commit

Permalink
[Fix rubocop#12261] Fix an infinite loop for `Layout/MultilineMethodC…
Browse files Browse the repository at this point in the history
…allIndentation`

Fix: rubocop#12261
  • Loading branch information
ydah committed Oct 12, 2023
1 parent 42898bc commit 7edb5ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12261](https://github.com/rubocop/rubocop/issues/12261): Fix an infinite loop for `Layout/MultilineMethodCallIndentation` when multiline method chain with a block argument and method chain. ([@ydah][])
6 changes: 5 additions & 1 deletion lib/rubocop/cop/layout/multiline_method_call_indentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ def find_multiline_block_chain_node(node)
return unless (block_node = node.each_descendant(:block, :numblock).first)
return unless block_node.multiline? && block_node.parent.call_type?

block_node.parent
if node.receiver.call_type?
node.receiver
else
block_node.parent
end
end

def first_call_has_a_dot(node)
Expand Down
20 changes: 20 additions & 0 deletions spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@
RUBY
end

it 'accepts aligned methods when multiline method chain with a block argument and method chain' do
expect_no_offenses(<<~RUBY)
a(b)
.c(
d do
end.f
)
RUBY
end

it "doesn't crash on unaligned multiline lambdas" do
expect_no_offenses(<<~RUBY)
MyClass.(my_args)
Expand Down Expand Up @@ -335,6 +345,16 @@
&.b
RUBY
end

it 'accepts aligned methods when multiline method chain with a block argument and method chain' do
expect_no_offenses(<<~RUBY)
a&.(b)
.c(
d do
end.f
)
RUBY
end
end
end

Expand Down

0 comments on commit 7edb5ca

Please sign in to comment.