Pattern: Negated condition in control flow
Issue: -
Using negated conditions makes code harder to understand. Improve readability by inverting the condition and swapping the consequent and alternate branches.
Example of incorrect code:
if (!a) {
doSomethingC();
} else {
doSomethingB();
}
!a ? doSomethingC() : doSomethingB();
Example of correct code:
if (a) {
doSomethingB();
} else {
doSomethingC();
}
a ? doSomethingB() : doSomethingC();