-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance/RegexpMatch: not enough global variables recognised #4589
Comments
Thanks for your report. I can't reproduce this problem.
if commit_info =~ /^commit \s* ([a-f0-9]+)$/xi
info[:commit] = $1
end
AllCops:
TargetRubyVersion: 2.4 $ rubocop --only RegexpMatch --cache false
Inspecting 1 file
.
1 file inspected, no offenses detected
This gvar is not parsed as $ ruby-parse test.rb
(if
(send
(send nil :commit_info) :=~
(regexp
(str "^commit \\s* ([a-f0-9]+)$")
(regopt :i :x)))
(send
(send nil :info) :[]=
(sym :commit)
(nth-ref 1)) nil) And rubocop handle Could you give me |
Apologies, that was a snippet from a larger file. When I reduced the file to only the three lines I supplied it doesn't report an offense. But if I add a little more of the context up to a class method it seems to trigger the problem: # frozen_string_literal: true
class MyClass
def self.parse(commit_info)
if commit_info =~ /^commit \s* ([a-f0-9]+)$/xi
return $1
end
end
end
|
Thanks. I can reproduce it. 👍 |
Thank you! 🙇🏻 |
Rubocop falsely reports an offense for the RegexpMatch cop on the following code:
The match data is being used by
$1
.To my eye this looks like the numbered global match variables (
$1
,$2
, ...) need to be added toRegexpMatch#match_gvar?
.Expected behavior
No offense reported.
Actual behavior
Offense reported.
Steps to reproduce the problem
Use a Regexp match and global match variables like the example above.
RuboCop version
The text was updated successfully, but these errors were encountered: