mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Update docComments rule to handle conditional compilation blocks in function bodies (#2343)
This commit is contained in:
@@ -175,21 +175,8 @@ extension Formatter {
|
||||
}
|
||||
|
||||
// For local declarations other than nested functions, use standard comments.
|
||||
if declarationToken != .keyword("func"),
|
||||
let startOfEnclosingScope = index(of: .startOfScope, before: startIndex)
|
||||
{
|
||||
switch tokens[startOfEnclosingScope] {
|
||||
case .startOfScope("#if"):
|
||||
break
|
||||
case .startOfScope("{"):
|
||||
guard let scope = lastSignificantKeyword(at: startOfEnclosingScope, excluding: ["where"]),
|
||||
["class", "actor", "struct", "enum", "protocol", "extension"].contains(scope)
|
||||
else {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
if declarationToken != .keyword("func"), declarationScope(at: startIndex) == .local {
|
||||
return false
|
||||
}
|
||||
|
||||
// If there are blank lines between comment and declaration, comment is not treated as doc comment
|
||||
|
||||
@@ -115,6 +115,11 @@ final class DocCommentsTests: XCTestCase {
|
||||
/// an entire following block of code (not just the property)
|
||||
let bar: Bar? = Bar()
|
||||
print(bar)
|
||||
|
||||
#if DEBUG
|
||||
/// This comment is in a conditional compilation block
|
||||
let baaz = Baaz()
|
||||
#endif
|
||||
}
|
||||
|
||||
var baaz: Baaz {
|
||||
@@ -150,6 +155,11 @@ final class DocCommentsTests: XCTestCase {
|
||||
// an entire following block of code (not just the property)
|
||||
let bar: Bar? = Bar()
|
||||
print(bar)
|
||||
|
||||
#if DEBUG
|
||||
// This comment is in a conditional compilation block
|
||||
let baaz = Baaz()
|
||||
#endif
|
||||
}
|
||||
|
||||
var baaz: Baaz {
|
||||
|
||||
Reference in New Issue
Block a user