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 on Layout/EndAlignment (with EnforcedStyleAlignWith: variable) #9928

Closed
Drowze opened this issue Jul 12, 2021 · 0 comments · Fixed by #9932
Closed

Infinite loop on Layout/EndAlignment (with EnforcedStyleAlignWith: variable) #9928

Drowze opened this issue Jul 12, 2021 · 0 comments · Fixed by #9932
Labels

Comments

@Drowze
Copy link
Contributor

Drowze commented Jul 12, 2021

Expected behavior

I expect Rubocop to autocorrect my code (or at least not crash while trying to do so).

Actual behavior

When running Layout/EndAlignment's autocorrection (with EnforcedStyleAlignWith: variable on that cop), Rubocop raises an infinite loop error.

Steps to reproduce the problem

Given .rubocop.yml:

AllCops:
  NewCops: disable

Layout/EndAlignment:
  EnforcedStyleAlignWith: variable

And a file test.rb:

100.minutes - if rand(100) > 50
                30
              else
                50
              end.minutes

When I run rubocop --only Layout/EndAlignment --debug -a test.rb I get:

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

Offenses:

test.rb:5:15: W: [Corrected] Layout/EndAlignment: end at 5, 14 is not aligned with 100.minutes - if at 1, 0.
              end.minutes
              ^^^

0 files inspected, 1 offense detected, 1 offense corrected
Infinite loop detected in /Users/Drowze/workspace/tests/test.rb and caused by Layout/EndAlignment
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.3/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.1869329996407032 seconds

RuboCop version

$ rubocop -V
1.18.3 (using Parser 3.0.2.0, rubocop-ast 1.7.0, running on ruby 2.7.3 x86_64-darwin20)
@Drowze Drowze changed the title Infinite loop on Layout/EndAlignment (with EnforcedStyleAlignWith: variable)) Infinite loop on Layout/EndAlignment (with EnforcedStyleAlignWith: variable) Jul 12, 2021
@koic koic added the bug label Jul 13, 2021
koic added a commit to koic/rubocop that referenced this issue Jul 14, 2021
Fixes rubocop#9928.

This PR fixes an infinite loop error and a false auto-correction behavior for `Layout/EndAlignment`
when using operator methods and `EnforcedStyleAlignWith: variable`.
This infinite loop error is due to an offense being registered but not auto-corrected.

`EnforcedStyleAlignWith: variable` enforces alignment to variable,
it should be auto-corrected to be aligned to variable even when operator method is used.
koic added a commit that referenced this issue Jul 18, 2021
…t_end_alignment

[Fix #9928] Fix a false auto-correct for `Layout/EndAlignment`
thearjunmdas pushed a commit to thearjunmdas/rubocop that referenced this issue Aug 20, 2021
Fixes rubocop#9928.

This PR fixes an infinite loop error and a false auto-correction behavior for `Layout/EndAlignment`
when using operator methods and `EnforcedStyleAlignWith: variable`.
This infinite loop error is due to an offense being registered but not auto-corrected.

`EnforcedStyleAlignWith: variable` enforces alignment to variable,
it should be auto-corrected to be aligned to variable even when operator method is used.
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