-
-
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
Fix a false negartive for Performance/RegexpMatch
#47
Fix a false negartive for Performance/RegexpMatch
#47
Conversation
I will release RuboCop Performance 1.2.0 after being merged with this PR. |
I think we should add a spec example that would catch this. |
My description was lacking. I noticed that existing tests are falling. So I think that there is no need to add a test to this PR because they are covered by existing tests. I think that it is good to add a test of NodePattern to RuboCop Core if adding a test. |
Follow up rubocop/rubocop#6965. This PR fixes a false negartive for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ```ruby # example.rb def foo if /re/.match(foo, 1) do_something end end ``` ## RuboCop 0.67 RuboCop 0.67 warns. ```console % rubocop _0.67.2_ --only Performance/RegexpMatch Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` ## RuboCop 0.68 (Before) RuboCop 0.68 does not warn. This is a false negative. ```console % rubocop _0.68.1_ --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file . 1 file inspected, no offenses detected ``` ## RuboCop 0.68 (After) This PR fixes a false negative. ```console % rubocop --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` This fix uses the following `<>` node pattern notation introduced in RuboCop 0.68, so it supports Ruby version 0.68 or higher. rubocop/rubocop#6965
6a5de0c
to
25e8894
Compare
RuboCop Performance 1.2.0 has been released. https://rubygems.org/gems/rubocop-performance/versions/1.2.0 This version includes the following fix false negative to `Performance/RegexpMatch` cop. rubocop/rubocop-performance#47
@koic recommended we bump to a newer version. The fix we are taking in can be found here: rubocop/rubocop-performance#47
Follow up rubocop/rubocop#7081. This PR fixes a false negartive for `Performance/RegexpMatch` when using RuboCop 0.71 or higher. This causes CI to fail. https://circleci.com/gh/rubocop-hq/rubocop-performance/588 This is a regression similar to rubocop#47. This PR tries to fix it using a node pattern that has been used for a long time.
Follow up rubocop/rubocop#6965.
This PR fixes a false negartive for
Performance/RegexpMatch
when using RuboCop 0.68 or higher.RuboCop 0.67
RuboCop 0.67 warns.
RuboCop 0.68 (Before)
RuboCop 0.68 does not warn. This is a false negative.
RuboCop 0.68 (After)
This PR fixes a false negative.
This fix uses the following
<>
node pattern notation introduced in RuboCop 0.68, so it supports Ruby version 0.68 or higher.rubocop/rubocop#6965
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.