diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ddba5b236..7b24fc8c08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,15 @@ ## master (unreleased) +### Bug fixes + +* [#48](https://github.com/rubocop-hq/rubocop-performance/issues/48): Fix false positives in Performance/RegexpMatch. ([@dduugg][]) + ## 1.2.0 (2019-05-04) ### Bug fixes -* [#47](https://github.com/rubocop-hq/rubocop-performance/pull/47): Fix a false negartive for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ([@koic][]) +* [#47](https://github.com/rubocop-hq/rubocop-performance/pull/47): Fix a false negative for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ([@koic][]) ## 1.1.0 (2019-04-08) @@ -23,3 +27,4 @@ [@composerinteralia]: https://github.com/composerinteralia [@koic]: https://github.com/koic +[@dduugg]: https://github.com/dduugg diff --git a/lib/rubocop/cop/performance/regexp_match.rb b/lib/rubocop/cop/performance/regexp_match.rb index 000485a039..011758a704 100644 --- a/lib/rubocop/cop/performance/regexp_match.rb +++ b/lib/rubocop/cop/performance/regexp_match.rb @@ -80,14 +80,14 @@ class RegexpMatch < Cop # Constants are included in this list because it is unlikely that # someone will store `nil` as a constant and then use it for comparison TYPES_IMPLEMENTING_MATCH = %i[const regexp str sym].freeze - MSG = - 'Use `match?` instead of `%s` when `MatchData` ' \ + MSG = 'Use `match?` instead of `%s` when `MatchData` ' \ 'is not used.'.freeze def_node_matcher :match_method?, <<-PATTERN { (send _recv :match _ ) - (send _recv :match _) + (send _recv :match {regexp str sym}) + (send {regexp str sym} :match _) } PATTERN diff --git a/spec/rubocop/cop/performance/regexp_match_spec.rb b/spec/rubocop/cop/performance/regexp_match_spec.rb index 54a0ffc987..6f25765e5e 100644 --- a/spec/rubocop/cop/performance/regexp_match_spec.rb +++ b/spec/rubocop/cop/performance/regexp_match_spec.rb @@ -381,5 +381,13 @@ def foo end RUBY end + + it 'accepts match without explicit regexp/str/sym use' do + expect_no_offenses(<<-RUBY) + if CONST.match(var) + do_something + end + RUBY + end end end