Skip to content

Commit

Permalink
Merge pull request #49 from dduugg/fix-regexp_match-falfe-positive
Browse files Browse the repository at this point in the history
[Fix #48] Fix RegexpMatch false positive
  • Loading branch information
koic authored May 10, 2019
2 parents c0ce42b + 1c61089 commit 9ee61d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#48](https://github.com/rubocop-hq/rubocop-performance/issues/48): Reduce `Performance/RegexpMatch` false positive by only flagging `match` used with Regexp/String/Symbol literals. ([@dduugg][])

### Changes

* [#52](https://github.com/rubocop-hq/rubocop-performance/issues/52): Drop support for Ruby 2.2. ([@bquorning][])
Expand All @@ -10,7 +14,7 @@

### 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)

Expand All @@ -28,3 +32,4 @@
[@composerinteralia]: https://github.com/composerinteralia
[@koic]: https://github.com/koic
[@bquorning]: https://github.com/bquorning
[@dduugg]: https://github.com/dduugg
6 changes: 3 additions & 3 deletions lib/rubocop/cop/performance/regexp_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 `%<current>s` when `MatchData` ' \
MSG = 'Use `match?` instead of `%<current>s` when `MatchData` ' \
'is not used.'

def_node_matcher :match_method?, <<-PATTERN
{
(send _recv :match _ <int ...>)
(send _recv :match _)
(send _recv :match {regexp str sym})
(send {regexp str sym} :match _)
}
PATTERN

Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/performance/regexp_match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9ee61d2

Please sign in to comment.