Ternary operator should not be used to select between two boolean values, or instead of a logical OR
operation. Ternary expressions
are often difficult to read, so if a simpler syntax exists, it should be used instead of a ternary expression. This happens when
- the expression returns two boolean values
let isGood = value > 0 ? true : false; // Non-compliant, replace with value > 0
let isBad = value > 0 ? false : true; // Non-compliant, replace with !(value > 0)
- the same value is used for both the conditional test and the consequent
let a = x ? x : y; // Non-compliant, replace with x || y