Skip to content

Commit

Permalink
Merge pull request #320 from fatkodima/regexp_match-regexp-cbase
Browse files Browse the repository at this point in the history
Fix `Performance/RegexpMatch` to handle `::Regexp`
  • Loading branch information
koic authored Dec 1, 2022
2 parents 55f7f4b + 2842d2b commit 9d2ac69
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/fix_regexp_match_to_handle_cbase_regexp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#314](https://github.com/rubocop/rubocop-performance/issues/314): Fix `Performance/RegexpMatch` to handle `::Regexp`. ([@fatkodima][])
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/regexp_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def match_with_lvasgn?(node)

def_node_search :last_matches, <<~PATTERN
{
(send (const nil? :Regexp) :last_match)
(send (const nil? :Regexp) :last_match _)
(send (const {nil? cbase} :Regexp) :last_match)
(send (const {nil? cbase} :Regexp) :last_match _)
({back_ref nth_ref} _)
(gvar #match_gvar?)
}
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/performance/regexp_match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def foo
%w[
$& $' $` $~ $1 $2 $100
$MATCH
Regexp.last_match Regexp.last_match(1)
Regexp.last_match ::Regexp.last_match Regexp.last_match(1)
].each do |var|
it "accepts #{name} in method with #{var}" do
expect_no_offenses(<<~RUBY)
Expand Down

0 comments on commit 9d2ac69

Please sign in to comment.