Rubocop: Infinite loop when fixed indentation is set for both Layout/ArrayAlignment and Layout/AssignmentIndentation

Created on 23 Sep 2020  路  1Comment  路  Source: rubocop-hq/rubocop

I just found an infinite loop bug that affect's standard's configuration. Minimal repro steps:

Given file listing foo.rb:

thing, foo =
    1, 2

and config.yml:

Layout/ArrayAlignment:
  Enabled: true
  EnforcedStyle: with_fixed_indentation

Layout/AssignmentIndentation:
  Enabled: true
  IndentationWidth: ~

and running this autocorrect command:

rubocop -a --config config.yml --only "Layout/ArrayAlignment,Layout/AssignmentIndentation" foo.rb

You get this infinite loop output:

Inspecting 1 file
C

Offenses:

foo.rb:2:5: C: [Corrected] Layout/ArrayAlignment: Use one level of indentation for elements following the first line of a multi-line array.
    1, 2
    ^
foo.rb:2:5: C: [Corrected] Layout/AssignmentIndentation: Indent the first line of the right-hand-side of a multi-line assignment.
    1, 2
    ^^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in /Users/justin/code/testdouble/static-rails/foo.rb and caused by Layout/ArrayAlignment, Layout/AssignmentIndentation
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:300:in `check_for_infinite_loop'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:283:in `block in iterate_until_no_changes'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:282:in `loop'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:282:in `iterate_until_no_changes'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:251:in `do_inspection_loop'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:128:in `block in file_offenses'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:153:in `file_offense_cache'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:127:in `file_offenses'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:118:in `process_file'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:97:in `block in each_inspected_file'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:96:in `each'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:96:in `reduce'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:96:in `each_inspected_file'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:82:in `inspect_files'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/runner.rb:43:in `run'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/cli.rb:65:in `run_command'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/lib/rubocop/cli.rb:41:in `run'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/exe/rubocop:13:in `block in <top (required)>'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/justin/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.91.1/exe/rubocop:12:in `<top (required)>'
/Users/justin/.rbenv/versions/2.7.1/bin/rubocop:23:in `load'
/Users/justin/.rbenv/versions/2.7.1/bin/rubocop:23:in `<main>'

Versions:

$ rubocop -v
0.91.1
$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
bug

Most helpful comment

Wow, what a fast turnaround! Amazing work @dvandersluis, and thanks @koic!! 鉂わ笍

>All comments

Wow, what a fast turnaround! Amazing work @dvandersluis, and thanks @koic!! 鉂わ笍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ecbrodie picture ecbrodie  路  3Comments

tedPen picture tedPen  路  3Comments

bquorning picture bquorning  路  3Comments

benoittgt picture benoittgt  路  3Comments

printercu picture printercu  路  3Comments