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

Performance/RedundantMerge backtrace #67

Closed
lamont-granquist opened this issue Jul 8, 2019 · 1 comment · Fixed by #68
Closed

Performance/RedundantMerge backtrace #67

lamont-granquist opened this issue Jul 8, 2019 · 1 comment · Fixed by #68
Labels
bug Something isn't working

Comments

@lamont-granquist
Copy link

getting several of these errors:

An error occurred while Performance/RedundantMerge cop was inspecting /Users/lamont/oc/chef2/spec/scripts/ssl-serve.rb:23:2.
can't convert nil into Integer
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:135:in `Integer'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:135:in `max_key_value_pairs'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:74:in `non_redundant_pairs?'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:68:in `non_redundant_merge?'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:61:in `block in each_redundant_merge'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:32:in `redundant_merge_candidate'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:60:in `each_redundant_merge'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-performance-1.4.0/lib/rubocop/cop/performance/redundant_merge.rb:32:in `on_send'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/commissioner.rb:59:in `block (2 levels) in trigger_responding_cops'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/commissioner.rb:130:in `with_cop_error_handling'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/commissioner.rb:58:in `block in trigger_responding_cops'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/commissioner.rb:57:in `each'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/commissioner.rb:57:in `trigger_responding_cops'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/ast/traversal.rb:137:in `on_if'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/ast/traversal.rb:50:in `each'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/ast/traversal.rb:50:in `on_begin'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/ast/traversal.rb:13:in `walk'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/commissioner.rb:46:in `investigate'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/team.rb:116:in `investigate'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/team.rb:104:in `offenses'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:277:in `inspect_file'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:225:in `block in do_inspection_loop'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:257:in `block in iterate_until_no_changes'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:250:in `loop'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:250:in `iterate_until_no_changes'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:221:in `do_inspection_loop'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:124:in `block in file_offenses'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:142:in `file_offense_cache'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:122:in `file_offenses'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:110:in `process_file'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:87:in `block in each_inspected_file'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:86:in `each'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:86:in `reduce'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:73:in `inspect_files'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/runner.rb:39:in `run'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cli.rb:210:in `execute_runner'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cli.rb:80:in `execute_runners'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/lib/rubocop/cli.rb:51:in `run'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/exe/rubocop:13:in `block in <top (required)>'
/Users/lamont/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/rubocop-0.72.0/exe/rubocop:12:in `<top (required)>'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/chefstyle-0.13.1/bin/chefstyle:13:in `load'
/Users/lamont/.rvm/gems/ruby-2.6.1/gems/chefstyle-0.13.1/bin/chefstyle:13:in `<top (required)>'
/Users/lamont/.rvm/gems/ruby-2.6.1/bin/chefstyle:23:in `load'
/Users/lamont/.rvm/gems/ruby-2.6.1/bin/chefstyle:23:in `<main>'
/Users/lamont/.rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `eval'
/Users/lamont/.rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `<main>'

That file is:

# ssl-serve.rb
# USAGE: ruby ssl-serve.rb
#
# ssl-serve is a script that serves a local directory over SSL.
# You can use it to test various HTTP behaviors in chef, like chef-client's
# `-j` and `-c` options and remote_file with https connections.
#
require "pp"
require "openssl"
require "webrick"
require "webrick/https"

$ssl = true

CHEF_SPEC_DATA = File.expand_path("../../data", __FILE__)
cert_text = File.read(File.expand_path("ssl/chef-rspec.cert", CHEF_SPEC_DATA))
cert = OpenSSL::X509::Certificate.new(cert_text)
key_text = File.read(File.expand_path("ssl/chef-rspec.key", CHEF_SPEC_DATA))
key = OpenSSL::PKey::RSA.new(key_text)

server_opts = {}
if $ssl
  server_opts.merge!( { SSLEnable: true,
                        SSLVerifyClient: OpenSSL::SSL::VERIFY_NONE,
                        SSLCertificate: cert,
                        SSLPrivateKey: key })
end

# 5 == debug, 3 == warning
LOGGER = WEBrick::Log.new(STDOUT, 5)
DEFAULT_OPTIONS = {
  server: "webrick",
  Port: 9000,
  Host: "localhost",
  environment: :none,
  Logger: LOGGER,
  DocumentRoot: File.expand_path("#{Dir.tmpdir}/chef-118-sampledata"),
  #:AccessLog => [] # Remove this option to enable the access log when debugging.
}.freeze

webrick_opts = DEFAULT_OPTIONS.merge(server_opts)
pp webrick_opts: webrick_opts

server = WEBrick::HTTPServer.new(webrick_opts)
trap("INT") { server.shutdown }

server.start

Could pretty obviously fix this instance, because that code is a bit strange, but there's also others. The line that is failing is the server_opts.merge! line.

@koic koic added the bug Something isn't working label Jul 9, 2019
koic added a commit to koic/rubocop-performance that referenced this issue Jul 11, 2019
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 added a commit to koic/rubocop-performance that referenced this issue Jul 11, 2019
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 added a commit to koic/rubocop-performance that referenced this issue Jul 11, 2019
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 closed this as completed in #68 Jul 12, 2019
koic added a commit that referenced this issue Jul 12, 2019
[Fix #67] Fix an error for `Performance/RedundantMerge`
@koic
Copy link
Member

koic commented Jul 29, 2019

This issue has been resolved RuboCop Performance 1.4.1 has been released.
https://rubygems.org/gems/rubocop-performance/versions/1.4.1

koic added a commit to koic/rubocop-performance that referenced this issue 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 added a commit to koic/rubocop-performance that referenced this issue 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants