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

An error occurred while Style/ExplicitBlockArgument #9497

Closed
yarafan opened this issue Feb 9, 2021 · 0 comments · Fixed by #9498
Closed

An error occurred while Style/ExplicitBlockArgument #9497

yarafan opened this issue Feb 9, 2021 · 0 comments · Fixed by #9498
Labels

Comments

@yarafan
Copy link

yarafan commented Feb 9, 2021

Rubocop fails to process file with following code

module WorkerHelper
  # clear workers around each test case
  def around
    Sidekiq::Worker.clear_all
    super { yield }
    Sidekiq::Worker.clear_all
  end

  def assert_last_job_args(expected, worker)
    assert_equal Array.wrap(expected), worker.jobs.last["args"]
  end
end

Expected behavior

Got an error message "Consider using explicit block argument in the surrounding method's signature over yield."

Actual behavior

Got "An error occurred while Style/ExplicitBlockArgument"
Stacktrace

undefined method `name' for #<Parser::Source::Map::Keyword:0x00007febb4d43c10>
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/style/explicit_block_argument.rb:103:in `add_block_argument'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/style/explicit_block_argument.rb:72:in `block (2 levels) in on_yield'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/base.rb:340:in `correct'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/base.rb:127:in `add_offense'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/style/explicit_block_argument.rb:69:in `block in on_yield'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/style/explicit_block_argument.rb:60:in `yielding_block?'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/style/explicit_block_argument.rb:60:in `on_yield'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:100:in `public_send'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:166:in `with_cop_error_handling'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:98:in `each'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:69:in `on_yield'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:158:in `on_block'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:71:in `on_block'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:137:in `each'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:154:in `on_def'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:71:in `on_def'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:137:in `each'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:138:in `on_while'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:71:in `on_module'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:20:in `walk'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/commissioner.rb:86:in `investigate'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/team.rb:157:in `investigate_partial'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cop/team.rb:83:in `investigate'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:315:in `inspect_file'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:259:in `block in do_inspection_loop'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:293:in `block in iterate_until_no_changes'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:286:in `loop'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:255:in `do_inspection_loop'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:132:in `block in file_offenses'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:157:in `file_offense_cache'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:131:in `file_offenses'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:122:in `process_file'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:100:in `each'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:100:in `reduce'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:100:in `each_inspected_file'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:86:in `inspect_files'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/runner.rb:47:in `run'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cli/command.rb:11:in `run'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cli/environment.rb:18:in `run'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cli.rb:65:in `run_command'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cli.rb:72:in `execute_runners'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/lib/rubocop/cli.rb:41:in `run'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/exe/rubocop:13:in `block in <top (required)>'
.rbenv/versions/2.7.2/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-1.9.1/exe/rubocop:12:in `<top (required)>'
.rbenv/versions/2.7.2/bin/rubocop:23:in `load'
.rbenv/versions/2.7.2/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

Run rubocop -d on file with following contents

module WorkerHelper
  # clear workers around each test case
  def around
    Sidekiq::Worker.clear_all
    super { yield }
    Sidekiq::Worker.clear_all
  end

  def assert_last_job_args(expected, worker)
    assert_equal Array.wrap(expected), worker.jobs.last["args"]
  end
end

with no additional configuration

RuboCop version

$ [bundle exec] rubocop -V
1.9.1 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.7.2 x86_64-darwin20)
  - rubocop-performance 1.9.2
@koic koic added the bug label Feb 9, 2021
koic added a commit to koic/rubocop that referenced this issue Feb 9, 2021
Fixes rubocop#9497.

This PR fixes an error for `Style/ExplicitBlockArgument`
when `yield` is inside block of `super`.
koic added a commit that referenced this issue Feb 10, 2021
…ock_argument

[Fix #9497] Fix an error for `Style/ExplicitBlockArgument`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants