You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running autocorrect on nested if statements can cause a syntax error if there's an if block with an empty else. Seems to be deleting one extra end statement. I just fixed it manually in our code, but autocorrect shouldn't introduce syntax errors if possible.
…nested `if`
See rubocop#4491.
Reproduce
======
```ruby
if cond
if cond2
some
else
end
end
```
```bash
$ rubocop -a --only EmptyElse
Inspecting 1 file
E
Offenses:
test.rb:4:3: C: [Corrected] Redundant else-clause.
else
^^^^
test.rb:5:1: E: unexpected token $end
(Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
1 file inspected, 2 offenses detected, 1 offense corrected
$ cat test.rb
if cond
if cond2
some
end
```
This change fixes the bug.
Running autocorrect on nested if statements can cause a syntax error if there's an if block with an empty else. Seems to be deleting one extra end statement. I just fixed it manually in our code, but autocorrect shouldn't introduce syntax errors if possible.
Expected behavior
Deletes only the else and empty line.
Actual behavior
An extra end is deleted causing a syntax error
unexpected token $end
Steps to reproduce the problem
Run the following on this test code
rubocop --only EmptyElse -a test_file.rb
RuboCop version
The text was updated successfully, but these errors were encountered: