UNPKG

889 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag nested ternary expressions
3 * @author Ian Christian Myers
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12module.exports = {
13 meta: {
14 docs: {
15 description: "disallow nested ternary expressions",
16 category: "Stylistic Issues",
17 recommended: false
18 },
19
20 schema: []
21 },
22
23 create(context) {
24
25 return {
26 ConditionalExpression(node) {
27 if (node.alternate.type === "ConditionalExpression" ||
28 node.consequent.type === "ConditionalExpression") {
29 context.report({ node, message: "Do not nest ternary expressions." });
30 }
31 }
32 };
33 }
34};