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/StringConcatenation autocorrect leads to more rubocop errors #8830

Closed
mobilutz opened this issue Oct 2, 2020 · 0 comments
Closed

Style/StringConcatenation autocorrect leads to more rubocop errors #8830

mobilutz opened this issue Oct 2, 2020 · 0 comments
Labels

Comments

@mobilutz
Copy link

mobilutz commented Oct 2, 2020

The Style/StringConcatenation is autocorrecting a "complex" string concatenation into a string that is incorrect.

%(You need to read this! This is very important. ) +
  %(<a target="_blank" rel="noopener noreferrer" id="body-redirect-link" ) +
  %(href="https://www.domain.com/article.html">read more</a>)

is being autocorrected to (note the unscoped " inside the string)

"You need to read this! This is very important. <a target="_blank" rel="noopener noreferrer" id="body-redirect-link" href="https://www.domain.com/article.html">read more</a>"

These are the additional errors after the autocorrection:

wrong.rb:3:60: E: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.4 parser; configure using TargetRubyVersion parameter, under AllCops)
"You need to read this! This is very important. <a target="_blank" rel="noopener noreferrer" id="body-redirect-link" href="https://www.domain.com/article.html">read more</a>"
                                                           ^^^^^^
wrong.rb:3:98: E: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.4 parser; configure using TargetRubyVersion parameter, under AllCops)
"You need to read this! This is very important. <a target="_blank" rel="noopener noreferrer" id="body-redirect-link" href="https://www.domain.com/article.html">read more</a>"
                                                                                                 ^^^^
wrong.rb:3:116: E: Lint/Syntax: unexpected token tSTRING
(Using Ruby 2.4 parser; configure using TargetRubyVersion parameter, under AllCops)
"You need to read this! This is very important. <a target="_blank" rel="noopener noreferrer" id="body-redirect-link" href="https://www.domain.com/article.html">read more</a>"
                                                                                                                   ^^^^^^^^
wrong.rb:3:160: E: Lint/Syntax: unexpected token tSTRING
(Using Ruby 2.4 parser; configure using TargetRubyVersion parameter, under AllCops)
"You need to read this! This is very important. <a target="_blank" rel="noopener noreferrer" id="body-redirect-link" href="https://www.domain.com/article.html">read more</a>"
                                                                                                                                                              ^^^^^^^^^^^^^^^^

Expected behavior

Running rubocop -A should correct a concatenated string in a way that does not lead to a broken string.

Actual behavior

Resulting string is wrong.

Steps to reproduce the problem

see above

RuboCop version

$ [bundle exec] rubocop -V
0.92.0 (using Parser 2.7.1.5, rubocop-ast 0.7.1, running on ruby 2.6.6 x86_64-darwin19)
@koic koic added the bug label Oct 2, 2020
@koic koic closed this as completed in 749a495 Oct 2, 2020
koic added a commit that referenced this issue Oct 2, 2020
…double-quotes

Fix #8830 bad autocorrect of `Style/StringConcatenation` when string includes double quotes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants