File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed
Sources/SwiftFormat/Rules
Tests/SwiftFormatTests/Rules Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -113,15 +113,15 @@ public final class NoAssignmentInExpressions: SyntaxFormatRule {
113113
114114 /// Returns a value indicating whether the given node is a standalone assignment statement.
115115 ///
116- /// This function considers try/await expressions and automatically walks up through them as
117- /// needed. This is because `try f().x = y` should still be a standalone assignment for our
116+ /// This function considers try/await/unsafe expressions and automatically walks up through them
117+ /// as needed. This is because `try f().x = y` should still be a standalone assignment for our
118118 /// purposes, even though a `TryExpr` will wrap the `InfixOperatorExpr` and thus would not be
119119 /// considered a standalone assignment if we only checked the infix expression for a
120120 /// `CodeBlockItem` parent.
121121 private func isStandaloneAssignmentStatement( _ node: InfixOperatorExprSyntax ) -> Bool {
122122 var node = Syntax ( node)
123123 while let parent = node. parent,
124- parent. is ( TryExprSyntax . self) || parent. is ( AwaitExprSyntax . self)
124+ parent. is ( TryExprSyntax . self) || parent. is ( AwaitExprSyntax . self) || parent . is ( UnsafeExprSyntax . self )
125125 {
126126 node = parent
127127 }
Original file line number Diff line number Diff line change @@ -187,19 +187,21 @@ final class NoAssignmentInExpressionsTests: LintOrFormatRuleTestCase {
187187 )
188188 }
189189
190- func testTryAndAwaitAssignmentExpressionsAreUnchanged ( ) {
190+ func testTryAndAwaitAndUnsafeAssignmentExpressionsAreUnchanged ( ) {
191191 assertFormatting (
192192 NoAssignmentInExpressions . self,
193193 input: """
194194 func foo() {
195195 try a.b = c
196196 await a.b = c
197+ unsafe a.b = c
197198 }
198199 """ ,
199200 expected: """
200201 func foo() {
201202 try a.b = c
202203 await a.b = c
204+ unsafe a.b = c
203205 }
204206 """ ,
205207 findings: [ ]
You can’t perform that action at this time.
0 commit comments