Skip to content

Commit

Permalink
Merge pull request #228 from dvandersluis/redundant-merge-unsafe
Browse files Browse the repository at this point in the history
Mark `Performance/RedundantMerge` as unsafe
  • Loading branch information
SerhiiMisiura committed Mar 29, 2021
2 parents 3984bc3 + 8d0827a commit f8f72b5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Changes

* [#228](https://github.com/rubocop/rubocop-performance/pull/228): Mark `Performance/RedundantMerge` as unsafe. ([@dvandersluis][])

## 1.10.2 (2021-03-23)

### Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Expand Up @@ -220,7 +220,9 @@ Performance/RedundantMerge:
Description: 'Use Hash#[]=, rather than Hash#merge! with a single key-value pair.'
Reference: 'https://github.com/JuanitoFatas/fast-ruby#hashmerge-vs-hash-code'
Enabled: true
Safe: false
VersionAdded: '0.36'
VersionChanged: '1.11'
# Max number of key-value pairs to consider an offense
MaxKeyValuePairs: 2

Expand Down
9 changes: 6 additions & 3 deletions docs/modules/ROOT/pages/cops_performance.adoc
Expand Up @@ -1272,17 +1272,20 @@ return value unless regex =~ 'str'
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged

| Enabled
| Yes
| Yes
| No
| Yes (Unsafe)
| 0.36
| -
| 1.11
|===

This cop identifies places where `Hash#merge!` can be replaced by
`Hash#[]=`.
You can set the maximum number of key-value pairs to consider
an offense with `MaxKeyValuePairs`.

This cop is marked as unsafe because RuboCop cannot determine if the
receiver of `merge!` is actually a hash or not.

=== Examples

[source,ruby]
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/cop/performance/redundant_merge.rb
Expand Up @@ -8,6 +8,9 @@ module Performance
# You can set the maximum number of key-value pairs to consider
# an offense with `MaxKeyValuePairs`.
#
# This cop is marked as unsafe because RuboCop cannot determine if the
# receiver of `merge!` is actually a hash or not.
#
# @example
# # bad
# hash.merge!(a: 1)
Expand Down

0 comments on commit f8f72b5

Please sign in to comment.