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

Infinite loop using Layout/ArgumentAlignment (with: with_fixed_indentation) #9954

Closed
Drowze opened this issue Jul 28, 2021 · 0 comments · Fixed by #9956
Closed

Infinite loop using Layout/ArgumentAlignment (with: with_fixed_indentation) #9954

Drowze opened this issue Jul 28, 2021 · 0 comments · Fixed by #9956
Labels

Comments

@Drowze
Copy link
Contributor

Drowze commented Jul 28, 2021

Expected behavior

I expect Rubocop not to crash.

Actual behavior

When running autocorrection on a specific configuration, Rubocop raises an infinite loop error.

Steps to reproduce the problem

Given .rubocop.yml:

AllCops:
  NewCops: disable

Layout/ArgumentAlignment:
  EnforcedStyle: with_fixed_indentation

Given test.rb:

subject { described_class.(some_argument: 'some_value', some_other_argument: 'some_other_value', another_argument: 'another_value') }

When I run rubocop -a --debug --only Layout/LineLength,Layout/ArgumentAlignment,Layout/HashAlignment test.rb
(obs.: there's also a similar behaviour without the --only argument)

It partially autocorrects the file to:

subject {
 described_class.(some_argument: 'some_value', some_other_argument: 'some_other_value', 
   another_argument: 'another_value') }

And I get this output:

For /Users/Drowze/workspace/ruby-scripts/rubocop_bug2: configuration from /Users/Drowze/workspace/ruby-scripts/rubocop_bug2/.rubocop.yml
Default configuration from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/config/default.yml
Inspecting 1 file
Scanning /Users/Drowze/workspace/ruby-scripts/rubocop_bug2/test.rb
C

Offenses:

test.rb:1:121: C: [Corrected] Layout/LineLength: Line is too long. [133/120]
subject { described_class.(some_argument: 'some_value', some_other_argument: 'some_other_value', another_argument: 'another_value') }
                                                                                                                        ^^^^^^^^^^^^^
test.rb:2:121: C: [Corrected] Layout/LineLength: Line is too long. [124/120]
 described_class.(some_argument: 'some_value', some_other_argument: 'some_other_value', another_argument: 'another_value') }
                                                                                                                        ^^^^
test.rb:3:1: C: [Corrected] Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.
another_argument: 'another_value') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:3:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
another_argument: 'another_value') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:3:4: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
   another_argument: 'another_value') }
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:3:19: C: [Corrected] Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.
                  another_argument: 'another_value') }
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:3:22: C: [Corrected] Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.
                     another_argument: 'another_value') }
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:3:22: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
                     another_argument: 'another_value') }
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 files inspected, 8 offenses detected, 8 offenses corrected
Infinite loop detected in /Users/Drowze/workspace/ruby-scripts/rubocop_bug2/test.rb and caused by Layout/HashAlignment -> Layout/ArgumentAlignment
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:299:in `check_for_infinite_loop'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:282:in `block in iterate_until_no_changes'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:281:in `loop'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:250:in `do_inspection_loop'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:120:in `process_file'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:100:in `each'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:100:in `reduce'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/runner.rb:47:in `run'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/cli/command.rb:11:in `run'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/cli/environment.rb:18:in `run'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/cli.rb:65:in `run_command'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/lib/rubocop/cli.rb:41:in `run'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/exe/rubocop:12:in `block in <top (required)>'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/benchmark-0.1.1/lib/benchmark.rb:308:in `realtime'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.4/exe/rubocop:12:in `<top (required)>'
/Users/Drowze/.asdf/installs/ruby/2.7.3/bin/rubocop:23:in `load'
/Users/Drowze/.asdf/installs/ruby/2.7.3/bin/rubocop:23:in `<main>'
Finished in 0.2556749999639578 seconds

RuboCop version

$ rubocop -V
1.18.4 (using Parser 3.0.2.0, rubocop-ast 1.8.0, running on ruby 2.7.3 x86_64-darwin20)
@koic koic added the bug label Jul 28, 2021
koic added a commit to koic/rubocop that referenced this issue Jul 29, 2021
Fixes rubocop#9954.

This PR fixes an infinite loop error for `Layout/HashAlignment` when
`EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArgumentAlignment`.
bbatsov pushed a commit that referenced this issue Aug 3, 2021
Fixes #9954.

This PR fixes an infinite loop error for `Layout/HashAlignment` when
`EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArgumentAlignment`.
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