Skip to content

Commit

Permalink
[Fix rubocop#9155] Fix a false positive for `Layout/MultilineMethodCa…
Browse files Browse the repository at this point in the history
…llIndentation`

Fixes rubocop#9155.

This PR fixes a false positive for `Layout/MultilineMethodCallIndentation`
when multiline method chain has expected indent width and the method is
preceded by splat for `EnforcedStyle: indented_relative_to_receiver`
  • Loading branch information
koic committed Dec 3, 2020
1 parent 2472e1c commit d047b61
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#9155](https://github.com/rubocop-hq/rubocop/issues/9155): Fix a false positive for `Layout/MultilineMethodCallIndentation` when multiline method chain has expected indent width and the method is preceded by splat for `EnforcedStyle: indented_relative_to_receiver`. ([@koic][])
10 changes: 7 additions & 3 deletions lib/rubocop/cop/layout/multiline_method_call_indentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,21 @@ def offending_range(node, lhs, rhs, given_style)

@base = alignment_base(node, rhs, given_style)
correct_column = if @base
@base.column + extra_indentation(given_style)
@base.column + extra_indentation(given_style, node.parent)
else
indentation(lhs) + correct_indentation(node)
end
@column_delta = correct_column - rhs.column
rhs if @column_delta.nonzero?
end

def extra_indentation(given_style)
def extra_indentation(given_style, parent)
if given_style == :indented_relative_to_receiver
configured_indentation_width
if parent && (parent.splat_type? || parent.kwsplat_type?)
configured_indentation_width - parent.loc.operator.length
else
configured_indentation_width
end
else
0
end
Expand Down
22 changes: 22 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 @@ -693,6 +693,28 @@ def a
RUBY
end

it 'does not register an offense when multiline method chain has expected indent width and ' \
'the method is preceded by splat' do
expect_no_offenses(<<~RUBY)
[
*foo
.bar(
arg)
]
RUBY
end

it 'does not register an offense when multiline method chain has expected indent width and ' \
'the method is preceded by double splat' do
expect_no_offenses(<<~RUBY)
[
**foo
.bar(
arg)
]
RUBY
end

it 'registers an offense and corrects one space indentation of 2nd line' do
expect_offense(<<~RUBY)
a
Expand Down

0 comments on commit d047b61

Please sign in to comment.