Why this matters
When an `if` statement has multiple `elsif` branches, it should always end with an `else` clause. This ensures all possible cases are handled, preventing unintended behavior.
Verify that all `if...elsif` constructs include a final `else` clause. If `else` is missing, ensure there is a comment explaining why all cases are covered.
When an `if` statement has multiple `elsif` branches, it should always end with an `else` clause. This ensures all possible cases are handled, preventing unintended behavior.
Side-by-side examples engineers can pattern-match during review.
if x == 0
doSomething
elsif x == 1
doSomethingElse
endif x == 0
doSomething
elsif x == 1
doSomethingElse
else
raise 'An error has occured'
endif x == 0
doSomething
elsif x == 1
doSomethingElse
endif x == 0
doSomething
elsif x == 1
doSomethingElse
else
raise 'An error has occured'
endFrom the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.