Skip to content

Commit 68dda60

Browse files
chore: add swiftformat GH action (#3732)
* chore: add swiftformat GH action * remove swift format container image * chore: disable error code with swift format linting * update to fail workflow on warning * pin to specific version * specify swift version * chore: add swiftformat changes for swift version 5.9 * chore: update code * chore: update code * chore: update code * chore: update swiftformat version in gh action * chore: update swiftformat version in gh action * chore: update swiftformat version in gh action * chore: runs gh action on macos-runner * chore: resolve swiftlint errors --------- Co-authored-by: Abhash Kumar Singh <[email protected]>
1 parent 81bc4b6 commit 68dda60

File tree

33 files changed

+111
-229
lines changed

33 files changed

+111
-229
lines changed

.github/workflows/swiftformat.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: SwiftFormat
2+
on:
3+
workflow_dispatch:
4+
workflow_call:
5+
inputs:
6+
identifier:
7+
required: true
8+
type: string
9+
10+
push:
11+
branches-ignore:
12+
- main
13+
- v1
14+
- release
15+
- release-v1
16+
17+
permissions:
18+
contents: read
19+
20+
concurrency:
21+
group: ${{ inputs.identifier || github.workflow }}-${{ github.event.pull_request.number || github.ref }}
22+
cancel-in-progress: ${{ github.ref_name != 'main'}}
23+
24+
jobs:
25+
run-swiftformat:
26+
runs-on: macos-latest
27+
steps:
28+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
29+
with:
30+
persist-credentials: false
31+
32+
- name: SwiftFormat
33+
run: |
34+
swiftformat --lint . --reporter github-actions-log --swiftversion 5.9
35+
36+
confirm-pass:
37+
runs-on: macos-latest
38+
name: Confirm Passing SwiftFormat
39+
if: ${{ !cancelled() }}
40+
needs: [ run-swiftformat ]
41+
env:
42+
EXIT_CODE: ${{ contains(needs.*.result, 'failure') && 1 || 0 }}
43+
steps:
44+
- run: exit $EXIT_CODE

Amplify/Categories/DataStore/DataStoreCategoryBehavior.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public protocol DataStoreBaseBehavior {
4343
paginate paginationInput: QueryPaginationInput?
4444
) async throws -> [M]
4545

46-
func delete<M: Model>(
47-
_ model: M,
46+
func delete(
47+
_ model: some Model,
4848
where predicate: QueryPredicate?
4949
) async throws
5050

51-
func delete<M: Model>(
52-
_ modelType: M.Type,
51+
func delete(
52+
_ modelType: (some Model).Type,
5353
withId id: String,
5454
where predicate: QueryPredicate?
5555
) async throws
@@ -66,8 +66,8 @@ public protocol DataStoreBaseBehavior {
6666
where predicate: QueryPredicate?
6767
) async throws where M: ModelIdentifiable
6868

69-
func delete<M: Model>(
70-
_ modelType: M.Type,
69+
func delete(
70+
_ modelType: (some Model).Type,
7171
where predicate: QueryPredicate
7272
) async throws
7373

@@ -100,7 +100,7 @@ public protocol DataStoreBaseBehavior {
100100
public protocol DataStoreSubscribeBehavior {
101101
/// Returns an AmplifyAsyncThrowingSequence for model changes (create, updates, delete)
102102
/// - Parameter modelType: The model type to observe
103-
func observe<M: Model>(_ modelType: M.Type) -> AmplifyAsyncThrowingSequence<MutationEvent>
103+
func observe(_ modelType: (some Model).Type) -> AmplifyAsyncThrowingSequence<MutationEvent>
104104

105105
/// Returns a Publisher for query snapshots.
106106
///

Amplify/Categories/DataStore/Subscribe/MutationEvent.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public struct MutationEvent: Model {
6666
Initializing from a model without a ModelSchema is deprecated.
6767
Use init(model:modelSchema:mutationType:version:graphQLFilterJSON:) instead.
6868
""")
69-
public init<M: Model>(
70-
model: M,
69+
public init(
70+
model: some Model,
7171
mutationType: MutationType,
7272
version: Int? = nil,
7373
graphQLFilterJSON: String? = nil

Amplify/Categories/Predictions/PredictionsCategoryBehavior.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public protocol PredictionsCategoryBehavior {
2626
/// - request:
2727
/// - options:
2828
/// - Returns:
29-
func convert<Input, Options, Output>(
30-
_ request: Predictions.Convert.Request<Input, Options, Output>,
29+
func convert<Options, Output>(
30+
_ request: Predictions.Convert.Request<some Any, Options, Output>,
3131
options: Options?
3232
) async throws -> Output
3333

Amplify/Core/Plugin/Plugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ public typealias PluginKey = String
3030
/// to store heterogenous collections of Plugins in a category.
3131
/// - Throws: PluginError.mismatchedPlugin if the instance is associated with the wrong category
3232
public protocol PluginInitializable {
33-
init<P: Plugin>(instance: P)
33+
init(instance: some Plugin)
3434
}

AmplifyAsyncTesting/Sources/AsyncTesting/XCTestCase+AsyncTesting.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ public extension XCTestCase {
150150
///
151151
/// - Returns:The error thrown during the execution of `action`, or `nil` if it run successfully.
152152
@discardableResult
153-
internal func waitError<T>(
153+
internal func waitError(
154154
with expectation: AsyncExpectation,
155155
timeout: TimeInterval = defaultNetworkTimeoutForAsyncExpectations,
156-
action: @escaping () async throws -> T
156+
action: @escaping () async throws -> some Any
157157
) async -> Error? {
158158
let task = Task { () -> Error? in
159159
defer {
@@ -186,10 +186,10 @@ public extension XCTestCase {
186186
///
187187
/// - Returns:The error thrown during the execution of `action`, or `nil` if it run successfully.
188188
@discardableResult
189-
internal func waitError<T>(
189+
internal func waitError(
190190
name: String,
191191
timeout: TimeInterval = defaultNetworkTimeoutForAsyncExpectations,
192-
action: @escaping () async throws -> T
192+
action: @escaping () async throws -> some Any
193193
) async -> Error? {
194194
let expectation = asyncExpectation(description: name)
195195
return await waitError(with: expectation, timeout: timeout, action: action)

AmplifyPlugins/API/Sources/AWSAPIPlugin/AppSyncRealTimeClient/AppSyncRealTimeClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ actor AppSyncRealTimeClient: AppSyncRealTimeClientProtocol {
165165
// promptly returning the filtered publisher for downstream consumption of all error messages.
166166
defer {
167167
let task = Task { [weak self] in
168-
guard let self = self else { return }
169-
if !(await self.isConnected) {
168+
guard let self else { return }
169+
if await !(self.isConnected) {
170170
try await connect()
171171
try await waitForState(.connected)
172172
}
173-
try await self.storeInConnectionCancellables(await self.startSubscription(id))
173+
try await self.storeInConnectionCancellables(self.startSubscription(id))
174174
}
175175
self.storeInConnectionCancellables(task.toAnyCancellable)
176176
}

AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginFunctionalTests/GraphQLModelBasedTests+List.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ extension GraphQLModelBasedTests {
188188
func list<M: Model>(_ request: GraphQLRequest<List<M>>) async throws -> [M] {
189189
func getAllPages(_ list: List<M>) async throws -> [M] {
190190
if list.hasNextPage() {
191-
return try list.elements + (await getAllPages(list.getNextPage()))
191+
return try await list.elements + getAllPages(list.getNextPage())
192192
} else {
193193
return list.elements
194194
}
195195
}
196196

197-
return try await getAllPages(await Amplify.API.query(request: request).get())
197+
return try await getAllPages(Amplify.API.query(request: request).get())
198198
}
199199

200200
}

AmplifyPlugins/API/Tests/AWSAPIPluginTests/AppSyncRealTimeClient/AppSyncRealTimeRequestAuthTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class AppSyncRealTimeRequestAuthTests: XCTestCase {
8181
}
8282

8383
private func areDictionariesEqual(_ lhs: [String: Any]?, _ rhs: [String: Any]?) -> Bool {
84-
guard let lhs = lhs, let rhs = rhs else { return false }
84+
guard let lhs, let rhs else { return false }
8585
return NSDictionary(dictionary: lhs).isEqual(to: rhs)
8686
}
8787

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ASF/ASFDeviceInfo.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ struct ASFDeviceInfo: ASFDeviceBehavior {
8181
}
8282

8383
func deviceInfo() async -> String {
84-
let model = await self.model
85-
let type = await self.type
86-
let version = await self.version
84+
let model = await model
85+
let type = await type
86+
let version = await version
8787
var build = "release"
8888
#if DEBUG
8989
build = "debug"

0 commit comments

Comments
 (0)