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

Layout/LineContinuationLeadingSpace false positive #12138

Closed
ymap opened this issue Aug 21, 2023 · 1 comment · Fixed by #12139
Closed

Layout/LineContinuationLeadingSpace false positive #12138

ymap opened this issue Aug 21, 2023 · 1 comment · Fixed by #12139

Comments

@ymap
Copy link
Contributor

ymap commented Aug 21, 2023

While examining the code for this rule, I noticed that the logic for detecting line continuations might mistakenly identify certain cases as such.

In the dstr node type, lines ending with a backslash are flagged. However, multiline single-quoted strings, also parsed as this node type, are mistakenly flagged if they end with a backslash.

Here's a code example:

puts '"this text is too" \
" long"'

Expected behavior

No offences for Layout/LineContinuationLeadingSpace should arise.

Actual behavior

An incorrect offence is reported as follows:

example.rb:2:2: C: [Correctable] Layout/LineContinuationLeadingSpace: Move leading spaces to the end of the previous line.
" long"'
 ^

When applying auto-correction with the -a option, it incorrectly alters the code's meaning as shown below:

puts '"this text is too " \
"long"'

Steps to reproduce the problem

  1. Save the following code in a file named example.rb
puts '"this text is too" \
" long"'
  1. Run bundle exec rubocop --only=Layout/LineContinuationLeadingSpace example.rb

RuboCop version

$ bundle exec rubocop -V
1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.0.2) [x86_64-linux]
  - rubocop-performance 1.19.0
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.23.2
@ymap
Copy link
Contributor Author

ymap commented Aug 21, 2023

And I'm working on it.

ymap added a commit to ymap/rubocop that referenced this issue Aug 23, 2023
…LeadingSpace`

Fixes rubocop#12138.

This PR fixes a false positive for `Layout/LineContinuationLeadingSpace`
when a backslash is part of a multiline string literal.
koic added a commit that referenced this issue Aug 24, 2023
…ine_continuation_leading_space

[Fix #12138] Fix a false positive for `Layout/LineContinuationLeadingSpace`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant