Skip to content

chore: add swiftformat GH action #3732

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions .github/workflows/swiftformat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: SwiftFormat
on:
workflow_dispatch:
workflow_call:
inputs:
identifier:
required: true
type: string

push:
branches-ignore:
- main
- v1
- release
- release-v1

permissions:
contents: read

concurrency:
group: ${{ inputs.identifier || github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref_name != 'main'}}

jobs:
run-swiftformat:
runs-on: ubuntu-latest
container:
image: ghcr.io/nicklockwood/swiftformat:0.54.3
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false

- name: SwiftFormat
run: |
swiftformat --lint . --reporter github-actions-log --swiftversion 5.9
confirm-pass:
runs-on: macos-latest
name: Confirm Passing SwiftFormat
if: ${{ !cancelled() }}
needs: [ run-swiftformat ]
env:
EXIT_CODE: ${{ contains(needs.*.result, 'failure') && 1 || 0 }}
steps:
- run: exit $EXIT_CODE
11 changes: 8 additions & 3 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -65,12 +65,17 @@
--enable void
--empty void

--disable wrapArguments
--closingparen same-line
--wraparguments after-first
--enable wrapArguments
--closingparen balanced
--wraparguments before-first
--wrapcollections before-first
--wrapconditions preserve

# standalone rules
--disable preferKeyPath
--disable conditionalAssignment
--disable wrapMultilineConditionalAssignment
--disable wrapMultilineStatementBraces
--disable andOperator
--disable anyObjectProtocol
--disable blankLinesAroundMark

Unchanged files with check annotations Beta

///
/// - Parameter plugin: The plugin to add
/// - Tag: Amplify.add_plugin
public static func add<P: Plugin>(plugin: P) throws {

Check warning on line 82 in Amplify/Amplify.swift

GitHub Actions / run-swiftlint

Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)
log.debug("Adding plugin: \(plugin))")
switch plugin {
case let plugin as AnalyticsCategoryPlugin:
import Foundation
// swiftlint:disable cyclomatic_complexity

Check warning on line 10 in Amplify/Core/Configuration/Internal/Amplify+Reset.swift

GitHub Actions / run-swiftlint

The disabled 'cyclomatic_complexity' rule should be re-enabled before the end of the file (blanket_disable_command)
extension Amplify {
/// Resets the state of the Amplify framework.
/// - Parameter configuration: The AmplifyConfiguration for specified Categories
///
/// - Tag: Amplify.configure
public static func configure(_ configuration: AmplifyConfiguration? = nil) throws {

Check warning on line 112 in Amplify/Core/Configuration/AmplifyConfiguration.swift

GitHub Actions / run-swiftlint

Function should have complexity 10 or less; currently complexity is 13 (cyclomatic_complexity)
log.info("Configuring")
log.debug("Configuration: \(String(describing: configuration))")
guard !isConfigured else {
}
}
public class AmplifyInProcessReportingOperationTaskAdapter<Request: AmplifyOperationRequest,

Check warning on line 67 in Amplify/Core/Support/AmplifyTask+OperationTaskAdapters.swift

GitHub Actions / run-swiftlint

Type name 'AmplifyInProcessReportingOperationTaskAdapter' should be between 3 and 40 characters long (type_name)
InProcess,
Success,
Failure: AmplifyError>: AmplifyTask, AmplifyInProcessReportingTask {
/// - Tag: StorageListResult.items
public var items: [Item]

Check warning on line 35 in Amplify/Categories/Storage/Result/StorageListResult.swift

GitHub Actions / run-swiftlint

Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
/// Array of excluded subpaths in the Result.
/// This field is only populated when [`StorageListRequest.Options.subpathStrategy`](x-source-tag://StorageListRequestOptions.subpathStragegy) is set to [`.exclude()`](x-source-tag://SubpathStrategy.exclude).
///
///
/// - Tag: StorageDownloadFileRequest.path
public let path: (any StoragePath)?

Check warning on line 20 in Amplify/Categories/Storage/Operation/Request/StorageDownloadDataRequest.swift

GitHub Actions / run-swiftlint

Lines should not have trailing whitespace (trailing_whitespace)
/// The unique identifier for the object in storage
///
/// - Tag: StorageDownloadDataRequest.key
import Foundation
// swiftlint:disable type_name

Check warning on line 10 in Amplify/Categories/Auth/Request/AuthAttributeSendVerificationCodeRequest.swift

GitHub Actions / run-swiftlint

The disabled 'type_name' rule should be re-enabled before the end of the file (blanket_disable_command)
/// Request for sending verification code that was generated for update attribute
public struct AuthSendUserAttributeVerificationCodeRequest: AmplifyOperationRequest {
import Foundation
// swiftlint:disable type_name

Check warning on line 10 in Amplify/Categories/Auth/Request/AuthAttributeResendConfirmationCodeRequest.swift

GitHub Actions / run-swiftlint

The disabled 'type_name' rule should be re-enabled before the end of the file (blanket_disable_command)
/// Request for resending confirmation code that was generated for update attribute
public struct AuthAttributeResendConfirmationCodeRequest: AmplifyOperationRequest {
import Foundation
import Combine

Check warning on line 11 in Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift

GitHub Actions / run-swiftlint

Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
// MARK: - RetryableGraphQLOperation
public final class RetryableGraphQLOperation<Payload: Decodable> {
public typealias Payload = Payload
fileprivate var asyncStream: AsyncStream<Self.Element> {
AsyncStream { continuation in
Task {
var it = self.makeAsyncIterator()

Check warning on line 134 in Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift

GitHub Actions / run-swiftlint

Variable name 'it' should be between 3 and 40 characters long (identifier_name)
do {
while let ele = try await it.next() {
continuation.yield(ele)
// SPDX-License-Identifier: Apache-2.0
//
import Foundation

Check warning on line 8 in AmplifyTestCommon/TestCommonConstants.swift

GitHub Actions / run-swiftformat

Insert blank line after import statements. (blankLineAfterImports)
class TestCommonConstants {
static let networkTimeout = TimeInterval(10)
}
import UIKit
@UIApplicationMain

Check warning on line 10 in AmplifyTestApp/AppDelegate.swift

GitHub Actions / run-swiftformat

Replace obsolete @UIApplicationMain and @NSApplicationMain attributes with @main for Swift 5.3 and above. (applicationMain)
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// SPDX-License-Identifier: Apache-2.0
//
import XCTest

Check warning on line 8 in AmplifyFunctionalTests/AmplifyConfigurationInitFromFileTests.swift

GitHub Actions / run-swiftformat

Sort import statements alphabetically. (sortImports)
import Amplify

Check warning on line 9 in AmplifyFunctionalTests/AmplifyConfigurationInitFromFileTests.swift

GitHub Actions / run-swiftformat

Sort import statements alphabetically. (sortImports)
/// Test the public AmplifyConfiguration initializer. Note that this means we must not import
/// Amplify as `@testable`. That means we cannot `await Amplify.reset()`, which means we can only have
@testable import CwlPreconditionTesting
public func XCTAssertThrowFatalError(_ expression: @escaping () -> Void,

Check warning on line 13 in AmplifyTestCommon/Helpers/AmplifyAssertions.swift

GitHub Actions / run-swiftformat

Align wrapped function arguments or collection elements. (wrapArguments)
file: StaticString = #file,

Check warning on line 14 in AmplifyTestCommon/Helpers/AmplifyAssertions.swift

GitHub Actions / run-swiftformat

Align wrapped function arguments or collection elements. (wrapArguments)
line: UInt = #line) throws {

Check warning on line 15 in AmplifyTestCommon/Helpers/AmplifyAssertions.swift

GitHub Actions / run-swiftformat

Align wrapped function arguments or collection elements. (wrapArguments)
#if (os(iOS) || os(macOS)) && (arch(arm64) || arch(x86_64))
var reached = false
let exception = catchBadInstruction {
#endif
}
public func XCTAssertNoThrowFatalError(_ expression: @escaping () -> Void,

Check warning on line 29 in AmplifyTestCommon/Helpers/AmplifyAssertions.swift

GitHub Actions / run-swiftformat

Align wrapped function arguments or collection elements. (wrapArguments)
file: StaticString = #file,

Check warning on line 30 in AmplifyTestCommon/Helpers/AmplifyAssertions.swift

GitHub Actions / run-swiftformat

Align wrapped function arguments or collection elements. (wrapArguments)
line: UInt = #line) throws {

Check warning on line 31 in AmplifyTestCommon/Helpers/AmplifyAssertions.swift

GitHub Actions / run-swiftformat

Align wrapped function arguments or collection elements. (wrapArguments)
#if (os(iOS) || os(macOS)) && (arch(arm64) || arch(x86_64))
var reached = false
let exception = catchBadInstruction {