Why this matters
Deeply nested conditionals make code hard to follow. Using guard clauses (`return` early) improves clarity and reduces indentation depth.
Detect deeply nested conditionals and suggest using guard clauses (`return unless condition`) instead to improve readability.
Deeply nested conditionals make code hard to follow. Using guard clauses (`return` early) improves clarity and reduces indentation depth.
Side-by-side examples engineers can pattern-match during review.
def process(input)
if input.is_a?(String)
if !input.empty?
return input.strip.upcase
end
end
nil
enddef process(input)
return unless input.is_a?(String)
return if input.empty?
input.strip.upcase
end
def process(input)
if input.is_a?(String)
if !input.empty?
return input.strip.upcase
end
end
nil
enddef process(input)
return unless input.is_a?(String)
return if input.empty?
input.strip.upcase
end
From the same buckets as this rule.