-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
Description
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.
def nested_if_empty_else(s)
if s.is_a?(Hash)
if s.empty?
puts 'hello'
end
end
end
Actual behavior
An extra end is deleted causing a syntax error
def nested_if_empty_else(s)
if s.is_a?(Hash)
if s.empty?
puts 'hello'
end
end
unexpected token $end
Steps to reproduce the problem
Run the following on this test code
rubocop --only EmptyElse -a test_file.rb
def nested_if_empty_else(s)
if s.is_a?(Hash)
if s.empty?
puts 'hello'
else
end
end
end
RuboCop version
$ rubocop -V
0.49.1 (using Parser 2.4.0.0, running on ruby 2.3.4 x86_64-darwin16)