Skip to content

Commit 1a078b9

Browse files
authored
Update: check ternary : even if ? was reported in space-infix-ops (#13963)
1 parent fb27422 commit 1a078b9

2 files changed

Lines changed: 66 additions & 10 deletions

File tree

lib/rules/space-infix-ops.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ module.exports = {
132132

133133
if (nonSpacedConsequentNode) {
134134
report(node, nonSpacedConsequentNode);
135-
} else if (nonSpacedAlternateNode) {
135+
}
136+
137+
if (nonSpacedAlternateNode) {
136138
report(node, nonSpacedAlternateNode);
137139
}
138140
}

tests/lib/rules/space-infix-ops.js

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,69 @@ ruleTester.run("space-infix-ops", rule, {
161161
},
162162
{
163163
code: "a?b:c",
164-
output: "a ? b:c",
165-
errors: [{
166-
messageId: "missingSpace",
167-
data: { operator: "?" },
168-
type: "ConditionalExpression",
169-
line: 1,
170-
column: 2,
171-
endColumn: 3
172-
}]
164+
output: "a ? b : c",
165+
errors: [
166+
{
167+
messageId: "missingSpace",
168+
data: { operator: "?" },
169+
type: "ConditionalExpression",
170+
line: 1,
171+
column: 2,
172+
endColumn: 3
173+
},
174+
{
175+
messageId: "missingSpace",
176+
data: { operator: ":" },
177+
type: "ConditionalExpression",
178+
line: 1,
179+
column: 4,
180+
endColumn: 5
181+
}
182+
]
183+
},
184+
{
185+
code: "a? b :c",
186+
output: "a ? b : c",
187+
errors: [
188+
{
189+
messageId: "missingSpace",
190+
data: { operator: "?" },
191+
type: "ConditionalExpression",
192+
line: 1,
193+
column: 2,
194+
endColumn: 3
195+
},
196+
{
197+
messageId: "missingSpace",
198+
data: { operator: ":" },
199+
type: "ConditionalExpression",
200+
line: 1,
201+
column: 6,
202+
endColumn: 7
203+
}
204+
]
205+
},
206+
{
207+
code: "a ?b: c",
208+
output: "a ? b : c",
209+
errors: [
210+
{
211+
messageId: "missingSpace",
212+
data: { operator: "?" },
213+
type: "ConditionalExpression",
214+
line: 1,
215+
column: 3,
216+
endColumn: 4
217+
},
218+
{
219+
messageId: "missingSpace",
220+
data: { operator: ":" },
221+
type: "ConditionalExpression",
222+
line: 1,
223+
column: 5,
224+
endColumn: 6
225+
}
226+
]
173227
},
174228
{
175229
code: "a?b : c",

0 commit comments

Comments
 (0)