File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -403,6 +403,11 @@ extension Formatter {
403
403
/// Returns true if the modifiers list for the given declaration contain a
404
404
/// modifier matching the specified predicate
405
405
func modifiersForDeclaration( at index: Int , contains: ( Int , String ) -> Bool ) -> Bool {
406
+ var declarationType : String ?
407
+ if tokens [ index] . isDeclarationTypeKeyword {
408
+ declarationType = tokens [ index] . string
409
+ }
410
+
406
411
var index = index
407
412
while var prevIndex = self . index ( of: . nonSpaceOrCommentOrLinebreak, before: index) {
408
413
switch tokens [ prevIndex] {
@@ -414,6 +419,12 @@ extension Formatter {
414
419
// Part of previous declaration
415
420
return false
416
421
}
422
+
423
+ // Async is only a valid modifier on local let/var declarations.
424
+ if token == . identifier( " async " ) , ![ " let " , " var " ] . contains ( declarationType) {
425
+ return false
426
+ }
427
+
417
428
if contains ( prevIndex, token. string) {
418
429
return true
419
430
}
Original file line number Diff line number Diff line change @@ -304,4 +304,20 @@ class DocCommentsBeforeModifiersTests: XCTestCase {
304
304
305
305
testFormatting ( for: input, rule: . docCommentsBeforeModifiers, exclude: [ . propertyTypes] )
306
306
}
307
+
308
+ func testIssue2216( ) {
309
+ let input = """
310
+ protocol TestIssue2216() {
311
+ /// Documentation comment explaining the function
312
+ /// with multiple lines of explanation
313
+ func method1(value: String) async
314
+
315
+ /// Documentation comment explaining the function
316
+ /// with multiple lines of explanation
317
+ func method2(value: String) async
318
+ }
319
+ """
320
+
321
+ testFormatting ( for: input, rule: . docCommentsBeforeModifiers)
322
+ }
307
323
}
You can’t perform that action at this time.
0 commit comments