Skip to content

Commit

Permalink
Merge pull request #10207 from mvz/fix-dot-position
Browse files Browse the repository at this point in the history
Fix false positive in Layout/DotPosition
  • Loading branch information
koic committed Oct 22, 2021
2 parents f598124 + 53bac7e commit bf18dd3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_fix_false_positive_in_layoutdotposition.md
@@ -0,0 +1 @@
* [#10207](https://github.com/rubocop/rubocop/pull/10207): Fix false positive in Layout/DotPosition when the selector is on the same line as the closing bracket of the receiver. ([@mvz][])
6 changes: 5 additions & 1 deletion lib/rubocop/cop/layout/dot_position.rb
Expand Up @@ -70,7 +70,7 @@ def message(dot)
def proper_dot_position?(node)
selector_range = selector_range(node)

return true if same_line?(selector_range, selector_range(node.receiver))
return true if same_line?(selector_range, end_range(node.receiver))

selector_line = selector_range.line
receiver_line = receiver_end_line(node.receiver)
Expand Down Expand Up @@ -119,6 +119,10 @@ def heredoc?(node)
(node.str_type? || node.dstr_type?) && node.heredoc?
end

def end_range(node)
node.source_range.end
end

def selector_range(node)
return node unless node.call_type?

Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/layout/dot_position_spec.rb
Expand Up @@ -316,6 +316,14 @@
expect_no_offenses('puts something')
end

it 'does not err on method call with multi-line arguments' do
expect_no_offenses(<<~RUBY)
foo(
bar
).baz
RUBY
end

it 'does not err on method call without a method name' do
expect_offense(<<~RUBY)
l
Expand Down

0 comments on commit bf18dd3

Please sign in to comment.