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 false positive in Layout/DotPosition #10207

Merged
merged 1 commit into from Oct 22, 2021
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
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