Skip to content
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 #48] Fix RegexpMatch false positive #49

Merged
merged 1 commit into from
May 10, 2019

Conversation

dduugg
Copy link
Contributor

@dduugg dduugg commented May 4, 2019

This fixes false positives in Performance/RegexpMatch by only flagging single-argument match methods where either the receiver or the argument is a literal of type Regexp, String, Symbol.

Resolves #48


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

## 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][])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated typo fix

@@ -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` ' \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to resolve a Metrics/ClassLength cop violation.

@dduugg dduugg force-pushed the fix-regexp_match-falfe-positive branch from 1672399 to 446b0be Compare May 4, 2019 16:15
CHANGELOG.md Outdated
@@ -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][])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write a little more about what false positives have been fixed?

@koic
Copy link
Member

koic commented May 9, 2019

This code looks good. Could you please rebase using latest master branch? A warning will probably occur because Ruby 2.2 was dropped.

@dduugg dduugg force-pushed the fix-regexp_match-falfe-positive branch from 446b0be to 1c61089 Compare May 9, 2019 16:33
@dduugg
Copy link
Contributor Author

dduugg commented May 9, 2019

@koic I've updated the changelog to detail the change, and rebased on current master. Please take another look. Thanks!

@koic koic merged commit 9ee61d2 into rubocop:master May 10, 2019
@koic
Copy link
Member

koic commented May 10, 2019

Thanks!

@dduugg dduugg deleted the fix-regexp_match-falfe-positive branch May 13, 2019 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positives for match in RegexpMatch
2 participants