Skip to content

Commit

Permalink
[Fix rubocop#48] Fix Performance/RegexpMatch false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed May 9, 2019
1 parent c0ce42b commit 1c61089
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 1c61089

Please sign in to comment.