Skip to content
Sarj Code Standards

merge-converging-adjacent-guards

Adjacent if statements end in the same exit.

Why

Back-to-back guards that run the same exiting body are one decision split across branches; each copy must be kept in sync without changing behavior.

Fix

Join the conditions with or in their original order under one guard.

Examples

Before — flagged Adjacent guards return the same value
app/service.py
def select(closed, messages):
if closed:
return None
if not messages:
return None
return messages[0]
After — preferred One guard owns the shared exit
app/service.py
def select(closed, messages):
if closed or not messages:
return None
return messages[0]