Skip to content

Commit

Permalink
Merge pull request #12765 from Earlopain/fix-an-error-for-layout-mult…
Browse files Browse the repository at this point in the history
…iline-method-call-indentation

Fix an error for `Layout/MultilineMethodCallIndentation` with safe navigation and assignment method
  • Loading branch information
koic committed Mar 9, 2024
2 parents 167bad9 + 0ef0e31 commit ca8b38c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12765](https://github.com/rubocop/rubocop/pull/12765): Fix an error for `Layout/MultilineMethodCallIndentation` with safe navigation and assignment method. ([@earlopain][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/multiline_expression_indentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def assignment_rhs(node)
case node.type
when :casgn then _scope, _lhs, rhs = *node
when :op_asgn then _lhs, _op, rhs = *node
when :send then rhs = node.last_argument
when :send, :csend then rhs = node.last_argument
else _lhs, rhs = *node
end
rhs
Expand Down
13 changes: 13 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 @@ -355,6 +355,19 @@
)
RUBY
end

it "doesn't crash on multiline method calls with safe navigation and assignment" do
expect_offense(<<~RUBY)
MyClass.
foo&.bar = 'baz'
^^^ Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
RUBY

expect_correction(<<~RUBY)
MyClass.
foo&.bar = 'baz'
RUBY
end
end
end

Expand Down

0 comments on commit ca8b38c

Please sign in to comment.