diff --git a/Sources/Rules/HoistTry.swift b/Sources/Rules/HoistTry.swift index 1a911cb3..96be0432 100644 --- a/Sources/Rules/HoistTry.swift +++ b/Sources/Rules/HoistTry.swift @@ -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 diff --git a/Tests/Rules/HoistTryTests.swift b/Tests/Rules/HoistTryTests.swift index f1d3a387..824eac48 100644 --- a/Tests/Rules/HoistTryTests.swift +++ b/Tests/Rules/HoistTryTests.swift @@ -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())