@@ -7,6 +7,23 @@ expression: invalid.js
77var thing = foo ? bar : baz === qux ? quxx : foobar;
88
99foo ? baz === qux ? quxx() : foobar() : bar();
10+
11+ var thing1 = foo ? (bar ? 1 : 2) : 3;
12+
13+ var thing2 = foo ? 1 : (bar ? 2 : 3);
14+
15+ var thing3 = foo ? ((bar ? 1 : 2)) : 3;
16+
17+ var thing4 = foo ? 1 : ((bar ? 2 : 3));
18+
19+ var thing5 = foo ? (baz === qux ? quxx : foobar) : bar;
20+
21+ const case1 = val ? (Math.random() ? 1 : 2) : 3;
22+
23+ const case2 = val ? 1 : Math.random() ? 2 : 3;
24+
25+ const case3 = (val ? (Math.random() ? 1 : 2) : 3);
26+
1027` ` `
1128
1229# Diagnostics
@@ -36,6 +53,159 @@ invalid.js:3:7 lint/style/noNestedTernary ━━━━━━━━━━━━
3653 2 │
3754 > 3 │ foo ? baz === qux ? quxx() : foobar() : bar();
3855 │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+ 4 │
57+ 5 │ var thing1 = foo ? (bar ? 1 : 2) : 3;
58+
59+ i Nesting ternary expressions can make code more difficult to understand.
60+
61+ i Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
62+
63+
64+ ` ` `
65+
66+ ` ` `
67+ invalid.js:5:21 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
68+
69+ i Do not nest ternary expressions.
70+
71+ 3 │ foo ? baz === qux ? quxx() : foobar() : bar();
72+ 4 │
73+ > 5 │ var thing1 = foo ? (bar ? 1 : 2) : 3;
74+ │ ^^^^^^^^^^^
75+ 6 │
76+ 7 │ var thing2 = foo ? 1 : (bar ? 2 : 3);
77+
78+ i Nesting ternary expressions can make code more difficult to understand.
79+
80+ i Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
81+
82+
83+ ` ` `
84+
85+ ` ` `
86+ invalid.js:7:25 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
87+
88+ i Do not nest ternary expressions.
89+
90+ 5 │ var thing1 = foo ? (bar ? 1 : 2) : 3;
91+ 6 │
92+ > 7 │ var thing2 = foo ? 1 : (bar ? 2 : 3);
93+ │ ^^^^^^^^^^^
94+ 8 │
95+ 9 │ var thing3 = foo ? ((bar ? 1 : 2)) : 3;
96+
97+ i Nesting ternary expressions can make code more difficult to understand.
98+
99+ i Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
100+
101+
102+ ` ` `
103+
104+ ` ` `
105+ invalid.js:9:22 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
106+
107+ i Do not nest ternary expressions.
108+
109+ 7 │ var thing2 = foo ? 1 : (bar ? 2 : 3);
110+ 8 │
111+ > 9 │ var thing3 = foo ? ((bar ? 1 : 2)) : 3;
112+ │ ^^^^^^^^^^^
113+ 10 │
114+ 11 │ var thing4 = foo ? 1 : ((bar ? 2 : 3));
115+
116+ i Nesting ternary expressions can make code more difficult to understand.
117+
118+ i Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
119+
120+
121+ ` ` `
122+
123+ ` ` `
124+ invalid.js:11:26 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
125+
126+ i Do not nest ternary expressions.
127+
128+ 9 │ var thing3 = foo ? ((bar ? 1 : 2)) : 3;
129+ 10 │
130+ > 11 │ var thing4 = foo ? 1 : ((bar ? 2 : 3));
131+ │ ^^^^^^^^^^^
132+ 12 │
133+ 13 │ var thing5 = foo ? (baz === qux ? quxx : foobar) : bar;
134+
135+ i Nesting ternary expressions can make code more difficult to understand.
136+
137+ i Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
138+
139+
140+ ` ` `
141+
142+ ` ` `
143+ invalid.js:13:21 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
144+
145+ i Do not nest ternary expressions.
146+
147+ 11 │ var thing4 = foo ? 1 : ((bar ? 2 : 3));
148+ 12 │
149+ > 13 │ var thing5 = foo ? (baz === qux ? quxx : foobar) : bar;
150+ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
151+ 14 │
152+ 15 │ const case1 = val ? (Math.random() ? 1 : 2) : 3;
153+
154+ i Nesting ternary expressions can make code more difficult to understand.
155+
156+ i Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
157+
158+
159+ ` ` `
160+
161+ ` ` `
162+ invalid.js:15:22 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
163+
164+ i Do not nest ternary expressions.
165+
166+ 13 │ var thing5 = foo ? (baz === qux ? quxx : foobar) : bar;
167+ 14 │
168+ > 15 │ const case1 = val ? (Math.random() ? 1 : 2) : 3;
169+ │ ^^^^^^^^^^^^^^^^^^^^^
170+ 16 │
171+ 17 │ const case2 = val ? 1 : Math.random() ? 2 : 3;
172+
173+ i Nesting ternary expressions can make code more difficult to understand.
174+
175+ i Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
176+
177+
178+ ` ` `
179+
180+ ` ` `
181+ invalid.js:17:25 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
182+
183+ i Do not nest ternary expressions.
184+
185+ 15 │ const case1 = val ? (Math.random() ? 1 : 2) : 3;
186+ 16 │
187+ > 17 │ const case2 = val ? 1 : Math.random() ? 2 : 3;
188+ │ ^^^^^^^^^^^^^^^^^^^^^
189+ 18 │
190+ 19 │ const case3 = (val ? (Math.random() ? 1 : 2) : 3);
191+
192+ i Nesting ternary expressions can make code more difficult to understand.
193+
194+ i Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
195+
196+
197+ ` ` `
198+
199+ ` ` `
200+ invalid.js:19:23 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
201+
202+ i Do not nest ternary expressions.
203+
204+ 17 │ const case2 = val ? 1 : Math.random() ? 2 : 3;
205+ 18 │
206+ > 19 │ const case3 = (val ? (Math.random() ? 1 : 2) : 3);
207+ │ ^^^^^^^^^^^^^^^^^^^^^
208+ 20 │
39209
40210 i Nesting ternary expressions can make code more difficult to understand.
41211
0 commit comments