Skip to content

Commit

Permalink
Fix an error for Layout/MultilineMethodCallIndentation with safe na…
Browse files Browse the repository at this point in the history
…vigation and assignment method
  • Loading branch information
Earlopain committed Mar 9, 2024
1 parent a1c67b3 commit 0ef0e31
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
@@ -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
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
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 0ef0e31

Please sign in to comment.