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

Auto-fix with empty else in case statement causes infinite loop ("Layout/IndentationWidth -> Layout/ElseAlignment") #10963

Closed
MarcPer opened this issue Aug 25, 2022 · 0 comments · Fixed by #10964
Labels

Comments

@MarcPer
Copy link

MarcPer commented Aug 25, 2022

Attempting auto-fix (rubocop -a) on a file with case statement using in (pattern matching) and an empty else clause causes an infinite loop.


Expected behavior

There shouldn't be an infinite loop. The empty else clause should be allowed.

Actual behavior

The two following offenses are detected, and the auto-correction for one contradicts the other:

Offenses:

test.rb:5:5: C: [Corrected] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
    else
    
test.rb:5:7: C: [Corrected] Layout/ElseAlignment: Align else with in.
      else
      ^^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in <path>/test.rb and caused by Layout/IndentationWidth -> Layout/ElseAlignment

Steps to reproduce the problem

  • Create a test.rb file with the following content:
x = 1
case x
in [:x, _] then puts ":x"
else
end
  • Run rubocop -a test.rb.

RuboCop version

$ rubocop -V
1.35.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.1.2 arm64-darwin21)
  - rubocop-performance 1.14.3```
@koic koic added the bug label Aug 25, 2022
koic added a commit to koic/rubocop that referenced this issue Aug 25, 2022
Fixes rubocop#10963.

This PR fixes a false positive for `Layout/IndentationWidth`
when using aligned empty `else` in pattern matching.
koic added a commit that referenced this issue Aug 26, 2022
…ndentation_width

[Fix #10963] Fix a false positive for `Layout/IndentationWidth`
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