Rubocop: False-positive auto-correct for Style/WhileUntilModifier?

Created on 8 Jul 2020  ยท  8Comments  ยท  Source: rubocop-hq/rubocop

Hi,

Whilst running rubocop, I came across this situation:

โžœ  puma git:(master) โœ— rubocop -a 
Inspecting 116 files
..........................................................
.....................................................C....

Offenses:

test/test_thread_pool.rb:148:17: C: [Corrected] Style/WhileUntilModifier: Favor modifier
 until usage when having a single-line body.
    Thread.pass until pool.spawned == 1 ||
                ^^^^^
test/test_thread_pool.rb:214:17: C: [Corrected] Style/WhileUntilModifier: Favor modifier
 until usage when having a single-line body.
    Thread.pass until pool.spawned == 0 ||
                ^^^^^

116 files inspected, 2 offenses detected, 2 offenses corrected
โžœ  puma git:(master) โœ— git diff
โžœ  puma git:(master) โœ— rubocop   
Inspecting 116 files
..........................................................
.....................................................C....

Offenses:

test/test_thread_pool.rb:148:17: C: Style/WhileUntilModifier: Favor modifier until usage when
 having a single-line body.
    Thread.pass until pool.spawned == 1 ||
                ^^^^^
test/test_thread_pool.rb:214:17: C: Style/WhileUntilModifier: Favor modifier until usage when
 having a single-line body.
    Thread.pass until pool.spawned == 0 ||
                ^^^^^

116 files inspected, 2 offenses detected

Even though the Style/WhileUntilModifier cop marks it as [Corrected], it still doesn't really auto-correct it.
Perhaps a bug?

Most helpful comment

Took a bit more time than I hoped ๐Ÿ˜…

A complete spec refactor and three (five, really) bug reports later, it's fixed ๐ŸŽ‰

Thanks for reporting this bug!

All 8 comments

Is this with the latest RuboCop?

Hi Marc,

Is this with the latest RuboCop?

Yep, 0.87.1.

I am also getting a "Infinite loop detected" error. You don't have that?

Ah, weird. Initially, I didn't get it, but now I do.
Here's the stacktrace:
`` Infinite loop detected in /home/utkarsh/github/puma/test/test_thread_pool.rb. /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:289:incheck_for_infinite_loop'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:272:in block in iterate_until_no_changes' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:271:inloop'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:271:in iterate_until_no_changes' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:242:indo_inspection_loop'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:122:in block in file_offenses' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:147:infile_offense_cache'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:120:in file_offenses' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:111:inprocess_file'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:90:in block in each_inspected_file' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:89:ineach'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:89:in reduce' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:89:ineach_inspected_file'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:78:in inspect_files' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/runner.rb:39:inrun'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/cli/command/execute_runner.rb:21:in execute_runner' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/cli/command/execute_runner.rb:13:inrun'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/cli/command.rb:10:in run' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/cli/environment.rb:17:inrun'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/cli.rb:65:in run_command' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/cli.rb:72:inexecute_runners'
/home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/lib/rubocop/cli.rb:41:in run' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/exe/rubocop:13:inblock in /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/benchmark-0.1.0/lib/benchmark.rb:308:in realtime' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/gems/rubocop-0.87.1/exe/rubocop:12:in /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/bin/rubocop:23:in load' /home/utkarsh/.ruby-standalone/gems/ruby/2.7.1/bin/rubocop:23:in

'
````

Ah, ok. Thanks for the report.

I can confirm this is a false positive and I'll try to fix it.

Great, thanks!
You're the best! :tada:

Took a bit more time than I hoped ๐Ÿ˜…

A complete spec refactor and three (five, really) bug reports later, it's fixed ๐ŸŽ‰

Thanks for reporting this bug!

Oh wow, this is awesome!
Thank you! โค๏ธ

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NobodysNightmare picture NobodysNightmare  ยท  3Comments

david942j picture david942j  ยท  3Comments

printercu picture printercu  ยท  3Comments

ecbrodie picture ecbrodie  ยท  3Comments

cabello picture cabello  ยท  3Comments