1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.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 | messages: {
|
26 | noNestedTernary: "Do not nest ternary expressions."
|
27 | }
|
28 | },
|
29 |
|
30 | create(context) {
|
31 |
|
32 | return {
|
33 | ConditionalExpression(node) {
|
34 | if (node.alternate.type === "ConditionalExpression" ||
|
35 | node.consequent.type === "ConditionalExpression") {
|
36 | context.report({
|
37 | node,
|
38 | messageId: "noNestedTernary"
|
39 | });
|
40 | }
|
41 | }
|
42 | };
|
43 | }
|
44 | };
|