Skip to content

Commit fac6d99

Browse files
authored
Merge pull request #7828 from tejasbubane/fix-7825
[Fix #7825] Fix crash for `Layout/MultilineMethodCallIndentation`
2 parents 5d47450 + 06309e1 commit fac6d99

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* [#7806](https://github.com/rubocop-hq/rubocop/pull/7806): Fix an error for `Lint/ErbNewArguments` cop when inspecting `ActionView::Template::Handlers::ERB.new`. ([@koic][])
3434
* [#7814](https://github.com/rubocop-hq/rubocop/issues/7814): Fix a false positive for `Migrate/DepartmentName` cop when inspecting an unexpected disabled comment format. ([@koic][])
3535
* [#7728](https://github.com/rubocop-hq/rubocop/issues/7728): Fix an error for `Style/OneLineConditional` when one of the branches contains a self keyword. ([@koic][])
36+
* [#7825](https://github.com/rubocop-hq/rubocop/issues/7825): Fix crash for `Layout/MultilineMethodCallIndentation` with key access to hash. ([@tejasbubane][])
3637

3738
### Changes
3839

lib/rubocop/cop/layout/multiline_method_call_indentation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def semantic_alignment_node(node)
193193
node = node.receiver while node.receiver
194194
# ascend to first call which has a dot
195195
node = node.parent
196-
node = node.parent until node.loc.dot
196+
node = node.parent until node.loc.respond_to?(:dot) && node.loc.dot
197197

198198
return if node.loc.dot.line != node.first_line
199199

spec/rubocop/cop/layout/multiline_method_call_indentation_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ def foo
304304
RUBY
305305
end
306306

307+
context 'target_ruby_version >= 2.5', :ruby25 do
308+
it 'accepts key access to hash' do
309+
expect_no_offenses(<<~RUBY)
310+
hash[key] { 10 / 0 }
311+
.fmap { |x| x * 3 }
312+
RUBY
313+
end
314+
end
315+
307316
it 'accepts 3 aligned methods' do
308317
expect_no_offenses(<<~RUBY)
309318
a_class.new(severity, location, 'message', 'CopName')

0 commit comments

Comments
 (0)