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

[Fix #8948] Fix autocorrection for Style/RedundantRegexpCharacterClass with %r #8954

Commits on Oct 28, 2020

  1. [Fix rubocop#8948] Fix autocorrection for Style/RedundantRegexpCharac…

    …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`
    ```
    ysakasin committed Oct 28, 2020
    Configuration menu
    Copy the full SHA
    0e74823 View commit details
    Browse the repository at this point in the history