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 #118] Fix a false positive for DeletePrefix and DeletePrefix cops #119

Conversation

koic
Copy link
Member

@koic koic commented May 25, 2020

Fixes #118.

Fix a false positive for Performance/DeletePrefix, Performance/DeletePrefix, Performance/StartWith, and Performance/EndWith cops when receiver is multiline string.


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.

@avdv
Copy link

avdv commented May 25, 2020

Hi @koic

I think the problem is not in any way related to heredocs.

Take any string containing newlines, and you cannot simply replace a call to .gsub(/^prefix/, '') with delete_prefix('prefix') since the latter has a different meaning, likewise for .gsub(/suffix$/, '').

The only thing that works in general is /\Aprefix/ and /suffix\z/.

@koic koic force-pushed the fix_false_positive_for_delete_prefix_and_delete_suffix branch from 7a499d8 to 1377de1 Compare June 4, 2020 17:17
@koic
Copy link
Member Author

koic commented Jun 4, 2020

@avdv Thanks for your feedback. I have rewritten this PR and added SafeMultiline option which is true by default. So it will detect only /\Aprefix/ and /suffix\z/ by default.

…Prefix` cops

Fixes rubocop#118.

Fix a false positive for `Performance/DeletePrefix`, `Performance/DeletePrefix`,
`Performance/StartWith`, and `Performance/EndWith` cops when receiver is multiline string.
@koic koic force-pushed the fix_false_positive_for_delete_prefix_and_delete_suffix branch from 1377de1 to f5f560f Compare June 4, 2020 17:26
@avdv
Copy link

avdv commented Jun 4, 2020

Thank you, LGTM!

@koic koic merged commit 67f8660 into rubocop:master Jun 5, 2020
@koic koic deleted the fix_false_positive_for_delete_prefix_and_delete_suffix branch June 5, 2020 02:04
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 positive with DeletePrefix
2 participants