Repository: apple/swift-syntax (swift)

Issue:
Rename `detach()` to `detached`
According to the Swift naming guidelines, `detach()` should be named `detached` because it’s not mutating. Also, I think it should be a computed property instead of a function.

Pull request description:
Resolve #1743 😄

Patch:
diff --git a/Sources/SwiftBasicFormat/BasicFormat.swift b/Sources/SwiftBasicFormat/BasicFormat.swift
index c9e17847a3a..fae1ea20205 100644
--- a/Sources/SwiftBasicFormat/BasicFormat.swift
+++ b/Sources/SwiftBasicFormat/BasicFormat.swift
@@ -437,7 +437,7 @@ open class BasicFormat: SyntaxRewriter {
       return token
     }
 
-    return token.detach().with(\.leadingTrivia, leadingTrivia).with(\.trailingTrivia, trailingTrivia)
+    return token.detached.with(\.leadingTrivia, leadingTrivia).with(\.trailingTrivia, trailingTrivia)
   }
 }
 
diff --git a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift
index bd4f42008e6..3ad3a2e7d6d 100644
--- a/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift
+++ b/Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift
@@ -329,6 +329,13 @@ public extension NamedOpaqueReturnTypeSyntax {
   }
 }
 
+public extension SyntaxProtocol {
+  @available(*, deprecated, message: "Use detached computed property instead.")
+  func detach() -> Self {
+    return detached
+  }
+}
+
 public extension TupleExprSyntax {
   @available(*, deprecated, renamed: "unexpectedBetweenLeftParenAndElements")
   var unexpectedBetweenLeftParenAndElementList: UnexpectedNodesSyntax? {
diff --git a/Sources/SwiftSyntax/Syntax.swift b/Sources/SwiftSyntax/Syntax.swift
index 4c4b3325ed4..acbbd5b93c6 100644
--- a/Sources/SwiftSyntax/Syntax.swift
+++ b/Sources/SwiftSyntax/Syntax.swift
@@ -225,7 +225,7 @@ extension SyntaxProtocol {
 
   /// Return this subtree with this node as the root, ie. detach this node
   /// from its parent.
-  public func detach() -> Self {
+  public var detached: Self {
     return Syntax(raw: self.raw).cast(Self.self)
   }
 
diff --git a/Sources/SwiftSyntaxMacros/BasicMacroExpansionContext.swift b/Sources/SwiftSyntaxMacros/BasicMacroExpansionContext.swift
index e218df6f86d..813486e7cdc 100644
--- a/Sources/SwiftSyntaxMacros/BasicMacroExpansionContext.swift
+++ b/Sources/SwiftSyntaxMacros/BasicMacroExpansionContext.swift
@@ -80,7 +80,7 @@ extension BasicMacroExpansionContext {
 
   /// Detach the given node, and record where it came from.
   public func detach<Node: SyntaxProtocol>(_ node: Node) -> Node {
-    let detached = node.detach()
+    let detached = node.detached
 
     if let rootSourceFile = node.root.as(SourceFileSyntax.self) {
       addDisconnected(detached, at: node.position, in: rootSourceFile)
diff --git a/Sources/SwiftSyntaxMacros/Syntax+MacroEvaluation.swift b/Sources/SwiftSyntaxMacros/Syntax+MacroEvaluation.swift
index e7fe77a9b13..c593404a8ef 100644
--- a/Sources/SwiftSyntaxMacros/Syntax+MacroEvaluation.swift
+++ b/Sources/SwiftSyntaxMacros/Syntax+MacroEvaluation.swift
@@ -21,7 +21,7 @@ extension SyntaxProtocol {
       return basicContext.detach(self)
     }
 
-    return self.detach()
+    return self.detached
   }
 }
 


Test patch:
diff --git a/Tests/SwiftSyntaxTest/SyntaxTests.swift b/Tests/SwiftSyntaxTest/SyntaxTests.swift
index f1ab22e4b02..207394745fc 100644
--- a/Tests/SwiftSyntaxTest/SyntaxTests.swift
+++ b/Tests/SwiftSyntaxTest/SyntaxTests.swift
@@ -38,7 +38,7 @@ public class SyntaxTests: XCTestCase {
     )
   }
 
-  public func testDetach() {
+  public func testDetached() {
     let s = StructDeclSyntax(
       structKeyword: .keyword(.struct),
       identifier: .identifier("someStruct"),
@@ -46,7 +46,7 @@ public class SyntaxTests: XCTestCase {
     )
 
     XCTAssertEqual(Syntax(s), s.memberBlock.parent)
-    XCTAssertNil(s.memberBlock.detach().parent)
+    XCTAssertNil(s.memberBlock.detached.parent)
   }
 
   public func testCasting() {