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 #10140] Fix false positive for Layout/DotPosition when a heredoc receives a method on the same line as the start sigil in trailing style #10141

Merged
merged 1 commit into from Sep 29, 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_for_layoutdotposition.md
@@ -0,0 +1 @@
* [#10140](https://github.com/rubocop/rubocop/issues/10140): Fix false positive for `Layout/DotPosition` when a heredoc receives a method on the same line as the start sigil in `trailing` style. ([@dvandersluis][])
10 changes: 7 additions & 3 deletions lib/rubocop/cop/layout/dot_position.rb
Expand Up @@ -68,14 +68,18 @@ def message(dot)
end

def proper_dot_position?(node)
receiver_line = receiver_end_line(node.receiver)
selector_line = selector_range(node).line

# receiver and selector are on the same line
return true if selector_line == receiver_line
# If the receiver is a HEREDOC and the selector is on the same line
# then there is nothing to do
return true if heredoc?(node.receiver) && node.receiver.loc.first_line == selector_line

receiver_line = receiver_end_line(node.receiver)
dot_line = node.loc.dot.line

# receiver and selector are on the same line
return true if selector_line == receiver_line

# don't register an offense if there is a line comment between the
# dot and the selector otherwise, we might break the code while
# "correcting" it (even if there is just an extra blank line, treat
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/layout/dot_position_spec.rb
Expand Up @@ -465,5 +465,15 @@
RUBY
end
end

context 'when there is a heredoc with a following method' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
<<~HEREDOC.squish
something
HEREDOC
RUBY
end
end
end
end