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

Mark Performance/RedundantMerge as unsafe #228

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Mark Performance/RedundantMerge as unsafe.
  • Loading branch information
dvandersluis committed Mar 29, 2021
commit fa4a9bf8bda67b7528021c987b894bf1b01ac749
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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