Skip to content

Commit

Permalink
[Fix rubocop#9097] Fix a false positive for `Layout/EmptyLinesAroundA…
Browse files Browse the repository at this point in the history
…rguments`

Fixes rubocop#9097.

This PR fixes a false positive for `Layout/EmptyLinesAroundArguments`
when blank line is inserted between method with arguments and receiver.
  • Loading branch information
koic committed Nov 26, 2020
1 parent e723c9b commit 8aa8576
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
@@ -0,0 +1 @@
* [#9097](https://github.com/rubocop-hq/rubocop/issues/9097): Fix a false positive for `Layout/EmptyLinesAroundArguments` when blank line is inserted between method with arguments and receiver. ([@koic][])
7 changes: 6 additions & 1 deletion lib/rubocop/cop/layout/empty_lines_around_arguments.rb
Expand Up @@ -45,7 +45,8 @@ class EmptyLinesAroundArguments < Base
MSG = 'Empty line detected around arguments.'

def on_send(node)
return if node.single_line? || node.arguments.empty?
return if node.single_line? || node.arguments.empty? ||
receiver_and_method_call_on_different_lines?(node)

extra_lines(node) do |range|
add_offense(range) do |corrector|
Expand All @@ -57,6 +58,10 @@ def on_send(node)

private

def receiver_and_method_call_on_different_lines?(node)
node.receiver && node.receiver.loc.last_line != node.loc.selector.line
end

def empty_lines(node)
lines = processed_lines(node)
lines.select! { |code, _| code.empty? }
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/layout/empty_lines_around_arguments_spec.rb
Expand Up @@ -284,6 +284,14 @@ def anything; end
RUBY
end

it 'accepts when blank line is inserted between method with arguments and receiver' do
expect_no_offenses(<<~RUBY)
foo.
bar(arg)
RUBY
end

context 'with one argument' do
it 'ignores empty lines inside of method arguments' do
expect_no_offenses(<<~RUBY)
Expand Down

0 comments on commit 8aa8576

Please sign in to comment.