Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an error for Layout/MultilineMethodCallIndentation with safe navigation and assignment method #12765

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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