mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Fix redundantParens incorrectly removing () from @MainActor closure signatures (#2469)
Co-authored-by: calda <1811727+calda@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user