You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Style/RedundantRegexpCharacterClass should not flag or fix single characters in brackets in interpolations. Interpolations with bracket notation are typically used to access objects and should not be treated as single-element classes.
Actual behavior
The Style/RedundantRegexpCharacterClass flags and fixes single characters in brackets in interpolations. Interpolations with bracket notation is viewed as a single-element class and has the brackets removed. This results in the Lint/Syntax cop flagging the change due to unrecognized characters in the interpolation. See below.
The expected behavior is that the regexp should resolve to /one/. However, running the Style/RedundantRegexpCharacterClass will flag [0] as a single-element class even though it is valid notation for accessing the first element of an array. Attempting to auto-correct with this cop results in the following change to the file:
Namely:
- `Lint/MixedRegexpCaptureTypes`
- `Style/RedundantRegexpCharacterClass` (disabled by default due to
rubocop/rubocop#8098)
- `Style/RedundantRegexpEscape`
…terClass
Also correct the handling of interpolations and comments - we need to
preserve their width in the checked pattern source without their
contents triggering the cop in question, so that we can correctly
highlight following offenses based on the offset in the pattern_source.
Namely:
- `Lint/MixedRegexpCaptureTypes`
- `Style/RedundantRegexpCharacterClass` (disabled by default due to
rubocop/rubocop#8098)
- `Style/RedundantRegexpEscape`
Expected behavior
The Style/RedundantRegexpCharacterClass should not flag or fix single characters in brackets in interpolations. Interpolations with bracket notation are typically used to access objects and should not be treated as single-element classes.
Actual behavior
The Style/RedundantRegexpCharacterClass flags and fixes single characters in brackets in interpolations. Interpolations with bracket notation is viewed as a single-element class and has the brackets removed. This results in the Lint/Syntax cop flagging the change due to unrecognized characters in the interpolation. See below.
Steps to reproduce the problem
Take this trivial script:
The expected behavior is that the regexp should resolve to
/one/
. However, running the Style/RedundantRegexpCharacterClass will flag[0]
as a single-element class even though it is valid notation for accessing the first element of an array. Attempting to auto-correct with this cop results in the following change to the file:The interpolation
string.split('.')0
has invalid syntax and results in the Lint/Syntax cop flagging the change due to an unexpected integer:RuboCop version
The text was updated successfully, but these errors were encountered: