π Disallow nested ternary expressions.
πΌπ« This rule is enabled in the β
recommended config. This rule is disabled in the βοΈ unopinionated config.
π§ This rule is automatically fixable by the --fix CLI option.
Improved version of the no-nested-ternary ESLint rule. This rule allows cases where the nested ternary is only one level and wrapped in parens.
// β
const foo = i > 5 ? i < 100 ? true : false : true;
// β
const foo = i > 5 ? (i < 100 ? true : false) : true;// β
const foo = i > 5 ? true : (i < 100 ? true : (i < 1000 ? true : false));// β
const foo = i > 5 ? (i < 100 ? true : false) : (i < 100 ? true : false);This rule is only fixable when the nesting is up to one level. The rule will wrap the nested ternary in parens:
const foo = i > 5 ? i < 100 ? true : false : truewill get fixed to
const foo = i > 5 ? (i < 100 ? true : false) : trueWe recommend disabling the ESLint no-nested-ternary rule in favor of this one:
{
"rules": {
"no-nested-ternary": "off"
}
}The recommended preset that comes with this plugin already does this for you.