Invert-Ternary¶
Sourcery rule id: invert-ternary
¶
Description¶
Invert ternary operator to remove negation
Before¶
const beverage = !too_young ? 'Beer' : 'Juice';
After¶
const beverage = too_young ? 'Juice': 'Beer';
Explanation¶
Negated conditions are more difficult to read than positive ones, so it is best to avoid them where we can. By inverting the ternary condition and swapping the expressions we can simplify the code.