mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Fix redundantSendable incorrectly removing Sendable from types inside public extension (#2423)
Co-authored-by: calda <1811727+calda@users.noreply.github.com>
This commit is contained in:
@@ -21,8 +21,16 @@ public extension FormatRule {
|
||||
switch typeDeclaration.visibility() {
|
||||
case .public, .open:
|
||||
return
|
||||
case .internal, .package, .fileprivate, .private, nil:
|
||||
case .internal, .package, .fileprivate, .private:
|
||||
break
|
||||
case nil:
|
||||
// A type with no explicit access modifier inside a public extension is effectively public
|
||||
let isInPublicExtension = typeDeclaration.parentDeclarations.last.map {
|
||||
$0.keyword == "extension" && $0.visibility() == .public
|
||||
} ?? false
|
||||
if isInPublicExtension {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
guard let sendableConformance = typeDeclaration.conformances.first(where: {
|
||||
|
||||
@@ -93,6 +93,39 @@ final class RedundantSendableTests: XCTestCase {
|
||||
testFormatting(for: input, [output], rules: [.redundantSendable])
|
||||
}
|
||||
|
||||
func testDoesNotRemoveSendableFromTypeInsidePublicExtension() {
|
||||
let input = """
|
||||
public struct OuterStruct {}
|
||||
|
||||
public extension OuterStruct {
|
||||
struct InnerStruct: Sendable {}
|
||||
enum InnerEnum: Sendable {}
|
||||
}
|
||||
"""
|
||||
|
||||
testFormatting(for: input, rules: [.redundantSendable])
|
||||
}
|
||||
|
||||
func testRemovesSendableFromTypeInsideInternalExtension() {
|
||||
let input = """
|
||||
struct OuterStruct {}
|
||||
|
||||
extension OuterStruct {
|
||||
struct InnerStruct: Sendable {}
|
||||
}
|
||||
"""
|
||||
|
||||
let output = """
|
||||
struct OuterStruct {}
|
||||
|
||||
extension OuterStruct {
|
||||
struct InnerStruct {}
|
||||
}
|
||||
"""
|
||||
|
||||
testFormatting(for: input, [output], rules: [.redundantSendable])
|
||||
}
|
||||
|
||||
func testRemovesSendableFromPackageValueTypes() {
|
||||
let input = """
|
||||
package struct PackageStruct: Sendable {
|
||||
|
||||
Reference in New Issue
Block a user