Fix redundantParens incorrectly removing () from @MainActor closure signatures (#2469)

Co-authored-by: calda <1811727+calda@users.noreply.github.com>
This commit is contained in:
Copilot
2026-03-19 13:52:24 -07:00
committed by Cal Stephens
parent ebcb440df9
commit e913427cab
2 changed files with 30 additions and 1 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ public extension FormatRule {
default:
break
}
if prevToken.isAttribute,
if prevToken.isAttribute, !isClosure,
formatter.index(of: .nonSpaceOrCommentOrLinebreak, after: i) == closingIndex
{
formatter.removeParen(at: closingIndex)
+29
View File
@@ -958,6 +958,35 @@ final class RedundantParensTests: XCTestCase {
testFormatting(for: input, rule: .redundantParens)
}
func testMainActorEmptyParensWithReturnTypeNotUnwrapped() {
let input = """
{ @MainActor () -> Bool in
false
}
"""
testFormatting(for: input, rule: .redundantParens)
}
func testMainActorEmptyParensWithReturnTypeNotUnwrappedInTask() {
let input = """
func someFunction() async -> Bool {
await Task { @MainActor () -> Bool in
false
}.value
}
"""
testFormatting(for: input, rule: .redundantParens)
}
func testMainActorEmptyParensWithThrowsNotUnwrapped() {
let input = """
{ @MainActor () throws -> Bool in
false
}
"""
testFormatting(for: input, rule: .redundantParens)
}
func testClosureArgsContainingSelfNotUnwrapped() {
let input = """
{ (self) in self }