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
Invalid autocorrection with Style/RedundantRegexpCharacterClass #8948
Comments
@ysakasin did you want to have a look? |
@marcandre Yes, I look it. |
Let me just throw in another simple broken example. this fails to get the position of because |
Ohhh. That's a different issue though, and should probably be fixed in the regexp parser gem... |
Examples
|
Right. It seems like their problem. |
…terClass with %r This commit uses `RegexpNode::RegexpParser#body` (rubocop#8960) instead of `Parser::Source::Range#adjust` in Style/RedundantRegexpCharacterClass. When regular expression are written by %r literal, RedundantRegexpCharacterClass made incorrect loc as following. ``` %r{abc[\d]+} ^^^^^^ ``` This bug are caused by calling`node.loc.begin.adjust` to get range of character class with %r regexp. `Parser::Source::Range#adjust` adjust based on `Parser::Source::Range#begin_pos` but it with %r literal doesn't indicate start of regular expression source, point to location of '%'. So, RedundantRegexpCharacterClass makes incorrect loc if %r literal are used in code. ``` r = %r{abc} ^ # `node.loc.begin.begin_pos` ``` ``` r = %r{abs} ^ # `node.loc.begin.end_pos` ```
Expected behavior
Regex autocorrect is a valid regex.
Actual behavior
The offense is partially corrected and an invalid regex is produced. This is a similar problem to the one that was fixed in #8913, but the issue still happens against current master with that fix.
Steps to reproduce the problem
Autocorrect:
Correct is to:
RuboCop version
The text was updated successfully, but these errors were encountered: