diff --git a/changelog/fix_an_error_for_layout_multiline_method_call_indentation.md b/changelog/fix_an_error_for_layout_multiline_method_call_indentation.md new file mode 100644 index 000000000000..e82585d6dfff --- /dev/null +++ b/changelog/fix_an_error_for_layout_multiline_method_call_indentation.md @@ -0,0 +1 @@ +* [#12265](https://github.com/rubocop/rubocop/issues/12265): Fix an error for `Layout/MultilineMethodCallIndentation` when usingarithmetic operation with block inside a grouped expression. ([@koic][]) diff --git a/lib/rubocop/cop/layout/multiline_method_call_indentation.rb b/lib/rubocop/cop/layout/multiline_method_call_indentation.rb index aaaeea54c946..afb76b900745 100644 --- a/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +++ b/lib/rubocop/cop/layout/multiline_method_call_indentation.rb @@ -182,7 +182,7 @@ def semantic_alignment_base(node, rhs) return unless rhs.source.start_with?('.', '&.') node = semantic_alignment_node(node) - return unless node&.loc&.selector + return unless node&.loc&.selector && node.loc.dot node.loc.dot.join(node.loc.selector) end diff --git a/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb b/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb index f141d037fd67..6fa108d3c150 100644 --- a/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb +++ b/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb @@ -73,6 +73,16 @@ RUBY end + it 'accepts arithmetic operation with block inside a grouped expression' do + expect_no_offenses(<<~RUBY) + ( + a * b do + end + ) + .c + RUBY + end + it 'accepts an expression where the first method spans multiple lines' do expect_no_offenses(<<~RUBY) subject.each do |item|