diff --git a/CHANGELOG.md b/CHANGELOG.md index d13e308..524175e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/config/default.yml b/config/default.yml index 17f3e7c..8f4feb9 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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 diff --git a/docs/modules/ROOT/pages/cops_performance.adoc b/docs/modules/ROOT/pages/cops_performance.adoc index 3aebd6a..0f0aa67 100644 --- a/docs/modules/ROOT/pages/cops_performance.adoc +++ b/docs/modules/ROOT/pages/cops_performance.adoc @@ -1272,10 +1272,10 @@ 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 @@ -1283,6 +1283,9 @@ This cop identifies places where `Hash#merge!` can be replaced by 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] diff --git a/lib/rubocop/cop/performance/redundant_merge.rb b/lib/rubocop/cop/performance/redundant_merge.rb index d986cc3..ee920ef 100644 --- a/lib/rubocop/cop/performance/redundant_merge.rb +++ b/lib/rubocop/cop/performance/redundant_merge.rb @@ -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)