-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[Fix #14502] Fix wrong autocorrect for Style/StringConcatenation when a single-quoted string contains interpolation
#14504
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 #14502] Fix wrong autocorrect for Style/StringConcatenation when a single-quoted string contains interpolation
#14504
Conversation
| it 'registers an offense for `#$`' do | ||
| expect_offense(<<~'RUBY') | ||
| "foo" + '#$bar' | ||
| ^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. | ||
| RUBY | ||
|
|
||
| expect_correction(<<~'RUBY') | ||
| "foo\#$bar" | ||
| RUBY | ||
| end | ||
|
|
||
| it 'registers an offense for `#@`' do | ||
| expect_offense(<<~'RUBY') | ||
| "foo" + '#@bar' | ||
| ^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. | ||
| RUBY | ||
|
|
||
| expect_correction(<<~'RUBY') | ||
| "foo\#@bar" | ||
| RUBY | ||
| end | ||
|
|
||
| it 'registers an offense for `#@@`' do | ||
| expect_offense(<<~'RUBY') | ||
| "foo" + '#@@bar' | ||
| ^^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. | ||
| RUBY | ||
|
|
||
| expect_correction(<<~'RUBY') | ||
| "foo\#@@bar" | ||
| RUBY | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good test cases. That's my two cents. Can you arrange them by scope, starting with the narrowest and ending with the widest?
| it 'registers an offense for `#$`' do | |
| expect_offense(<<~'RUBY') | |
| "foo" + '#$bar' | |
| ^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. | |
| RUBY | |
| expect_correction(<<~'RUBY') | |
| "foo\#$bar" | |
| RUBY | |
| end | |
| it 'registers an offense for `#@`' do | |
| expect_offense(<<~'RUBY') | |
| "foo" + '#@bar' | |
| ^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. | |
| RUBY | |
| expect_correction(<<~'RUBY') | |
| "foo\#@bar" | |
| RUBY | |
| end | |
| it 'registers an offense for `#@@`' do | |
| expect_offense(<<~'RUBY') | |
| "foo" + '#@@bar' | |
| ^^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. | |
| RUBY | |
| expect_correction(<<~'RUBY') | |
| "foo\#@@bar" | |
| RUBY | |
| end | |
| it 'registers an offense for `#@`' do | |
| expect_offense(<<~'RUBY') | |
| "foo" + '#@bar' | |
| ^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. | |
| RUBY | |
| expect_correction(<<~'RUBY') | |
| "foo\#@bar" | |
| RUBY | |
| end | |
| it 'registers an offense for `#@@`' do | |
| expect_offense(<<~'RUBY') | |
| "foo" + '#@@bar' | |
| ^^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. | |
| RUBY | |
| expect_correction(<<~'RUBY') | |
| "foo\#@@bar" | |
| RUBY | |
| end | |
| it 'registers an offense for `#$`' do | |
| expect_offense(<<~'RUBY') | |
| "foo" + '#$bar' | |
| ^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. | |
| RUBY | |
| expect_correction(<<~'RUBY') | |
| "foo\#$bar" | |
| RUBY | |
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I moved globals to be last.
…ion` when a single-quoted string contains interpolation This only escapes `#` when it looks like interpolation, not all the time. If it turns out to not be interpolation after all, `Style/RedundantStringEscape` will take care of it.
8cdf802 to
996eeec
Compare
|
Thanks! |
Fix #14502
This only escapes
#when it looks like interpolation, not all the time. If it turns out to not be interpolation after all,Style/RedundantStringEscapewill take care of it.Before submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).bundle exec rake default. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.mdif the new code introduces user-observable changes. See changelog entry format for details.