Skip to content

Commit

Permalink
Fix an error for Performance/RedundantMerge
Browse files Browse the repository at this point in the history
Follow up rubocop#68 (comment).

rubocop#68 didn't solve an issue rubocop#67 with `Performance/RedundantMerge`.
This PR is corrected by adding a reproduction test.
  • Loading branch information
koic committed Jul 30, 2019
1 parent 6f49b5e commit 06f9333
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#74](https://github.com/rubocop-hq/rubocop-performance/pull/74): Fix an error for `Performance/RedundantMerge` when `MaxKeyValuePairs` option is set to `null`. ([@koic][])

## 1.4.1 (2019-07-29)

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/redundant_merge.rb
Expand Up @@ -132,7 +132,7 @@ def indent_width
end

def max_key_value_pairs
Integer(cop_config['MaxKeyValuePairs']) || 2
Integer(cop_config['MaxKeyValuePairs'] || 2)
end

# A utility class for checking the use of values within an
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/performance/redundant_merge_spec.rb
Expand Up @@ -261,4 +261,18 @@
RUBY
end
end

context 'when MaxKeyValuePairs is set to nil' do
let(:cop_config) do
{ 'MaxKeyValuePairs' => nil }
end

it 'does not raise `TypeError`' do
expect_offense(<<~RUBY)
hash = {}
hash.merge!(a: 1, b: 2)
^^^^^^^^^^^^^^^^^^^^^^^ Use `hash[:a] = 1; hash[:b] = 2` instead of `hash.merge!(a: 1, b: 2)`.
RUBY
end
end
end

0 comments on commit 06f9333

Please sign in to comment.