@@ -33,13 +33,16 @@ public extension FormatRule {
33
33
let startOfScope = formatter. startOfScope ( at: i) ,
34
34
let identifierBeforeStartOfScope = formatter. index ( of: . nonSpaceOrCommentOrLinebreak, before: startOfScope) ,
35
35
let identifierToken = formatter. token ( at: identifierBeforeStartOfScope) ,
36
- identifierToken. isIdentifier || identifierToken. isAttribute || ( identifierToken. isKeyword && identifierToken. string. hasPrefix ( " # " ) )
36
+ identifierToken. isIdentifier || identifierToken. isAttribute || ( identifierToken. isKeyword && identifierToken. string. hasPrefix ( " # " ) ) ,
37
+ // If the case of `@escaping` or `@Sendable`, this could be a closure type where trailing commas are not supported.
38
+ !formatter. isStartOfClosureType ( at: startOfScope)
37
39
{
38
40
// In Swift 6.1, built-in attributes unexpectedly don't support trailing commas.
39
41
// Other attributes like property wrappers and macros do support trailing commas.
40
42
// https://github.com/swiftlang/swift/issues/81475
41
43
// https://docs.swift.org/swift-book/documentation/the-swift-programming-language/attributes/
42
- let unsupportedBuiltInAttributes = [ " @available " , " @backDeployed " , " @objc " , " @freestanding " , " @attached " ]
44
+ // Some attributes like `@objc`, `@inline` that have parens but not comma-separated lists don't support trailing commas.
45
+ let unsupportedBuiltInAttributes = [ " @available " , " @backDeployed " , " @freestanding " , " @attached " , " @objc " , " @inline " ]
43
46
if identifierToken. isAttribute, unsupportedBuiltInAttributes. contains ( identifierToken. string)
44
47
|| identifierToken. string. hasPrefix ( " @_ " )
45
48
{
@@ -78,7 +81,7 @@ public extension FormatRule {
78
81
case . endOfScope( " > " ) :
79
82
var trailingCommaSupported = false
80
83
81
- // In Swift 6.1, only generic lists in type / function / typealias declarations are allowed.
84
+ // In Swift 6.1, only generic lists in concrete type / function / typealias declarations are allowed.
82
85
// https://github.com/swiftlang/swift/issues/81474
83
86
// All of these cases have the form `keyword identifier<...>`, like `class Foo<...>` or `func foo<...>`.
84
87
if formatter. options. swiftVersion >= " 6.1 " ,
@@ -88,7 +91,7 @@ public extension FormatRule {
88
91
let keywordIndex = formatter. index ( of: . nonSpaceOrCommentOrLinebreak, before: identifierIndex) ,
89
92
let keyword = formatter. token ( at: keywordIndex) ,
90
93
keyword. isKeyword,
91
- [ " class " , " actor " , " struct " , " enum " , " protocol " , " typealias " , " func " ] . contains ( keyword. string)
94
+ [ " class " , " actor " , " struct " , " enum " , " typealias " , " func " ] . contains ( keyword. string)
92
95
{
93
96
trailingCommaSupported = true
94
97
}
0 commit comments