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/StringLiterals does not work for Strings interpolated into a Regex #12061

Closed
vinnydiehl opened this issue Jul 21, 2023 · 1 comment
Closed
Labels

Comments

@vinnydiehl
Copy link

To reproduce

With default settings, run RuboCop on:

/foo#{"sar".sub("s", "b")}/

Expected behavior

A Style/StringLiterals warning, or maybe Style/StringLiteralsInInterpolation.

Actual behavior

No warnings.

RuboCop version

1.54.2 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux]

Other thoughts

Would it be better to use Style/StringLiteralsInInterpolation here, rather than Style/StringLiterals? This would be consistent with other interpolations, however, the rule isn't quite as important in this case since there are no external " to cause confusion, as there would be with a String or Symbol.

@jonas054
Copy link
Collaborator

Yes, this seems to be a bug. We've overlooked interpolations inside regular expressions.

Since Style/StringLiteralsInInterpolation currently covers interpolations inside string literals and inside symbol literals, it seems obvious that it should handle regexp literals too.

however, the rule isn't quite as important in this case since there are no external " to cause confusion

Agreed, but up until now we have not cared about this distinction. Style/StringLiteralsInInterpolation reports when the wrong kind of quotes are used even when there are no outer quotes to cause confusion, e.g. in heredocs. So I say we should just add regexp literals to the duties of Style/StringLiteralsInInterpolation and not worry about which delimiters those outer literals use.

@jonas054 jonas054 added the bug label Jul 23, 2023
@koic koic closed this as completed in 8b4de3a Aug 2, 2023
koic added a commit that referenced this issue Aug 2, 2023
…lation_regex

[Fix #12061] Support regex in StringLiteralsInInterpolation
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