From a4a505da327c7a0dcd0e2d6bed2149628ed3e614 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Thu, 12 Oct 2023 00:43:54 +0900 Subject: [PATCH] [Fix #12265] Fix an error for `Layout/MultilineMethodCallIndentation` Fixes #12265. This PR fixes an error for `Layout/MultilineMethodCallIndentation` when usingarithmetic operation with block inside a grouped expression. --- ...ror_for_layout_multiline_method_call_indentation.md | 1 + .../cop/layout/multiline_method_call_indentation.rb | 2 +- .../layout/multiline_method_call_indentation_spec.rb | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_an_error_for_layout_multiline_method_call_indentation.md 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|