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

[Fix #67] Fix an error for Performance/RedundantMerge #68

Merged
merged 1 commit into from Jul 12, 2019

Conversation

koic
Copy link
Member

@koic koic commented Jul 11, 2019

Fixes #67.

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

require: rubocop-performance

Performance/RedundantMerge:
  Enabled: true
  MaxKeyValuePairs: null
% 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.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

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
@koic koic force-pushed the fix_an_error_for_redundant_merge branch from 2438cb2 to e286f25 Compare July 11, 2019 08:06
@koic koic merged commit 69ba7f7 into rubocop:master Jul 12, 2019
@koic koic deleted the fix_an_error_for_redundant_merge branch July 12, 2019 02:57
@ashmaroli
Copy link

@koic Shouldn't the || 2 be inside the parenthesis instead:

- Integer(cop_config['MaxKeyValuePairs']) || 2
+ Integer(cop_config['MaxKeyValuePairs'] || 2)

This way Integer() never operates on a nil value

koic added a commit to koic/rubocop-performance that referenced this pull request Jul 30, 2019
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.
@koic
Copy link
Member Author

koic commented Jul 30, 2019

This is my mistake 💦 I opened a PR #74. Thanks!

@ashmaroli
Copy link

You're welcome @koic

koic added a commit to koic/rubocop-performance that referenced this pull request Jul 30, 2019
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.
renawatson68 added a commit to renawatson68/performance-develop-rubyonrails that referenced this pull request Sep 23, 2022
Follow up rubocop/rubocop-performance#68 (comment).

#68 didn't solve an issue #67 with `Performance/RedundantMerge`.
This PR is corrected by adding a reproduction test.
richardstewart0213 added a commit to richardstewart0213/performance-build-Performance-optimization-analysis- that referenced this pull request Nov 4, 2022
Follow up rubocop/rubocop-performance#68 (comment).

#68 didn't solve an issue #67 with `Performance/RedundantMerge`.
This PR is corrected by adding a reproduction test.
MarttiCheng added a commit to MarttiCheng/Rubocop-Performance that referenced this pull request Sep 28, 2023
Follow up rubocop/rubocop-performance#68 (comment).

#68 didn't solve an issue #67 with `Performance/RedundantMerge`.
This PR is corrected by adding a reproduction test.
SerhiiMisiura added a commit to SerhiiMisiura/Rubocop-Performance that referenced this pull request Oct 5, 2023
Follow up rubocop/rubocop-performance#68 (comment).

#68 didn't solve an issue #67 with `Performance/RedundantMerge`.
This PR is corrected by adding a reproduction test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance/RedundantMerge backtrace
2 participants