Skip to content

Commit

Permalink
[Fix rubocop#249] Mark Performance/RedundantStringChars as unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasbubane committed May 21, 2021
1 parent 1fff69f commit 5edf8ff
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changes

* [#245](https://github.com/rubocop/rubocop-performance/issues/245): Mark `Performance/DeletePrefix` and `Performance/DeleteSuffix` as unsafe. ([@koic][])
* [#249](https://github.com/rubocop/rubocop-performance/issues/249): Mark `Performance/RedundantStringChars` as unsafe. ([@tejasbubane][])

## 1.11.3 (2021-05-06)

Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ Performance/RedundantSplitRegexpArgument:

Performance/RedundantStringChars:
Description: 'Checks for redundant `String#chars`.'
Safe: false
Enabled: 'pending'
VersionAdded: '1.7'
VersionChanged: '1.12'

Performance/RegexpMatch:
Description: >-
Expand Down
6 changes: 3 additions & 3 deletions docs/modules/ROOT/pages/cops_performance.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1425,10 +1425,10 @@ a deterministic regexp to a string.
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged

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

This cop checks for redundant `String#chars`.
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/cop/performance/redundant_string_chars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module RuboCop
module Cop
module Performance
# This cop checks for redundant `String#chars`.
# It is marked unsafe by default because suggested autocorrections like
# `str[-2..-1]` could return `nil` when `str` holds short values and
# `.chars` on that can raise error - resulting in unsafe behaviour.
#
# @example
# # bad
Expand Down

0 comments on commit 5edf8ff

Please sign in to comment.