diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml index 0a6d51ae0..6995e8ce1 100644 --- a/.github/workflows/publish_release.yml +++ b/.github/workflows/publish_release.yml @@ -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 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index f1d7840ca..777a2d19d 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -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] @@ -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" diff --git a/Sources/SwiftFormat/API/Configuration.swift b/Sources/SwiftFormat/API/Configuration.swift index cb5dfb025..98a1b9b70 100644 --- a/Sources/SwiftFormat/API/Configuration.swift +++ b/Sources/SwiftFormat/API/Configuration.swift @@ -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 { diff --git a/Sources/SwiftFormat/Rules/NoAssignmentInExpressions.swift b/Sources/SwiftFormat/Rules/NoAssignmentInExpressions.swift index bc10f3a31..194ed43cb 100644 --- a/Sources/SwiftFormat/Rules/NoAssignmentInExpressions.swift +++ b/Sources/SwiftFormat/Rules/NoAssignmentInExpressions.swift @@ -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 } diff --git a/Tests/SwiftFormatTests/API/ConfigurationTests.swift b/Tests/SwiftFormatTests/API/ConfigurationTests.swift index 9c6977db8..d983e9cb9 100644 --- a/Tests/SwiftFormatTests/API/ConfigurationTests.swift +++ b/Tests/SwiftFormatTests/API/ConfigurationTests.swift @@ -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) @@ -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) } } @@ -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 + } } diff --git a/Tests/SwiftFormatTests/Rules/NoAssignmentInExpressionsTests.swift b/Tests/SwiftFormatTests/Rules/NoAssignmentInExpressionsTests.swift index 928296c59..7a9093d2c 100644 --- a/Tests/SwiftFormatTests/Rules/NoAssignmentInExpressionsTests.swift +++ b/Tests/SwiftFormatTests/Rules/NoAssignmentInExpressionsTests.swift @@ -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: []