From 30f8583cfc778e2dec52649db9fcc90143e9d0fe Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 19 Mar 2022 00:10:08 +0900 Subject: [PATCH] [Fix #10456] Fix a false positive for `Layout/MultilineMethodCallIndentation` Fixes #10456. This PR fixes a false positive for `Layout/MultilineMethodCallIndentation` when using `EnforcedStyle: indented` with indented assignment method. --- ...itive_for_layout_multiline_method_call_indentation.md | 1 + .../cop/mixin/multiline_expression_indentation.rb | 4 +++- .../cop/layout/multiline_method_call_indentation_spec.rb | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_false_positive_for_layout_multiline_method_call_indentation.md diff --git a/changelog/fix_false_positive_for_layout_multiline_method_call_indentation.md b/changelog/fix_false_positive_for_layout_multiline_method_call_indentation.md new file mode 100644 index 00000000000..59cf7166beb --- /dev/null +++ b/changelog/fix_false_positive_for_layout_multiline_method_call_indentation.md @@ -0,0 +1 @@ +* [#10456](https://github.com/rubocop/rubocop/issues/10456): Fix a false positive for `Layout/MultilineMethodCallIndentation` when using `EnforcedStyle: indented` with indented assignment method. ([@koic][]) diff --git a/lib/rubocop/cop/mixin/multiline_expression_indentation.rb b/lib/rubocop/cop/mixin/multiline_expression_indentation.rb index e44e0f324f5..30911dab051 100644 --- a/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +++ b/lib/rubocop/cop/mixin/multiline_expression_indentation.rb @@ -29,7 +29,9 @@ def on_send(node) # b c { block }. <-- b is indented relative to a # d <-- d is indented relative to a def left_hand_side(lhs) - lhs = lhs.parent while lhs.parent&.send_type? && lhs.parent.loc.dot + while lhs.parent&.send_type? && lhs.parent.loc.dot && !lhs.parent.assignment_method? + lhs = lhs.parent + end lhs 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 18226d5adfd..943230abe28 100644 --- a/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb +++ b/spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb @@ -985,6 +985,15 @@ def foo .to_s RUBY end + + it "accepts indentation of assignment to obj.#{lhs} with newline after =" do + expect_no_offenses(<<~RUBY) + obj.#{lhs} = + int_part + .abs + .to_s + RUBY + end end include_examples 'assignment', 'a'