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
AllowComments works for if/unless blocks only when there is no elsif/else and code after the block ends at the same nesting level. AllowComments always works of elsif` blocks
Steps to reproduce the problem
Based on documentation all of these should be allowed when AllowComments: true
test code:
module Something
def method1(foobar, barfoo)
puts 'lets do something'
if foobar # 1
puts 'testing the conditional'
end
unless barfoo # 1
# no error
end
puts 'foobar'
end
def method2(foobar, barfoo)
puts 'lets do something'
if foobar # 2
puts 'testing the conditional'
end
unless barfoo # 2
# issue found!
end
#puts 'foobar'
end
def method3(foobar, barfoo)
puts 'lets do something'
if foobar # 3
# no error
end
unless barfoo # 3
# issue found!
end
end
def method4(foobar)
puts 'lets do something'
if foobar # 4
# no error
end
puts 'foobar'
end
def method5(foobar)
puts 'lets do something'
if foobar # 5
# issue found!
end
end
def method6(foobar, barfoo)
puts 'lets do something'
if foobar # 6
# no error
elsif barfoo # 6
# no error
end
end
def method7(foobar)
puts 'lets do something'
if foobar # 7
# no error
else # 7
puts 'hello'
end
end
def method8(foobar, barfoo)
puts 'lets do something'
if foobar # 8
puts 'foobar'
if barfoo # 8
# issue found!
end
end
puts 'hello'
end
def method9(foobar, barfoo)
puts 'lets do something'
if foobar # 9
puts 'foobar'
if barfoo # 9
# no error
end
puts 'hello'
end
end
end
Expected behavior
As documented here: https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/EmptyConditionalBody
Checks for the presence of ‘if`, `elsif` and `unless` branches without a body.
Expect
AllowComments
to work for bothif/unless
andelsif
blocksActual behavior
AllowComments
works forif/unless
blocks only when there is noelsif/else
and code after the block ends at the same nesting level.AllowComments always works of
elsif` blocksSteps to reproduce the problem
Based on documentation all of these should be allowed when
AllowComments: true
test code:
test config:
test command and output:
There may be more weird edge cases, but this is as far down this rabbit-hole as I choose to go for now.
RuboCop version
The text was updated successfully, but these errors were encountered: