Fix hoistTry with XCTUnwrap

This commit is contained in:
Nick Lockwood
2025-10-16 07:55:45 +01:00
parent ad4b6b92d9
commit 76fbc14e7d
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ public extension FormatRule {
help: "Move inline `try` keyword(s) to start of expression.",
options: ["throw-capturing"]
) { formatter in
let names = formatter.options.throwCapturing.union(["expect"])
let names = formatter.options.throwCapturing.union(["expect", "XCTUnwrap"])
formatter.forEachToken(where: {
$0 == .startOfScope("(") || $0 == .startOfScope("[")
}) { i, _ in
+7
View File
@@ -131,6 +131,13 @@ final class HoistTryTests: XCTestCase {
testFormatting(for: input, rule: .hoistTry)
}
func testNoHoistTryInsideXCTUnwrap() {
let input = """
let foo = try XCTUnwrap(try expression() as? Bar, message, file: file, line: line)
"""
testFormatting(for: input, rule: .hoistTry)
}
func testNoMergeTrysInsideXCTAssert() {
let input = """
XCTAssertEqual(try foo(), try bar())