Skip to content

Commit

Permalink
Fix a false positive for Performance/RegexpMatch
Browse files Browse the repository at this point in the history
Follow up rubocop/rubocop-performance#288 (comment).

This PR fixes a false positive for `Performance/RegexpMatch`
when `TargetRubyVersion: 2.3`.
  • Loading branch information
MarttiCheng committed Jun 7, 2022
1 parent 428ed26 commit 1ac9d40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#292](https://github.com/rubocop/rubocop-performance/pull/292): Fix a false positive for `Performance/RegexpMatch` when `TargetRubyVersion: 2.3`. ([@koic][])
3 changes: 3 additions & 0 deletions lib/rubocop/cop/performance/regexp_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ module Performance
# end
class RegexpMatch < Base
extend AutoCorrector
extend TargetRubyVersion

minimum_target_ruby_version 2.4

# Constants are included in this list because it is unlikely that
# someone will store `nil` as a constant and then use it for comparison
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/performance/regexp_match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,13 @@ def foo
end
RUBY
end

context 'when Ruby <= 2.3', :ruby23 do
it 'does not register an offense when using `String#match` in condition' do
expect_no_offenses(<<~RUBY)
if 'foo'.match(re)
end
RUBY
end
end
end

0 comments on commit 1ac9d40

Please sign in to comment.