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 4, 2019
1 parent 8c5a375 commit 446b0be
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,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)

Expand All @@ -23,3 +27,4 @@

[@composerinteralia]: https://github.com/composerinteralia
[@koic]: https://github.com/koic
[@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.'.freeze

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 446b0be

Please sign in to comment.