Navigation Menu

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 Lint/UselessTimes cop was inspecting ... #10415

Closed
msbit opened this issue Feb 14, 2022 · 1 comment · Fixed by #10420
Closed

An error occurred while Lint/UselessTimes cop was inspecting ... #10415

msbit opened this issue Feb 14, 2022 · 1 comment · Fixed by #10420
Labels

Comments

@msbit
Copy link

msbit commented Feb 14, 2022

Expected behavior

Just the (correctable) warning for Lint/UselessTimes

Actual behavior

For /Users/tom/Development/msbit/megadrive: Default configuration from /Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/config/default.yml
Use parallel by default.
Running parallel inspection
An error occurred while Lint/UselessTimes cop was inspecting /Users/tom/Development/msbit/megadrive/buffer.rb:27:4.
undefined method `body' for s(:send,
  s(:int, 1), :times):RuboCop::AST::SendNode
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/lint/useless_times.rb:84:in `autocorrect_block'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/lint/useless_times.rb:61:in `block in on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/base.rb:342:in `correct'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/base.rb:127:in `add_offense'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/lint/useless_times.rb:53:in `on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:134:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:158:in `block in on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:155:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:155:in `each_with_index'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:155:in `on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:153:in `on_block'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:153:in `on_def'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_def'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:153:in `on_class'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_class'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:309:in `inspect_file'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:253:in `block in do_inspection_loop'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:287:in `block in iterate_until_no_changes'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:280:in `loop'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:280:in `iterate_until_no_changes'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:249:in `do_inspection_loop'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:67:in `block in warm_cache'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:515:in `call_with_index'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:485:in `process_incoming_jobs'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:465:in `block in worker'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:456:in `fork'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:456:in `worker'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:447:in `block in create_workers'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:446:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:446:in `each_with_index'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:446:in `create_workers'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:386:in `work_in_processes'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:289:in `map'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:238:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:67:in `warm_cache'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:46:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli.rb:71:in `run_command'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli.rb:78:in `execute_runners'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli.rb:47:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/exe/rubocop:12:in `block in <top (required)>'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/exe/rubocop:12:in `<top (required)>'
/Users/tom/.rbenv/versions/2.7.5/bin/rubocop:23:in `load'
/Users/tom/.rbenv/versions/2.7.5/bin/rubocop:23:in `<main>'
An error occurred while Lint/UselessTimes cop was inspecting /Users/tom/Development/msbit/megadrive/buffer.rb:27:4.
Inspecting 1 file
Scanning /Users/tom/Development/msbit/megadrive/buffer.rb
undefined method `body' for s(:send,
  s(:int, 1), :times):RuboCop::AST::SendNode
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/lint/useless_times.rb:84:in `autocorrect_block'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/lint/useless_times.rb:61:in `block in on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/base.rb:342:in `correct'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/base.rb:127:in `add_offense'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/lint/useless_times.rb:53:in `on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:134:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:158:in `block in on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:155:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:155:in `each_with_index'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:155:in `on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:153:in `on_block'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:153:in `on_def'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_def'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:153:in `on_class'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_class'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.15.2/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:309:in `inspect_file'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:253:in `block in do_inspection_loop'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:287:in `block in iterate_until_no_changes'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:280:in `loop'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:280:in `iterate_until_no_changes'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:249:in `do_inspection_loop'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:120:in `process_file'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:100:in `each'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:100:in `reduce'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:47:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli.rb:71:in `run_command'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli.rb:78:in `execute_runners'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/lib/rubocop/cli.rb:47:in `run'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/exe/rubocop:12:in `block in <top (required)>'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/tom/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.25.1/exe/rubocop:12:in `<top (required)>'
/Users/tom/.rbenv/versions/2.7.5/bin/rubocop:23:in `load'
/Users/tom/.rbenv/versions/2.7.5/bin/rubocop:23:in `<main>'
W

Offenses:

buffer.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
require 'forwardable'
^
buffer.rb:3:1: C: Style/Documentation: Missing top-level documentation comment for class Buffer.

1 error occurred:
An error occurred while Lint/UselessTimes cop was inspecting /Users/tom/Development/msbit/megadrive/buffer.rb:27:4.
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.25.1 (using Parser 3.1.0.0, rubocop-ast 1.15.2, running on ruby 2.7.5 x86_64-darwin19)
class Buffer
^^^^^^^^^^^^
buffer.rb:18:5: W: [Correctable] Lint/UselessTimes: Useless call to 1.times detected.
    1.times do |i| ...
    ^^^^^^^^^^^^^^

1 file inspected, 3 offenses detected, 2 offenses auto-correctable
Finished in 0.38748200004920363 seconds

Steps to reproduce the problem

The issue occurs with the second 1.times loop in the following class:

require 'forwardable'

class Buffer
  extend Forwardable

  def_delegators :@data, :[], :[]=, :slice

  def self.alloc(length)
    Buffer.new(length)
  end

  def initialize(length)
    @data = Array.new(length, 0x00)
  end

  def read_uint8(offset = 0)
    result = 0
    1.times do |i|
      result <<= 8
      result += @data[offset + i]
    end

    result
  end

  def write_uint8(value, offset = 0)
    1.times.reverse_each do |i|
      @data[offset + i] = value & 0xff
      value >>= 8
    end
  end

  def read_uint16_be(offset = 0)
    result = 0
    2.times do |i|
      result <<= 8
      result += @data[offset + i]
    end

    result
  end

  def write_uint16_be(value, offset = 0)
    2.times.reverse_each do |i|
      @data[offset + i] = value & 0xff
      value >>= 8
    end
  end

  def read_uint32_be(offset = 0)
    result = 0
    4.times do |i|
      result <<= 8
      result += @data[offset + i]
    end

    result
  end

  def write_uint32_be(value, offset = 0)
    4.times.reverse_each do |i|
      @data[offset + i] = value & 0xff
      value >>= 8
    end
  end
end

I note that the first invocation is warned about appropriately:

buffer.rb:18:5: W: [Correctable] Lint/UselessTimes: Useless call to 1.times detected.
    1.times do |i| ...
    ^^^^^^^^^^^^^^

so I'm guessing it may have something to do with the use of reverse_each (in 1.times.reverse_each)

RuboCop version

1.25.1 (using Parser 3.1.0.0, rubocop-ast 1.15.2, running on ruby 2.7.5 x86_64-darwin19)
@koic koic added the bug label Feb 14, 2022
koic added a commit to koic/rubocop that referenced this issue Feb 16, 2022
Fixes rubocop#10415.

This PR fixes an error for `Lint/UselessTimes` when using `1.times` with method chain.

This bug fix case does not support auto-correction because it is complicated to cover
the usage of the methods of `Enumerator` returned by `Integer#times` method.
koic added a commit that referenced this issue Feb 16, 2022
@msbit
Copy link
Author

msbit commented Feb 16, 2022

Nice one!

I seem to be the only one around using 1.times in my code, so at least the cop is working in dissuading others 😂

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