blob: 87a11e87962a8f6152d0f314b70388b945f88458 [file] [log] [blame]
Yang Guo4fd355c2019-09-19 10:59:03 +02001/**
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 type: "suggestion",
15
16 docs: {
17 description: "disallow nested ternary expressions",
18 category: "Stylistic Issues",
19 recommended: false,
20 url: "https://eslint.org/docs/rules/no-nested-ternary"
21 },
22
23 schema: []
24 },
25
26 create(context) {
27
28 return {
29 ConditionalExpression(node) {
30 if (node.alternate.type === "ConditionalExpression" ||
31 node.consequent.type === "ConditionalExpression") {
32 context.report({ node, message: "Do not nest ternary expressions." });
33 }
34 }
35 };
36 }
37};