diff options
Diffstat (limited to 'tools/eslint/lib/rules/no-nested-ternary.js')
-rw-r--r-- | tools/eslint/lib/rules/no-nested-ternary.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/eslint/lib/rules/no-nested-ternary.js b/tools/eslint/lib/rules/no-nested-ternary.js new file mode 100644 index 00000000000..10b0683f952 --- /dev/null +++ b/tools/eslint/lib/rules/no-nested-ternary.js @@ -0,0 +1,22 @@ +/** + * @fileoverview Rule to flag nested ternary expressions + * @author Ian Christian Myers + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = function(context) { + + return { + "ConditionalExpression": function(node) { + if (node.alternate.type === "ConditionalExpression" || + node.consequent.type === "ConditionalExpression") { + context.report(node, "Do not nest ternary expressions"); + } + } + }; +}; |