Skip to content
Sarj Code Standards

no-adjacent-boolean-parameters

Avoid swap-prone positional boolean parameters.

Why

Callers can reverse two boolean arguments and still type-check. Named fields make each argument's role visible, including when the boolean parameters are separated by other parameters.

Fix

Group independent flags in an options object. Use a literal union with named modes when the flags represent one choice. Update the signature and its callers together.

Examples

Before — flagged Positional flags can be reversed
range.ts
declare function checkRange(
min: number,
excludeMin: boolean,
max: number,
excludeMax: boolean,
): void;
checkRange(1, false, 4, true);
After — preferred Name each flag at the call site
range.ts
declare function checkRange(
min: number,
max: number,
options: { excludeMin: boolean; excludeMax: boolean },
): void;
checkRange(1, 4, { excludeMin: false, excludeMax: true });