Rubocop failing with An error occurred while VariableForce cop was inspecting [...]
when using a splat.
Fails on Ruby 2.7.8, 3.1.3, 3.2.2.
Code is valid:
irb(main):001:0> qux = [1, 2, 3, 4, 5] => [1, 2, 3, 4, 5] irb(main):002:0> foo, bar, *baz = qux => [1, 2, 3, 4, 5] irb(main):003:0> foo => 1 irb(main):004:0> bar => 2 irb(main):005:0> baz => [3, 4, 5]Expected behavior
Successful Rubocop run.
Actual behaviorRubocop reports VariableForce error.
An error occurred while VariableForce cop was inspecting /tmp/rubocop-variableforce-error/example.rb. 1 error occurred: An error occurred while VariableForce cop was inspecting /tmp/rubocop-variableforce-error/example.rb. Errors are usually caused by RuboCop bugs. Please, report your problems to RuboCop's issue tracker. https://github.com/rubocop/rubocop/issues Mention the following information in the issue report: 1.51.0 (using Parser 3.2.2.1, rubocop-ast 1.28.1, running on ruby 3.2.2) [x86_64-linux] For /tmp/rubocop-variableforce-error: Default configuration from /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/config/default.yml Use parallel by default. Skipping parallel inspection: only a single file needs inspection Inspecting 1 file Scanning /tmp/rubocop-variableforce-error/example.rb undefined method `source' for nil:NilClass /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/lint/useless_assignment.rb:175:in `remove_local_variable_assignment_part' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/lint/useless_assignment.rb:146:in `autocorrect' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/lint/useless_assignment.rb:69:in `block (2 levels) in check_for_unused_assignments' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/base.rb:377:in `correct' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/base.rb:181:in `add_offense' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/lint/useless_assignment.rb:68:in `block in check_for_unused_assignments' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/lint/useless_assignment.rb:57:in `each' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/lint/useless_assignment.rb:57:in `check_for_unused_assignments' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/lint/useless_assignment.rb:51:in `block in after_leaving_scope' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/lint/useless_assignment.rb:51:in `each_value' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/lint/useless_assignment.rb:51:in `after_leaving_scope' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/force.rb:34:in `public_send' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/force.rb:34:in `block in run_hook' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/force.rb:31:in `each' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/force.rb:31:in `run_hook' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/variable_force.rb:369:in `block (2 levels) in <class:VariableForce>' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/variable_force/variable_table.rb:17:in `invoke_hook' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/variable_force/variable_table.rb:36:in `pop_scope' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/variable_force.rb:81:in `investigate' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/commissioner.rb:164:in `block (2 levels) in invoke_with_argument' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/commissioner.rb:164:in `block in invoke_with_argument' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/commissioner.rb:164:in `each' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/commissioner.rb:164:in `invoke_with_argument' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/commissioner.rb:85:in `investigate' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/team.rb:156:in `investigate_partial' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cop/team.rb:98:in `investigate' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:345:in `block in inspect_file' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:344:in `each' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:344:in `flat_map' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:344:in `inspect_file' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:287:in `block in do_inspection_loop' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:314:in `loop' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:283:in `do_inspection_loop' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:164:in `block in file_offenses' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:189:in `file_offense_cache' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:163:in `file_offenses' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:154:in `process_file' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:134:in `each' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:134:in `reduce' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:134:in `each_inspected_file' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:120:in `inspect_files' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/runner.rb:73:in `run' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli/command.rb:11:in `run' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli/environment.rb:18:in `run' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli.rb:118:in `run_command' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli.rb:125:in `execute_runners' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli.rb:51:in `block in run' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli.rb:77:in `profile_if_needed' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/lib/rubocop/cli.rb:43:in `run' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/exe/rubocop:19:in `block in <top (required)>' /home/bob/.rbenv/versions/3.2.2/lib/ruby/3.2.0/benchmark.rb:311:in `realtime' /home/bob/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.51.0/exe/rubocop:19:in `<top (required)>' /home/bob/.rbenv/versions/3.2.2/bin/rubocop:25:in `load' /home/bob/.rbenv/versions/3.2.2/bin/rubocop:25:in `<main>' . 1 file inspected, no offenses detected Finished in 0.14725028816610575 secondsSteps to reproduce the problem
Create a file containing:
Run Rubocop:
RuboCop version$ rubocop -V 1.51.0 (using Parser 3.2.2.1, rubocop-ast 1.28.1, running on ruby 3.2.2) [x86_64-linux]
Let me know if you need more info - good luck.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4