Skip to content
Sarj Code Standards

no-boolean-selector-parameter

Prefer intention-revealing operations over a boolean parameter selecting between actions.

Why

A positional boolean hides which operation a caller requests. Splitting independent actions can make that intent explicit, while boolean data, pure mappings and externally required callback or method contracts remain valid.

Fix

Consider separate named operations or an explicit domain mode. Review the public API and its callers manually; preserve required callback, setter and inherited contracts instead of wrapping them solely to silence the warning.

Examples

Before — flagged Name the selected operation explicitly
src/book.ts
const book = (premium: boolean) => (premium ? premiumBook() : regularBook());
After — preferred Boolean data may select a pure value
src/label.ts
function label(enabled: boolean) {
if (enabled) {
return "Enabled";
} else {
return "Disabled";
}
}

References