Skip to content

Merge main into release/6.2 #1022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- run: |
if [[ "${{ github.triggering_actor }}" != "ahoppen" ]]; then
if [[ "${{ github.triggering_actor }}" != "bnbarham" ]]; then
echo "${{ github.triggering_actor }} is not allowed to create a release"
exit 1
fi
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Pull request

# 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).
# 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.

on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
Expand All @@ -12,17 +15,11 @@ jobs:
tests:
name: Test
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
# 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).
# 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.
if: (github.event.action != 'ready_for_review') || (github.event.action == 'ready_for_review' && github.event.pull_request.user.login == 'github-actions[bot]')
with:
linux_exclude_swift_versions: "[{\"swift_version\": \"5.8\"}]"
soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
# 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).
# 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.
if: (github.event.action != 'ready_for_review') || (github.event.action == 'ready_for_review' && github.event.pull_request.user.login == 'github-actions[bot]')
with:
license_header_check_project_name: "Swift.org"
api_breakage_check_allowlist_path: "api-breakages.txt"
6 changes: 5 additions & 1 deletion Sources/SwiftFormat/API/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ public struct Configuration: Codable, Equatable {

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

public init(from decoder: Decoder) throws {
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftFormat/Rules/NoAssignmentInExpressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ public final class NoAssignmentInExpressions: SyntaxFormatRule {

/// Returns a value indicating whether the given node is a standalone assignment statement.
///
/// This function considers try/await expressions and automatically walks up through them as
/// needed. This is because `try f().x = y` should still be a standalone assignment for our
/// This function considers try/await/unsafe expressions and automatically walks up through them
/// as needed. This is because `try f().x = y` should still be a standalone assignment for our
/// purposes, even though a `TryExpr` will wrap the `InfixOperatorExpr` and thus would not be
/// considered a standalone assignment if we only checked the infix expression for a
/// `CodeBlockItem` parent.
private func isStandaloneAssignmentStatement(_ node: InfixOperatorExprSyntax) -> Bool {
var node = Syntax(node)
while let parent = node.parent,
parent.is(TryExprSyntax.self) || parent.is(AwaitExprSyntax.self)
parent.is(TryExprSyntax.self) || parent.is(AwaitExprSyntax.self) || parent.is(UnsafeExprSyntax.self)
{
node = parent
}
Expand Down
35 changes: 33 additions & 2 deletions Tests/SwiftFormatTests/API/ConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ final class ConfigurationTests: XCTestCase {

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

Expand Down Expand Up @@ -79,7 +82,11 @@ final class ConfigurationTests: XCTestCase {
}
""".data(using: .utf8)!

let config = try JSONDecoder().decode(Configuration.self, from: jsonData)
let jsonDecoder = JSONDecoder()
#if canImport(Darwin) || compiler(>=6)
jsonDecoder.allowsJSON5 = true
#endif
let config = try jsonDecoder.decode(Configuration.self, from: jsonData)
XCTAssertEqual(config.reflowMultilineStringLiterals, expectedBehavior)
}
}
Expand All @@ -99,9 +106,33 @@ final class ConfigurationTests: XCTestCase {
}
""".data(using: .utf8)!

let config = try JSONDecoder().decode(Configuration.self, from: jsonData)
let jsonDecoder = JSONDecoder()
#if canImport(Darwin) || compiler(>=6)
jsonDecoder.allowsJSON5 = true
#endif
let config = try jsonDecoder.decode(Configuration.self, from: jsonData)
XCTAssertEqual(config.reflowMultilineStringLiterals, expectedBehavior)
}
}

func testConfigurationWithComments() throws {
#if !canImport(Darwin) && compiler(<6)
try XCTSkipIf(true, "JSONDecoder does not support JSON5")
#else
let expected = Configuration()

let jsonData = """
{
// Indicates the configuration schema version.
"version": 1,
}
""".data(using: .utf8)!

let jsonDecoder = JSONDecoder()

jsonDecoder.allowsJSON5 = true
let config = try jsonDecoder.decode(Configuration.self, from: jsonData)
XCTAssertEqual(config, expected)
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,21 @@ final class NoAssignmentInExpressionsTests: LintOrFormatRuleTestCase {
)
}

func testTryAndAwaitAssignmentExpressionsAreUnchanged() {
func testTryAndAwaitAndUnsafeAssignmentExpressionsAreUnchanged() {
assertFormatting(
NoAssignmentInExpressions.self,
input: """
func foo() {
try a.b = c
await a.b = c
unsafe a.b = c
}
""",
expected: """
func foo() {
try a.b = c
await a.b = c
unsafe a.b = c
}
""",
findings: []
Expand Down
Loading