Skip to content

Commit

Permalink
Merge pull request #153 from koic/mark_string_include_as_unsafe_autoc…
Browse files Browse the repository at this point in the history
…orrect

[Fix #145] Mark `Performance/StringInclude` as unsafe
  • Loading branch information
koic authored Jul 17, 2020
2 parents 33832a8 + 5237b39 commit dad69b1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Changes

* [#149](https://github.com/rubocop-hq/rubocop-performance/pull/149): Mark `Performance/AncestorsInclude` as unsafe. ([@eugeneius][])
* [#145](https://github.com/rubocop-hq/rubocop-performance/issues/145): Mark `Performance/StringInclude` as `SafeAutocorrect: false` and disable autocorrect by default. ([@koic][])

## 1.7.0 (2020-07-07)

Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
SafeAutoCorrect: false
VersionAdded: '1.7'

Performance/StringReplacement:
Expand Down
14 changes: 13 additions & 1 deletion docs/modules/ROOT/pages/cops_performance.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1499,14 +1499,16 @@ for receiver is multiline string.

| Pending
| Yes
| Yes
| Yes (Unsafe)
| 1.7
| -
|===

This cop identifies unnecessary use of a regex where
`String#include?` would suffice.

This cop's offenses are not safe to auto-correct if a receiver is nil.

=== Examples

[source,ruby]
Expand All @@ -1523,6 +1525,16 @@ This cop identifies unnecessary use of a regex where
'abc'.include?('ab')
----

=== Configurable attributes

|===
| Name | Default value | Configurable values

| AutoCorrect
| `false`
| Boolean
|===

== Performance/StringReplacement

|===
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/performance/string_include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Performance
# This cop identifies unnecessary use of a regex where
# `String#include?` would suffice.
#
# This cop's offenses are not safe to auto-correct if a receiver is nil.
#
# @example
# # bad
# 'abc'.match?(/ab/)
Expand Down

0 comments on commit dad69b1

Please sign in to comment.