Skip to content

Commit 2a8349e

Browse files
authored
Merge pull request #1022 from swiftlang/automerge/merge-main-2025-05-19_09-01
Merge `main` into `release/6.2`
2 parents b1858e8 + 009925c commit 2a8349e

File tree

6 files changed

+48
-14
lines changed

6 files changed

+48
-14
lines changed

.github/workflows/publish_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
runs-on: ubuntu-latest
3131
steps:
3232
- run: |
33-
if [[ "${{ github.triggering_actor }}" != "ahoppen" ]]; then
33+
if [[ "${{ github.triggering_actor }}" != "bnbarham" ]]; then
3434
echo "${{ github.triggering_actor }} is not allowed to create a release"
3535
exit 1
3636
fi

.github/workflows/pull_request.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Pull request
22

3+
# PRs created by GitHub Actions don't kick off further actions (https://github.com/peter-evans/create-pull-request/blob/d57e551ebc1a16dee0b8c9ea6d24dba7627a6e35/docs/concepts-guidelines.md#triggering-further-workflow-runs).
4+
# As a workaround, we mark automerge PRs that are created by GitHub actions as draft and trigger the GitHub actions by marking the PR as ready for review. We'd prefer not re-triggering testing on a normal user's PR in this case, but skipping them causes the checks to reset.
5+
36
on:
47
pull_request:
58
types: [opened, reopened, synchronize, ready_for_review]
@@ -12,17 +15,11 @@ jobs:
1215
tests:
1316
name: Test
1417
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
15-
# PRs created by GitHub Actions don't kick off further actions (https://github.com/peter-evans/create-pull-request/blob/d57e551ebc1a16dee0b8c9ea6d24dba7627a6e35/docs/concepts-guidelines.md#triggering-further-workflow-runs).
16-
# As a workaround, we mark automerge PRs that are created by GitHub actions as draft and trigger the GitHub actions by marking the PR as ready for review. But we don't want to re-trigger testing this when a normal user's PR is marked as ready for review.
17-
if: (github.event.action != 'ready_for_review') || (github.event.action == 'ready_for_review' && github.event.pull_request.user.login == 'github-actions[bot]')
1818
with:
1919
linux_exclude_swift_versions: "[{\"swift_version\": \"5.8\"}]"
2020
soundness:
2121
name: Soundness
2222
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
23-
# PRs created by GitHub Actions don't kick off further actions (https://github.com/peter-evans/create-pull-request/blob/d57e551ebc1a16dee0b8c9ea6d24dba7627a6e35/docs/concepts-guidelines.md#triggering-further-workflow-runs).
24-
# As a workaround, we mark automerge PRs that are created by GitHub actions as draft and trigger the GitHub actions by marking the PR as ready for review. But we don't want to re-trigger testing this when a normal user's PR is marked as ready for review.
25-
if: (github.event.action != 'ready_for_review') || (github.event.action == 'ready_for_review' && github.event.pull_request.user.login == 'github-actions[bot]')
2623
with:
2724
license_header_check_project_name: "Swift.org"
2825
api_breakage_check_allowlist_path: "api-breakages.txt"

Sources/SwiftFormat/API/Configuration.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ public struct Configuration: Codable, Equatable {
292292

293293
/// Creates a new `Configuration` by decoding it from the UTF-8 representation in the given data.
294294
public init(data: Data) throws {
295-
self = try JSONDecoder().decode(Configuration.self, from: data)
295+
let jsonDecoder = JSONDecoder()
296+
#if canImport(Darwin) || compiler(>=6)
297+
jsonDecoder.allowsJSON5 = true
298+
#endif
299+
self = try jsonDecoder.decode(Configuration.self, from: data)
296300
}
297301

298302
public init(from decoder: Decoder) throws {

Sources/SwiftFormat/Rules/NoAssignmentInExpressions.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

Tests/SwiftFormatTests/API/ConfigurationTests.swift

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ final class ConfigurationTests: XCTestCase {
2323

2424
let emptyDictionaryData = "{}\n".data(using: .utf8)!
2525
let jsonDecoder = JSONDecoder()
26+
#if canImport(Darwin) || compiler(>=6)
27+
jsonDecoder.allowsJSON5 = true
28+
#endif
2629
let emptyJSONConfig =
2730
try! jsonDecoder.decode(Configuration.self, from: emptyDictionaryData)
2831

@@ -79,7 +82,11 @@ final class ConfigurationTests: XCTestCase {
7982
}
8083
""".data(using: .utf8)!
8184

82-
let config = try JSONDecoder().decode(Configuration.self, from: jsonData)
85+
let jsonDecoder = JSONDecoder()
86+
#if canImport(Darwin) || compiler(>=6)
87+
jsonDecoder.allowsJSON5 = true
88+
#endif
89+
let config = try jsonDecoder.decode(Configuration.self, from: jsonData)
8390
XCTAssertEqual(config.reflowMultilineStringLiterals, expectedBehavior)
8491
}
8592
}
@@ -99,9 +106,33 @@ final class ConfigurationTests: XCTestCase {
99106
}
100107
""".data(using: .utf8)!
101108

102-
let config = try JSONDecoder().decode(Configuration.self, from: jsonData)
109+
let jsonDecoder = JSONDecoder()
110+
#if canImport(Darwin) || compiler(>=6)
111+
jsonDecoder.allowsJSON5 = true
112+
#endif
113+
let config = try jsonDecoder.decode(Configuration.self, from: jsonData)
103114
XCTAssertEqual(config.reflowMultilineStringLiterals, expectedBehavior)
104115
}
105116
}
106117

118+
func testConfigurationWithComments() throws {
119+
#if !canImport(Darwin) && compiler(<6)
120+
try XCTSkipIf(true, "JSONDecoder does not support JSON5")
121+
#else
122+
let expected = Configuration()
123+
124+
let jsonData = """
125+
{
126+
// Indicates the configuration schema version.
127+
"version": 1,
128+
}
129+
""".data(using: .utf8)!
130+
131+
let jsonDecoder = JSONDecoder()
132+
133+
jsonDecoder.allowsJSON5 = true
134+
let config = try jsonDecoder.decode(Configuration.self, from: jsonData)
135+
XCTAssertEqual(config, expected)
136+
#endif
137+
}
107138
}

Tests/SwiftFormatTests/Rules/NoAssignmentInExpressionsTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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: []

0 commit comments

Comments
 (0)