diff --git a/CODEOWNERS b/CODEOWNERS index a8142cf6a..f5bc2420d 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -8,7 +8,7 @@ # See https://swift.org/CONTRIBUTORS.txt for Swift project authors # -* @allevato @bnbarham @shawnhyam +* @allevato @bnbarham @hamishknight @rintaro .github/ @bnbarham @shahmishal .swiftci/ @bnbarham @shahmishal diff --git a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift index 966ccc399..2a08bb15c 100644 --- a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift +++ b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift @@ -2737,6 +2737,13 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor { return .visitChildren } + override func visit(_ node: BorrowExprSyntax) -> SyntaxVisitorContinueKind { + // The `borrow` keyword cannot be separated from the following token or it will be parsed as + // an identifier. + after(node.borrowKeyword, tokens: .space) + return .visitChildren + } + override func visit(_ node: ConsumeExprSyntax) -> SyntaxVisitorContinueKind { // The `consume` keyword cannot be separated from the following token or it will be parsed as // an identifier. diff --git a/Tests/SwiftFormatTests/PrettyPrint/BorrowExprTests.swift b/Tests/SwiftFormatTests/PrettyPrint/BorrowExprTests.swift new file mode 100644 index 000000000..1113a7105 --- /dev/null +++ b/Tests/SwiftFormatTests/PrettyPrint/BorrowExprTests.swift @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +final class BorrowExprTests: PrettyPrintTestCase { + func testBorrow() { + assertPrettyPrintEqual( + input: """ + @lifetime(borrow self) + init() {} + """, + expected: """ + @lifetime( + borrow self) + init() {} + + """, + linelength: 21 + ) + } +}