Skip to content

Commit fe989b5

Browse files
authored
chore(notifications): resolve swiftformat errors and warnings (#3853)
* chore(notifications): resolve swiftformat errors and warnings * updated swiftformat rules
1 parent 47601cd commit fe989b5

23 files changed

+154
-134
lines changed

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+ClientBehaviour.swift

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,34 @@ import UIKit
1818
import AppKit
1919
#endif
2020

21-
extension AWSPinpointPushNotificationsPlugin {
22-
public func identifyUser(userId: String, userProfile: UserProfile?) async throws {
21+
public extension AWSPinpointPushNotificationsPlugin {
22+
func identifyUser(userId: String, userProfile: UserProfile?) async throws {
2323
var currentEndpointProfile = await pinpoint.currentEndpointProfile()
2424
currentEndpointProfile.addUserId(userId)
25-
if let userProfile = userProfile {
25+
if let userProfile {
2626
currentEndpointProfile.addUserProfile(userProfile)
2727
}
28-
try await pinpoint.updateEndpoint(with: currentEndpointProfile,
29-
source: .pushNotifications)
28+
try await pinpoint.updateEndpoint(
29+
with: currentEndpointProfile,
30+
source: .pushNotifications
31+
)
3032
}
3133

32-
public func registerDevice(apnsToken: Data) async throws {
34+
func registerDevice(apnsToken: Data) async throws {
3335
var currentEndpointProfile = await pinpoint.currentEndpointProfile()
3436
currentEndpointProfile.setAPNsToken(apnsToken)
3537
do {
36-
try await pinpoint.updateEndpoint(with: currentEndpointProfile,
37-
source: .pushNotifications)
38+
try await pinpoint.updateEndpoint(
39+
with: currentEndpointProfile,
40+
source: .pushNotifications
41+
)
3842
} catch {
3943
throw error.pushNotificationsError
4044
}
4145
}
4246

43-
public func recordNotificationReceived(_ userInfo: Notifications.Push.UserInfo) async throws {
44-
let applicationState = await self.applicationState
47+
func recordNotificationReceived(_ userInfo: Notifications.Push.UserInfo) async throws {
48+
let applicationState = await applicationState
4549
await recordNotification(
4650
userInfo,
4751
applicationState: applicationState,
@@ -50,8 +54,8 @@ extension AWSPinpointPushNotificationsPlugin {
5054
}
5155

5256
#if !os(tvOS)
53-
public func recordNotificationOpened(_ response: UNNotificationResponse) async throws {
54-
let applicationState = await self.applicationState
57+
func recordNotificationOpened(_ response: UNNotificationResponse) async throws {
58+
let applicationState = await applicationState
5559
await recordNotification(
5660
response.notification.request.content.userInfo,
5761
applicationState: applicationState,
@@ -63,24 +67,28 @@ extension AWSPinpointPushNotificationsPlugin {
6367
/// Retrieves the escape hatch to perform actions directly on PinpointClient.
6468
///
6569
/// - Returns: PinpointClientProtocol instance
66-
public func getEscapeHatch() -> PinpointClientProtocol {
70+
func getEscapeHatch() -> PinpointClientProtocol {
6771
pinpoint.pinpointClient
6872
}
6973

70-
private func recordNotification(_ userInfo: [String: Any],
71-
applicationState: ApplicationState,
72-
action: PushNotification.Action) async {
73-
let userInfo: PushNotification.UserInfo = Dictionary(uniqueKeysWithValues: userInfo.map({($0, $1)}))
74+
private func recordNotification(
75+
_ userInfo: [String: Any],
76+
applicationState: ApplicationState,
77+
action: PushNotification.Action
78+
) async {
79+
let userInfo: PushNotification.UserInfo = Dictionary(uniqueKeysWithValues: userInfo.map {($0, $1)})
7480
await recordNotification(
7581
userInfo,
7682
applicationState: applicationState,
7783
action: action
7884
)
7985
}
8086

81-
private func recordNotification(_ userInfo: PushNotification.UserInfo,
82-
applicationState: ApplicationState,
83-
action: PushNotification.Action) async {
87+
private func recordNotification(
88+
_ userInfo: PushNotification.UserInfo,
89+
applicationState: ApplicationState,
90+
action: PushNotification.Action
91+
) async {
8492
// Retrieve the payload from the notification
8593
guard let payload = userInfo.payload else {
8694
log.error(
@@ -99,8 +107,10 @@ extension AWSPinpointPushNotificationsPlugin {
99107

100108
// Add application state
101109
let applicationStateAttribute = applicationState.pinpointAttribute
102-
pushNotificationEvent.addAttribute(applicationStateAttribute.value,
103-
forKey: applicationStateAttribute.key)
110+
pushNotificationEvent.addAttribute(
111+
applicationStateAttribute.value,
112+
forKey: applicationStateAttribute.key
113+
)
104114

105115
// Set global remote attributes
106116
await pinpoint.setRemoteGlobalAttributes(payload.attributes)

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+Configure.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ extension AWSPinpointPushNotificationsPlugin {
3131

3232
pluginConfiguration = AWSPinpointPluginConfiguration(
3333
appId: notifications.amazonPinpointAppId,
34-
region: notifications.awsRegion)
34+
region: notifications.awsRegion
35+
)
3536
} else if let config = configuration as? JSONValue {
3637
pluginConfiguration = try AWSPinpointPluginConfiguration(config)
3738
} else {
@@ -51,8 +52,10 @@ extension AWSPinpointPushNotificationsPlugin {
5152
region: configuration.region
5253
)
5354

54-
configure(pinpoint: pinpoint,
55-
remoteNotificationsHelper: .default)
55+
configure(
56+
pinpoint: pinpoint,
57+
remoteNotificationsHelper: .default
58+
)
5659
}
5760

5861
private func requestNotificationsPermissions(using helper: RemoteNotificationsBehaviour) async {
@@ -70,8 +73,10 @@ extension AWSPinpointPushNotificationsPlugin {
7073

7174
// MARK: Internal
7275
/// Internal configure method to set the properties of the plugin
73-
func configure(pinpoint: AWSPinpointBehavior,
74-
remoteNotificationsHelper: RemoteNotificationsBehaviour) {
76+
func configure(
77+
pinpoint: AWSPinpointBehavior,
78+
remoteNotificationsHelper: RemoteNotificationsBehaviour
79+
) {
7580
self.pinpoint = pinpoint
7681
Task {
7782
await remoteNotificationsHelper.registerForRemoteNotifications()

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+Reset.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import Foundation
99

10-
extension AWSPinpointPushNotificationsPlugin {
11-
public func reset() async {
10+
public extension AWSPinpointPushNotificationsPlugin {
11+
func reset() async {
1212
if pinpoint != nil {
1313
pinpoint = nil
1414
}

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+Types.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import AmplifyUtilsNotifications
99
import Foundation
1010

11-
extension AWSPinpointPushNotificationsPlugin {
11+
public extension AWSPinpointPushNotificationsPlugin {
1212

1313
#if !os(tvOS)
1414
/// Service Extension that can handle AWS Pinpoint rich notifications.
15-
public typealias ServiceExtension = AUNotificationService
15+
typealias ServiceExtension = AUNotificationService
1616
#endif
1717

1818
/// A protocol that can be used to customize the expeded payload that the ServiceExtension can handle.
19-
public typealias NotificationPayload = AUNotificationPayload
19+
typealias NotificationPayload = AUNotificationPayload
2020
}

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/Error/CommonRunTimeError+PushNotificationsErrorConvertible.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
import Foundation
98
import Amplify
109
import AwsCommonRuntimeKit
10+
import Foundation
1111
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint
1212

1313
extension CommonRunTimeError: PushNotificationsErrorConvertible {

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/Error/Pinpoint+PushNotificationsErrorConvertible.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
import Foundation
98
import Amplify
9+
import AWSClientRuntime
1010
import AWSPinpoint
1111
import ClientRuntime
12-
import AWSClientRuntime
12+
import Foundation
1313

1414
private func recoverySuggestion(for error: ClientRuntime.ModeledError) -> String {
1515
type(of: error).isRetryable

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/Error/PushNotificationsErrorConvertible.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
import Foundation
98
import Amplify
9+
import Foundation
1010

1111
protocol PushNotificationsErrorConvertible {
1212
var pushNotificationsError: PushNotificationsError { get }

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/Extensions/PushNotificationUserInfo+Pinpoint.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ import Foundation
1111
extension PushNotification.UserInfo {
1212
private var root: [String: Any]? {
1313
guard let data = self[Constants.Keys.data] as? [String: Any],
14-
let root = data[Constants.Keys.pinpoint] as? [String: Any] else {
14+
let root = data[Constants.Keys.pinpoint] as? [String: Any]
15+
else {
1516
return nil
1617
}
1718

1819
return root
1920
}
2021

2122
var payload: PushNotification.Payload? {
22-
guard let root = root else {
23+
guard let root else {
2324
return nil
2425
}
2526

@@ -42,8 +43,8 @@ extension PushNotification.UserInfo {
4243
}
4344

4445
extension PushNotification.UserInfo {
45-
private struct Constants {
46-
struct Keys {
46+
private enum Constants {
47+
enum Keys {
4748
static let data = "data"
4849
static let pinpoint = "pinpoint"
4950
static let campaing = "campaign"

AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/Support/Constants/PushNotificationsPluginErrorConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
typealias PushNotificationsPluginErrorString = (errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion)
1212

13-
struct PushNotificationsPluginErrorConstants {
13+
enum PushNotificationsPluginErrorConstants {
1414
static let decodeConfigurationError: PushNotificationsPluginErrorString = (
1515
"Unable to decode configuration",
1616
"Make sure the plugin configuration is JSONValue"

AmplifyPlugins/Notifications/Push/Tests/AWSPinpointPushNotificationsPluginUnitTests/AWSPinpointPushNotificationsPluginAmplifyVersionableTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
import XCTest
98
import AWSPinpointPushNotificationsPlugin
9+
import XCTest
1010

1111
class AWSPinpointPushNotificationsPluginAmplifyVersionableTests: AWSPinpointPushNotificationsPluginTestBase {
1212
func testVersion_shouldReturnNotNil() {

0 commit comments

Comments
 (0)