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

Handle trailing line continuation in Layout/LineContinuationLeadingSpace #12581

Merged
merged 1 commit into from
Dec 29, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12581](https://github.com/rubocop/rubocop/pull/12581): Handle trailing line continuation in `Layout/LineContinuationLeadingSpace`. ([@eugeneius][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/line_continuation_leading_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def continuation?(line, line_num, node)
return false unless line.end_with?("\\\n")

# Ensure backslash isn't part of a token spanning to the next line.
node.children.none? { |c| c.first_line == line_num && c.multiline? }
node.children.none? { |c| (c.first_line...c.last_line).cover?(line_num) && c.multiline? }
end

def autocorrect(corrector, offense_range, insert_pos, spaces)
Expand Down
23 changes: 23 additions & 0 deletions spec/rubocop/cop/layout/line_continuation_leading_space_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@
RUBY
end

it 'registers no offense when multiline string ends with a line continuation' do
expect_no_offenses(<<~'RUBY')
"" "foo
bar\
"
RUBY
end

it 'registers an offense when multiline string ends on 1st line' do
expect_offense(<<~'RUBY')
"foo
bar" \
" baz"
^ Move leading spaces to the end of previous line.
RUBY

expect_correction(<<~'RUBY')
"foo
bar " \
"baz"
RUBY
end

describe 'interpolated strings' do
it 'registers no offense on interpolated string alone' do
expect_no_offenses(<<~'RUBY')
Expand Down