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

Style/RedundantStringEscape has bad interaction with squiggly heredoc #11346

Closed
amake opened this issue Dec 28, 2022 · 0 comments · Fixed by #11347
Closed

Style/RedundantStringEscape has bad interaction with squiggly heredoc #11346

amake opened this issue Dec 28, 2022 · 0 comments · Fixed by #11347
Labels

Comments

@amake
Copy link

amake commented Dec 28, 2022

I have a unit test where the expected value is a squiggly heredoc with a leading space like so:

assert_equal(<<~TXT.chomp, segments.last)
  \ very long string that has a leading space
TXT

The Style/RedundantStringEscape cop flags the escaped leading space, and wants to autocorrect it to remove the escape. The Layout/HeredocIndentation cop then wants to remove the space, resulting in a non-equivalent string.

I tried to use an interpolated string literal (#{' '}very long string...) but this is flagged by Lint/LiteralInInterpolation.

I know there are various other contortions I could try to build the desired string, but that seems like it shouldn't be necessary.


Expected behavior

The Style/RedundantStringEscape shouldn't flag an escape necessary for the meaning of the string, and shouldn't remove it as an autofix.

Actual behavior

Style/RedundantStringEscape will in some cases flag an escape that is necessary for the meaning of the string, and will remove it as an autofix.

Steps to reproduce the problem

Write a squiggly heredoc containing a leading escaped whitespace character.

RuboCop version

$ bundle exec rubocop -V
1.41.1 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on ruby 2.7.7) [x86_64-darwin22]
  - rubocop-performance 1.15.2
@koic koic added the bug label Dec 28, 2022
koic added a commit to koic/rubocop that referenced this issue Dec 28, 2022
…cape`

Fixes rubocop#11346.

This PR fixes a false positive for `Style/RedundantStringEscape`
when using escaped space in heredoc.
koic added a commit that referenced this issue Dec 30, 2022
…t_string_escape

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

Successfully merging a pull request may close this issue.

2 participants