Skip to content
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

chore(analytics): resolve swiftformat errors and warnings #3844

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import AWSPinpoint
import Foundation
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint

extension AWSPinpointAnalyticsPlugin {
public func identifyUser(userId: String, userProfile: AnalyticsUserProfile?) {
public extension AWSPinpointAnalyticsPlugin {
func identifyUser(userId: String, userProfile: AnalyticsUserProfile?) {
if !isEnabled {
log.warn("Cannot identify user. Analytics is disabled. Call Amplify.Analytics.enable() to enable")
return
Expand All @@ -20,7 +20,7 @@ extension AWSPinpointAnalyticsPlugin {
Task {
var currentEndpointProfile = await pinpoint.currentEndpointProfile()
currentEndpointProfile.addUserId(userId)
if let userProfile = userProfile {
if let userProfile {
currentEndpointProfile.addUserProfile(userProfile)
}
do {
Expand All @@ -33,7 +33,7 @@ extension AWSPinpointAnalyticsPlugin {
}
}

public func record(event: AnalyticsEvent) {
func record(event: AnalyticsEvent) {
if !isEnabled {
log.warn("Cannot record events. Analytics is disabled. Call Amplify.Analytics.enable() to enable")
return
Expand All @@ -55,12 +55,12 @@ extension AWSPinpointAnalyticsPlugin {
}
}

public func record(eventWithName eventName: String) {
func record(eventWithName eventName: String) {
let event = BasicAnalyticsEvent(name: eventName)
record(event: event)
}

public func registerGlobalProperties(_ properties: [String: AnalyticsPropertyValue]) {
func registerGlobalProperties(_ properties: [String: AnalyticsPropertyValue]) {
// TODO: check if there is a limit on total number of properties
properties.forEach { key, _ in
guard key.count >= 1, key.count <= 50 else {
Expand All @@ -75,13 +75,13 @@ extension AWSPinpointAnalyticsPlugin {
}
}

public func unregisterGlobalProperties(_ keys: Set<String>?) {
func unregisterGlobalProperties(_ keys: Set<String>?) {
Task {
await unregisterGlobalProperties(keys)
}
}

public func flushEvents() {
func flushEvents() {
if !isEnabled {
log.warn("Cannot flushEvents. Analytics is disabled. Call Amplify.Analytics.enable() to enable")
return
Expand All @@ -105,18 +105,18 @@ extension AWSPinpointAnalyticsPlugin {
}
}

public func enable() {
func enable() {
isEnabled = true
}

public func disable() {
func disable() {
isEnabled = false
}

/// Retrieve the escape hatch to perform actions directly on PinpointClient.
///
/// - Returns: PinpointClientProtocol instance
public func getEscapeHatch() -> PinpointClientProtocol {
func getEscapeHatch() -> PinpointClientProtocol {
pinpoint.pinpointClient
}

Expand All @@ -128,7 +128,7 @@ extension AWSPinpointAnalyticsPlugin {
}

private func unregisterGlobalProperties(_ keys: Set<String>?) async {
guard let keys = keys else {
guard let keys else {
for (key, value) in globalProperties {
await pinpoint.removeGlobalProperty(value, forKey: key)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint
import Network

extension AWSPinpointAnalyticsPlugin {
public extension AWSPinpointAnalyticsPlugin {
/// Configures AWSPinpointAnalyticsPlugin with the specified configuration.
///
/// This method will be invoked as part of the Amplify configuration flow.
///
/// - Parameter configuration: The configuration specified for this plugin
/// - Throws:
/// - PluginError.pluginConfigurationError: If one of the configuration values is invalid or empty
public func configure(using configuration: Any?) throws {
func configure(using configuration: Any?) throws {
let pluginConfiguration: AWSPinpointAnalyticsPluginConfiguration
if let config = configuration as? AmplifyOutputsData {
print(config)
Expand All @@ -45,7 +45,7 @@
}

/// Configure AWSPinpointAnalyticsPlugin programatically using AWSPinpointAnalyticsPluginConfiguration
public func configure(using configuration: AWSPinpointAnalyticsPluginConfiguration) throws {
func configure(using configuration: AWSPinpointAnalyticsPluginConfiguration) throws {
let pinpoint = try AWSPinpointFactory.sharedPinpoint(
appId: configuration.appId,
region: configuration.region
Expand Down Expand Up @@ -82,10 +82,11 @@
// MARK: Internal

/// Internal configure method to set the properties of the plugin
func configure(pinpoint: AWSPinpointBehavior,
internal func configure(pinpoint: AWSPinpointBehavior,
networkMonitor: NetworkMonitor,
globalProperties: AtomicDictionary<String, AnalyticsPropertyValue> = [:],
isEnabled: Bool = true) {
isEnabled: Bool = true)
{

Check failure on line 89 in AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Configure.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
self.pinpoint = pinpoint
self.networkMonitor = networkMonitor
self.globalProperties = globalProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import Foundation

extension AWSPinpointAnalyticsPlugin {
public struct Options {
public extension AWSPinpointAnalyticsPlugin {
struct Options {
static let defaultAutoFlushEventsInterval: TimeInterval = 60
static let defaultTrackAppSession = true

Expand All @@ -17,13 +17,15 @@

#if os(macOS)
public init(autoFlushEventsInterval: TimeInterval = 60,
trackAppSessions: Bool = true) {
trackAppSessions: Bool = true)
{

Check failure on line 21 in AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Options.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
self.autoFlushEventsInterval = autoFlushEventsInterval
self.trackAppSessions = trackAppSessions
}
#else
public init(autoFlushEventsInterval: TimeInterval = 60,
trackAppSessions: Bool = true) {
trackAppSessions: Bool = true)
{

Check failure on line 28 in AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Options.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
self.autoFlushEventsInterval = autoFlushEventsInterval
self.trackAppSessions = trackAppSessions
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Amplify
import Foundation
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint

extension AWSPinpointAnalyticsPlugin {
public extension AWSPinpointAnalyticsPlugin {
/// Resets the state of the plugin
public func reset() async {
func reset() async {
if pinpoint != nil {
pinpoint = nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

@_spi(InternalAmplifyConfiguration) import Amplify
import AWSPinpoint
import AWSClientRuntime
import AWSPinpoint
import Foundation
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint

Expand Down Expand Up @@ -54,20 +54,20 @@

let pluginConfiguration = try AWSPinpointPluginConfiguration(pinpointAnalyticsConfig)

let configOptions: AWSPinpointAnalyticsPlugin.Options
if let options {
configOptions = options
let configOptions: AWSPinpointAnalyticsPlugin.Options = if let options {
options
} else {
configOptions = .init(
autoFlushEventsInterval: try Self.getAutoFlushEventsInterval(configObject),
trackAppSessions: try Self.getTrackAppSessions(configObject))
try .init(
autoFlushEventsInterval: Self.getAutoFlushEventsInterval(configObject),
trackAppSessions: Self.getTrackAppSessions(configObject))
}
let autoSessionTrackingInterval = try Self.getAutoSessionTrackingInterval(configObject)

// Warn users in case they set different regions between pinpointTargeting and pinpointAnalytics
if let pinpointTargetingJson = configObject[Self.pinpointTargetingConfigKey],
let pinpointTargetingConfig = try? AWSPinpointPluginConfiguration(pinpointTargetingJson),
pinpointTargetingConfig.region != pluginConfiguration.region {
pinpointTargetingConfig.region != pluginConfiguration.region
{

Check failure on line 70 in AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Configuration/AWSPinpointAnalyticsPluginConfiguration.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
Self.logger.warn("Having different regions for Analytics and Targeting operations is not supported. The Analytics region will be used.")
}

Expand All @@ -78,7 +78,8 @@
}

init(_ configuration: AmplifyOutputsData,
options: AWSPinpointAnalyticsPlugin.Options) throws {
options: AWSPinpointAnalyticsPlugin.Options) throws
{

Check failure on line 82 in AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Configuration/AWSPinpointAnalyticsPluginConfiguration.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
guard let analyticsConfig = configuration.analytics else {
throw PluginError.pluginConfigurationError(
AnalyticsPluginErrorConstant.missingAnalyticsCategoryConfiguration.errorDescription,
Expand All @@ -102,7 +103,8 @@
init(appId: String,
region: String,
autoSessionTrackingInterval: TimeInterval,
options: AWSPinpointAnalyticsPlugin.Options) {
options: AWSPinpointAnalyticsPlugin.Options)
{

Check failure on line 107 in AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Configuration/AWSPinpointAnalyticsPluginConfiguration.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
self.appId = appId
self.region = region
self.autoSessionTrackingInterval = autoSessionTrackingInterval
Expand Down Expand Up @@ -148,7 +150,7 @@

private static func getAutoSessionTrackingInterval(_ configuration: [String: JSONValue]) throws -> TimeInterval {
guard let autoSessionTrackingInterval = configuration[autoSessionTrackingIntervalKey] else {
return Self.defaultAutoSessionTrackingInterval
return defaultAutoSessionTrackingInterval
}

guard case let .number(autoSessionTrackingIntervalValue) = autoSessionTrackingInterval else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

typealias AnalyticsPluginErrorString = (errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion)

struct AnalyticsPluginErrorConstant {
enum AnalyticsPluginErrorConstant {
static let decodeConfigurationError: AnalyticsPluginErrorString = (
"Unable to decode configuration",
"Make sure the plugin configuration is JSONValue"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Amplify
import Foundation
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint

extension PinpointEvent {
public func asAnalyticsEvent() -> AnalyticsEvent {
public extension PinpointEvent {
func asAnalyticsEvent() -> AnalyticsEvent {
var properties: AnalyticsProperties = [:]

for attribute in attributes {
Expand All @@ -26,7 +26,7 @@ extension PinpointEvent {
}
}

extension Array where Element == PinpointEvent {
extension [PinpointEvent] {
func asAnalyticsEventArray() -> [AnalyticsEvent] {
map { $0.asAnalyticsEvent() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import AWSPinpoint
import ClientRuntime
import Foundation

extension AWSPinpoint.BadRequestException: AnalyticsErrorConvertible {
var analyticsError: AnalyticsError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

protocol AnalyticsErrorConvertible {
var analyticsError: AnalyticsError { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import AwsCommonRuntimeKit
import Foundation

enum AnalyticsErrorHelper {
static func getDefaultError(_ error: Error) -> AnalyticsError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint
import AwsCommonRuntimeKit
import Foundation
@_spi(InternalAWSPinpoint) import InternalAWSPinpoint

extension CommonRunTimeError: AnalyticsErrorConvertible {
var analyticsError: AnalyticsError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import XCTest
import AWSPinpointAnalyticsPlugin
import XCTest

// swiftlint:disable:next type_name
class AWSPinpointAnalyticsPluginAmplifyVersionableTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import Amplify
import AWSPinpoint
@_spi(InternalAWSPinpoint) @testable import InternalAWSPinpoint
@testable import AWSPinpointAnalyticsPlugin
@testable import AmplifyTestCommon
import XCTest
@testable import AmplifyTestCommon
@testable import AWSPinpointAnalyticsPlugin
@_spi(InternalAWSPinpoint) @testable import InternalAWSPinpoint

// swiftlint:disable:next type_name
class AWSPinpointAnalyticsPluginClientBehaviorTests: AWSPinpointAnalyticsPluginTestBase {
Expand Down Expand Up @@ -281,9 +281,9 @@ class AWSPinpointAnalyticsPluginClientBehaviorTests: AWSPinpointAnalyticsPluginT
func testRegisterGlobalProperties() async {
mockPinpoint.addGlobalPropertyExpectation = expectation(description: "Add global property called")
mockPinpoint.addGlobalPropertyExpectation?.expectedFulfillmentCount = testProperties.count

analyticsPlugin.registerGlobalProperties(testProperties)

await fulfillment(of: [mockPinpoint.addGlobalPropertyExpectation!], timeout: 1)
XCTAssertEqual(analyticsPlugin.globalProperties.count, testProperties.count)
XCTAssertTrue(mockPinpoint.addGlobalMetricCalled > 0)
Expand All @@ -310,7 +310,7 @@ class AWSPinpointAnalyticsPluginClientBehaviorTests: AWSPinpointAnalyticsPluginT
func testUnregisterGlobalProperties() async {
mockPinpoint.removeGlobalPropertyExpectation = expectation(description: "Remove global property called")
mockPinpoint.removeGlobalPropertyExpectation?.expectedFulfillmentCount = testProperties.count

analyticsPlugin.globalProperties = AtomicDictionary(initialValue: testProperties)
analyticsPlugin.unregisterGlobalProperties(Set<String>(testProperties.keys))

Expand Down Expand Up @@ -365,7 +365,7 @@ class AWSPinpointAnalyticsPluginClientBehaviorTests: AWSPinpointAnalyticsPluginT
await fulfillment(of: [methodWasInvokedOnPlugin], timeout: 1)
mockPinpoint.verifySubmitEvents()
}

/// Given: The device does not have internet access
/// When: AnalyticsPlugin.flushEvents is invoked
/// Then: AWSPinpoint.submitEvents is invoked
Expand Down
Loading
Loading