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 #145] Mark Performance/StringInclude as unsafe #153

Merged
merged 1 commit into from
Jul 17, 2020

Conversation

koic
Copy link
Member

@koic koic commented Jul 16, 2020

Fixes #145.

This PR marks Performance/StringInclude as SafeAutocorrect: false and disable autocorrect by default. The cop's offenses are not safe to auto-correct if a receiver is nil.


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.

Fixes rubocop#145.

This PR marks `Performance/StringInclude` as `SafeAutocorrect: false`
and disable autocorrect by default.

The cop's offenses are not safe to auto-correct if a receiver is nil.
@koic koic merged commit dad69b1 into rubocop:master Jul 17, 2020
@koic koic deleted the mark_string_include_as_unsafe_autocorrect branch July 17, 2020 15:29
@@ -248,6 +248,8 @@ Performance/StartWith:
Performance/StringInclude:
Description: 'Use `String#include?` instead of a regex match with literal-only pattern.'
Enabled: 'pending'
AutoCorrect: false
Copy link
Contributor

@ghiculescu ghiculescu Oct 2, 2020

Choose a reason for hiding this comment

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

is it okay to leave AutoCorrect: true, as long as SafeAutoCorrect: false?

my understanding is:

  • AutoCorrect: true and SafeAutoCorrect: true= autocorrected by rubocop -a or rubocop -A
  • AutoCorrect: true and SafeAutoCorrect: false= autocorrected by rubocop -A only
  • AutoCorrect: false and SafeAutoCorrect: false= never autocorrected
  • AutoCorrect: false and SafeAutoCorrect: true= never autocorrected

Currently this defaults to the third option. Why not the second?

Copy link
Contributor

Choose a reason for hiding this comment

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

As it stands, AutoCorrect: false in the default file is reserved for Cops that have corrections that could be useful to some but probably not most people. An example that comes to my mind is LineLength.

This setting should be overriden in .rubocop.yml or via CLI for those that want it

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.

Performance/StringInclude autocorrect is unsafe
3 participants