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 {
113
113
114
114
/// Returns a value indicating whether the given node is a standalone assignment statement.
115
115
///
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
118
118
/// purposes, even though a `TryExpr` will wrap the `InfixOperatorExpr` and thus would not be
119
119
/// considered a standalone assignment if we only checked the infix expression for a
120
120
/// `CodeBlockItem` parent.
121
121
private func isStandaloneAssignmentStatement( _ node: InfixOperatorExprSyntax ) -> Bool {
122
122
var node = Syntax ( node)
123
123
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 )
125
125
{
126
126
node = parent
127
127
}
Original file line number Diff line number Diff line change @@ -187,19 +187,21 @@ final class NoAssignmentInExpressionsTests: LintOrFormatRuleTestCase {
187
187
)
188
188
}
189
189
190
- func testTryAndAwaitAssignmentExpressionsAreUnchanged ( ) {
190
+ func testTryAndAwaitAndUnsafeAssignmentExpressionsAreUnchanged ( ) {
191
191
assertFormatting (
192
192
NoAssignmentInExpressions . self,
193
193
input: """
194
194
func foo() {
195
195
try a.b = c
196
196
await a.b = c
197
+ unsafe a.b = c
197
198
}
198
199
""" ,
199
200
expected: """
200
201
func foo() {
201
202
try a.b = c
202
203
await a.b = c
204
+ unsafe a.b = c
203
205
}
204
206
""" ,
205
207
findings: [ ]
You can’t perform that action at this time.
0 commit comments