From 06f9333148dd6cab52eeb34bc4adbfb00674f57b Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 30 Jul 2019 02:27:38 +0900 Subject: [PATCH] Fix an error for `Performance/RedundantMerge` Follow up https://github.com/rubocop-hq/rubocop-performance/pull/68#issuecomment-516072052. #68 didn't solve an issue #67 with `Performance/RedundantMerge`. This PR is corrected by adding a reproduction test. --- CHANGELOG.md | 4 ++++ lib/rubocop/cop/performance/redundant_merge.rb | 2 +- .../cop/performance/redundant_merge_spec.rb | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b09db6a49..4e0da22590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rubocop/cop/performance/redundant_merge.rb b/lib/rubocop/cop/performance/redundant_merge.rb index 45b610846c..0ccb54eeea 100644 --- a/lib/rubocop/cop/performance/redundant_merge.rb +++ b/lib/rubocop/cop/performance/redundant_merge.rb @@ -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 diff --git a/spec/rubocop/cop/performance/redundant_merge_spec.rb b/spec/rubocop/cop/performance/redundant_merge_spec.rb index b8c2b65138..5c2a281e71 100644 --- a/spec/rubocop/cop/performance/redundant_merge_spec.rb +++ b/spec/rubocop/cop/performance/redundant_merge_spec.rb @@ -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