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 || in their original order under one guard.

Examples

Before — flagged Adjacent guards return the same value
src/select.ts
export function select(closed: boolean, items: string[]) {
if (closed) return null;
if (items.length === 0) return null;
return items[0];
}
After — preferred One guard owns the shared exit
src/select.ts
export function select(closed: boolean, items: string[]) {
if (closed || items.length === 0) return null;
return items[0];
}
Autofix output
src/select.ts
export function select(closed: boolean, items: string[]) {
if (closed || items.length === 0) return null;
return items[0];
}