Skip to content

Commit

Permalink
[Fix rubocop#67] Fix an error for Performance/RedundantMerge
Browse files Browse the repository at this point in the history
Fixes rubocop#67.

This PR fixes an error for `Performance/RedundantMerge` when
`MaxKeyValuePairs` option is set to `null`.

```yaml
require: rubocop-performance

Performance/RedundantMerge:
  Enabled: true
  MaxKeyValuePairs: null
```

```console
% bundle exec rubocop --only Performance/RedundantMerge -d
For /private/tmp/67: configuration from /private/tmp/67/.rubocop.yml
configuration from
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-performance-1.4.0/config/default.yml
configuration from
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-performance-1.4.0/config/default.yml
Default configuration from
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/config/default.yml
Inspecting 2 files
Scanning /private/tmp/67/Gemfile
.Scanning /private/tmp/67/example.rb
An error occurred while Performance/RedundantMerge cop was inspecting
/private/tmp/67/example.rb:23:2.
can't convert nil into Integer
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:135:in
`Integer'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:135:in
`max_key_value_pairs'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:74:in
`non_redundant_pairs?'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:68:in `non_redundant_merge?
```

As with `Width` option of `IndentationWidth` cop, value of default.yml
is specified as the default value.

- https://github.com/rubocop-hq/rubocop-performance/blob/v1.4.0/lib/rubocop/cop/performance/redundant_merge.rb#L131
- https://github.com/rubocop-hq/rubocop/blob/v0.72.0/config/default.yml#L794-L801
  • Loading branch information
koic committed Jul 11, 2019
1 parent 29316f4 commit e286f25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
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)

### Bug fixes

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

## 1.4.0 (2019-06-20)

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

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

# A utility class for checking the use of values within an
Expand Down

0 comments on commit e286f25

Please sign in to comment.