Why this matters
Simplifies control flow and reduces cognitive load.
Validate and return early to avoid deep nesting.
Simplifies control flow and reduces cognitive load.
Side-by-side examples engineers can pattern-match during review.
if params[:id]
if current_user
process
end
endreturn head :bad_request unless params[:id]
return head :unauthorized unless current_user
processnested ifsreturn unless ...; main pathFrom 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.