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
The most recent version of RuboCop as well as current git master trigger this GuardClause errors for my if/elsif/else branches. Example file:
def process_file file
if file.video?
puts file.video_info
elsif file.image?
puts file.image_info
else
raise "unsupported file type"
end
puts file.general_info
end
Output:
asd.rb:4:3: C: Use a guard clause instead of wrapping the code inside a conditional expression.
elsif file.image?
^^^^^
I think it doesn't make sense. The guard condition would have to be very complex, the more complex the more elsif clauses there are. Below is – in my opinion – worse code that Rubocop likes:
def process_file file
raise "unsupported file type" unless file.video? || file.image?
if file.video?
puts file.video_info
elsif file.image?
puts file.image_info
end
puts file.general_info
end
If this looks OK to you then consider the same example, but with 5 elsif checks.
The text was updated successfully, but these errors were encountered:
def process_file file
case
when file.video?
puts file.video_info
when file.image?
puts file.image_info
else
raise "unsupported file type"
end
puts file.general_info
end
The most recent version of RuboCop as well as current git master trigger this GuardClause errors for my if/elsif/else branches. Example file:
Output:
I think it doesn't make sense. The guard condition would have to be very complex, the more complex the more
elsif
clauses there are. Below is – in my opinion – worse code that Rubocop likes:If this looks OK to you then consider the same example, but with 5
elsif
checks.The text was updated successfully, but these errors were encountered: