Invert-Ternary
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery rule id: invert-ternary
Section titled “Sourcery rule id: invert-ternary”Description
Section titled “Description”Invert ternary operator to remove negation
Before
Section titled “Before”const beverage = !too_young ? 'Beer' : 'Juice';const beverage = too_young ? 'Juice': 'Beer';Explanation
Section titled “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.