-
-
Notifications
You must be signed in to change notification settings - Fork 81
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: Does not consider ::Regexp.last_match(1)
#314
Comments
For the second case it should not trigger an offense, because of |
Consider the two lines together. The first should trigger an offense, but it does not since there is an unrelated |
Seems like yes. |
I understand the reasoning. |
Yes, I opened a PR with the fix. |
I noticed a couple of issues with this cop.
::Regexp.last_match(1)
as use ofMatchData
MatchData
if a following unrelated line mentions MatchData-like statements.Expected behavior
Expectation 1:
::Regexp.last_match(1)
should be detected asMatchData
useExpecting the cop detect
::Regexp.last_match(1)
as use ofMatchData
and not trigger an offense (in the same way it detectsRegexp.last_match(1)
or$1
).Expectation 2: Offense should be reported
The first line below does not use
MatchData
, the cop is expected to report an offense. Removing the second (unrelated) line makes it work as expected.Actual behavior
This code triggers an offense where it shouldn't:
This code does not trigger an offense, where it should:
Steps to reproduce the problem
then run
rubocop --only Performance
and get this output (trimmed for readability):Additional consideration
Note that normally I am using
$1
and notRegexp.last_match
(and definitely not::Regexp.last_match
), but the nativeStyle/PerlBackrefs
cop autocorrected my code to::Regexp.last_match
.The point being - if one cop is saying "use
::Regexp.last_match
", then the other cop should be aware of it.RuboCop version
The text was updated successfully, but these errors were encountered: