-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Lint/LiteralInInterpolation
autocorrects literals inside string like nodes to remove the interpolation. However, this does not make sense for arrays inside a regexp, because the array is converted to a character class that is probably not expected.
For example:
/#{%w[a b c]}/
# compiles to...
/["a", "b", "c"]/
# but it is much more likely the programmer wanted this instead
/[abc]/
The character class created also adds multiple quotes, spaces and commas depending on the array, which means that the rubocop correction of /#{%w[a b c]}/
becomes /[\"a, bc]/
, which looks very different than where it started. As such, even if the programmer was trying to match the array literally, the resulting regexp will not do that.
I would like to suggest removing the ability for Lint/LiteralInInterpolation
to deal with arrays inside a regexp, and instead add a new cop to detect literal arrays inside a regexp (and possibly correct them to proper character classes or alternation).