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 a false negartive for Performance/RegexpMatch #47

Merged
merged 1 commit into from
May 4, 2019

Commits on May 3, 2019

  1. Fix a false negartive for Performance/RegexpMatch

    Follow up rubocop/rubocop#6965.
    
    This PR fixes a false negartive for `Performance/RegexpMatch`
    when using RuboCop 0.68 or higher.
    
    ```ruby
    # example.rb
    def foo
      if /re/.match(foo, 1)
        do_something
      end
    end
    ```
    
    ## RuboCop 0.67
    
    RuboCop 0.67 warns.
    
    ```console
    % rubocop _0.67.2_ --only Performance/RegexpMatch
    Inspecting 1 file
    C
    
    Offenses:
    
    example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match
    when MatchData is not used.
      if /re/.match(foo, 1)
           ^^^^^^^^^^^^^^^^^^
    
    1 file inspected, 1 offense detected
    ```
    
    ## RuboCop 0.68 (Before)
    
    RuboCop 0.68 does not warn. This is a false negative.
    
    ```console
    % rubocop _0.68.1_ --only Performance/RegexpMatch --require
    rubocop-performance
    Inspecting 1 file
    .
    
    1 file inspected, no offenses detected
    ```
    
    ## RuboCop 0.68 (After)
    
    This PR fixes a false negative.
    
    ```console
    % rubocop --only Performance/RegexpMatch --require rubocop-performance
    Inspecting 1 file
    C
    
    Offenses:
    
    example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match
    when MatchData is not used.
      if /re/.match(foo, 1)
           ^^^^^^^^^^^^^^^^^^
    
    1 file inspected, 1 offense detected
    ```
    
    This fix uses the following `<>` node pattern notation introduced in
    RuboCop 0.68, so it supports Ruby version 0.68 or higher.
    rubocop/rubocop#6965
    koic committed May 3, 2019
    Configuration menu
    Copy the full SHA
    25e8894 View commit details
    Browse the repository at this point in the history