Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information