@@ -263,6 +263,77 @@ final class NoParensAroundConditionsTests: LintOrFormatRuleTestCase {
263
263
FindingSpec ( " 7️⃣ " , message: " remove the parentheses around this expression " ) ,
264
264
]
265
265
)
266
+ }
266
267
268
+ func testBlockCommentsBeforeConditionArePreserved( ) {
269
+ assertFormatting (
270
+ NoParensAroundConditions . self,
271
+ input: """
272
+ if/*foo*/1️⃣(x) {}
273
+ while/*foo*/2️⃣(x) {}
274
+ guard/*foo*/3️⃣(x), /*foo*/4️⃣(y), /*foo*/5️⃣(x == 3) else {}
275
+ repeat {} while/*foo*/6️⃣(x)
276
+ switch/*foo*/7️⃣(4) { default: break }
277
+ """ ,
278
+ expected: """
279
+ if/*foo*/x {}
280
+ while/*foo*/x {}
281
+ guard/*foo*/x, /*foo*/y, /*foo*/x == 3 else {}
282
+ repeat {} while/*foo*/x
283
+ switch/*foo*/4 { default: break }
284
+ """ ,
285
+ findings: [
286
+ FindingSpec ( " 1️⃣ " , message: " remove the parentheses around this expression " ) ,
287
+ FindingSpec ( " 2️⃣ " , message: " remove the parentheses around this expression " ) ,
288
+ FindingSpec ( " 3️⃣ " , message: " remove the parentheses around this expression " ) ,
289
+ FindingSpec ( " 4️⃣ " , message: " remove the parentheses around this expression " ) ,
290
+ FindingSpec ( " 5️⃣ " , message: " remove the parentheses around this expression " ) ,
291
+ FindingSpec ( " 6️⃣ " , message: " remove the parentheses around this expression " ) ,
292
+ FindingSpec ( " 7️⃣ " , message: " remove the parentheses around this expression " ) ,
293
+ ]
294
+ )
295
+ }
296
+
297
+ func testCommentsAfterKeywordArePreserved( ) {
298
+ assertFormatting (
299
+ NoParensAroundConditions . self,
300
+ input: """
301
+ if /*foo*/ // bar
302
+ 1️⃣(x) {}
303
+ while /*foo*/ // bar
304
+ 2️⃣(x) {}
305
+ guard /*foo*/ // bar
306
+ 3️⃣(x), /*foo*/ // bar
307
+ 4️⃣(y), /*foo*/ // bar
308
+ 5️⃣(x == 3) else {}
309
+ repeat {} while /*foo*/ // bar
310
+ 6️⃣(x)
311
+ switch /*foo*/ // bar
312
+ 7️⃣(4) { default: break }
313
+ """ ,
314
+ expected: """
315
+ if /*foo*/ // bar
316
+ x {}
317
+ while /*foo*/ // bar
318
+ x {}
319
+ guard /*foo*/ // bar
320
+ x, /*foo*/ // bar
321
+ y, /*foo*/ // bar
322
+ x == 3 else {}
323
+ repeat {} while /*foo*/ // bar
324
+ x
325
+ switch /*foo*/ // bar
326
+ 4 { default: break }
327
+ """ ,
328
+ findings: [
329
+ FindingSpec ( " 1️⃣ " , message: " remove the parentheses around this expression " ) ,
330
+ FindingSpec ( " 2️⃣ " , message: " remove the parentheses around this expression " ) ,
331
+ FindingSpec ( " 3️⃣ " , message: " remove the parentheses around this expression " ) ,
332
+ FindingSpec ( " 4️⃣ " , message: " remove the parentheses around this expression " ) ,
333
+ FindingSpec ( " 5️⃣ " , message: " remove the parentheses around this expression " ) ,
334
+ FindingSpec ( " 6️⃣ " , message: " remove the parentheses around this expression " ) ,
335
+ FindingSpec ( " 7️⃣ " , message: " remove the parentheses around this expression " ) ,
336
+ ]
337
+ )
267
338
}
268
339
}
0 commit comments