diff --git a/.swiftlint.yml b/.swiftlint.yml index 07cbce1..41adafd 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,6 +1,5 @@ # By default, SwiftLint uses a set of sensible default rules you can adjust: disabled_rules: # rule identifiers turned on by default to exclude from running - - identifier_name - function_body_length - opening_brace - trailing_comma diff --git a/Sources/TelemetryClient/CryptoHashing.swift b/Sources/TelemetryClient/CryptoHashing.swift index aa6bd20..777f196 100644 --- a/Sources/TelemetryClient/CryptoHashing.swift +++ b/Sources/TelemetryClient/CryptoHashing.swift @@ -11,8 +11,8 @@ enum CryptoHashing { /// should be preferred where available. /// [CommonCrypto](https://github.com/apple-oss-distributions/CommonCrypto) provides compatibility with older OS versions, /// apps built with Xcode versions lower than 11 and non-Apple platforms like Linux. - static func sha256(str: String, salt: String) -> String { - if let strData = (str + salt).data(using: String.Encoding.utf8) { + static func sha256(string: String, salt: String) -> String { + if let strData = (string + salt).data(using: String.Encoding.utf8) { #if canImport(CryptoKit) if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) { let digest = SHA256.hash(data: strData) diff --git a/Sources/TelemetryClient/Signal.swift b/Sources/TelemetryClient/Signal.swift index 4e78a4b..1a14ccc 100644 --- a/Sources/TelemetryClient/Signal.swift +++ b/Sources/TelemetryClient/Signal.swift @@ -61,13 +61,13 @@ public struct DefaultSignalPayload: Encodable { "region": Self.region, "appLanguage": Self.appLanguage, "preferredLanguage": Self.preferredLanguage, - "telemetryClientVersion": TelemetryClientVersion, + "telemetryClientVersion": telemetryClientVersion, // new names "TelemetryDeck.AppInfo.buildNumber": Self.buildNumber, "TelemetryDeck.AppInfo.version": Self.appVersion, "TelemetryDeck.AppInfo.versionAndBuildNumber": "\(Self.appVersion) (build \(Self.buildNumber))", - + "TelemetryDeck.Device.architecture": Self.architecture, "TelemetryDeck.Device.modelName": Self.modelName, "TelemetryDeck.Device.operatingSystem": Self.operatingSystem, @@ -89,8 +89,8 @@ public struct DefaultSignalPayload: Encodable { "TelemetryDeck.RunContext.targetEnvironment": Self.targetEnvironment, "TelemetryDeck.SDK.name": "SwiftSDK", - "TelemetryDeck.SDK.nameAndVersion": "SwiftSDK \(TelemetryClientVersion)", - "TelemetryDeck.SDK.version": TelemetryClientVersion, + "TelemetryDeck.SDK.nameAndVersion": "SwiftSDK \(telemetryClientVersion)", + "TelemetryDeck.SDK.version": telemetryClientVersion, "TelemetryDeck.UserPreference.language": Self.preferredLanguage, "TelemetryDeck.UserPreference.region": Self.region, @@ -210,7 +210,7 @@ extension DefaultSignalPayload { var modelIdentifier: String? if let modelData = IORegistryEntryCreateCFProperty(service, "model" as CFString, kCFAllocatorDefault, 0).takeRetainedValue() as? Data { - if let modelIdentifierCString = String(data: modelData, encoding: .utf8)?.cString(using: .utf8) { + if let modelIdentifierCString = String(decoding: modelData, as: UTF8.self).cString(using: .utf8) { modelIdentifier = String(cString: modelIdentifierCString) } } diff --git a/Sources/TelemetryClient/SignalEnricher.swift b/Sources/TelemetryClient/SignalEnricher.swift index 516a853..aedeb12 100644 --- a/Sources/TelemetryClient/SignalEnricher.swift +++ b/Sources/TelemetryClient/SignalEnricher.swift @@ -9,9 +9,9 @@ public protocol SignalEnricher { } extension Dictionary where Key == String, Value == String { - func applying(_ rhs: [String: String]) -> [String: String] { - merging(rhs) { _, rhs in - rhs + func applying(_ other: [String: String]) -> [String: String] { + merging(other) { _, other in + other } } diff --git a/Sources/TelemetryClient/SignalManager.swift b/Sources/TelemetryClient/SignalManager.swift index 74214b6..0432733 100644 --- a/Sources/TelemetryClient/SignalManager.swift +++ b/Sources/TelemetryClient/SignalManager.swift @@ -130,7 +130,7 @@ internal class SignalManager: SignalManageable { } if let data = data { - configuration.logHandler?.log(.debug, message: String(data: data, encoding: .utf8)!) + configuration.logHandler?.log(.debug, message: String(decoding: data, as: UTF8.self)) } } } @@ -189,7 +189,7 @@ private extension SignalManager { } urlRequest.httpBody = body - self.configuration.logHandler?.log(.debug, message: String(data: urlRequest.httpBody!, encoding: .utf8)!) + self.configuration.logHandler?.log(.debug, message: String(decoding: urlRequest.httpBody!, as: UTF8.self)) let task = URLSession.shared.dataTask(with: urlRequest, completionHandler: completionHandler) task.resume() @@ -253,13 +253,13 @@ private extension URLResponse { // Check for valid response in the 200-299 range guard (200 ... 299).contains(statusCode() ?? 0) else { if statusCode() == 401 { - return TelemetryError.Unauthorised + return TelemetryError.unauthorised } else if statusCode() == 403 { - return TelemetryError.Forbidden + return TelemetryError.forbidden } else if statusCode() == 413 { - return TelemetryError.PayloadTooLarge + return TelemetryError.payloadTooLarge } else { - return TelemetryError.InvalidStatusCode(statusCode: statusCode() ?? 0) + return TelemetryError.invalidStatusCode(statusCode: statusCode() ?? 0) } } return nil @@ -269,22 +269,22 @@ private extension URLResponse { // MARK: - Errors private enum TelemetryError: Error { - case Unauthorised - case Forbidden - case PayloadTooLarge - case InvalidStatusCode(statusCode: Int) + case unauthorised + case forbidden + case payloadTooLarge + case invalidStatusCode(statusCode: Int) } extension TelemetryError: LocalizedError { public var errorDescription: String? { switch self { - case .InvalidStatusCode(let statusCode): + case .invalidStatusCode(let statusCode): return "Invalid status code \(statusCode)" - case .Unauthorised: + case .unauthorised: return "Unauthorized (401)" - case .Forbidden: + case .forbidden: return "Forbidden (403)" - case .PayloadTooLarge: + case .payloadTooLarge: return "Payload is too large (413)" } } diff --git a/Sources/TelemetryClient/TelemetryClient.swift b/Sources/TelemetryClient/TelemetryClient.swift index 43a7559..12f1b24 100644 --- a/Sources/TelemetryClient/TelemetryClient.swift +++ b/Sources/TelemetryClient/TelemetryClient.swift @@ -10,7 +10,7 @@ import Foundation import TVUIKit #endif -let TelemetryClientVersion = "2.0.0" +let telemetryClientVersion = "2.0.0" /// Configuration for TelemetryManager /// @@ -217,7 +217,10 @@ public class TelemetryManager { /// /// If you specify a payload, it will be sent in addition to the default payload which includes OS Version, App Version, and more. @_disfavoredOverload - @available(*, deprecated, message: "This call was renamed to `TelemetryDeck.signal(_:parameters:floatValue:customUserID:)`. Please migrate – no fix-it possible due to the changed order of arguments.") + @available( + *, deprecated, + message: "This call was renamed to `TelemetryDeck.signal(_:parameters:floatValue:customUserID:)`. Please migrate – no fix-it possible due to the changed order of arguments." + ) public static func send(_ signalName: String, for customUserID: String? = nil, floatValue: Double? = nil, with parameters: [String: String] = [:]) { TelemetryManager.shared.send(signalName, for: customUserID, floatValue: floatValue, with: parameters) } @@ -277,7 +280,10 @@ public class TelemetryManager { /// If you specify a user identifier here, it will take precedence over the default user identifier specified in the `TelemetryManagerConfiguration`. /// /// If you specify a payload, it will be sent in addition to the default payload which includes OS Version, App Version, and more. - @available(*, deprecated, message: "This call was renamed to `TelemetryDeck.signal(_:parameters:floatValue:customUserID:)`. Please migrate – no fix-it possible due to the changed order of arguments.") + @available( + *, deprecated, + message: "This call was renamed to `TelemetryDeck.signal(_:parameters:floatValue:customUserID:)`. Please migrate – no fix-it possible due to the changed order of arguments." + ) public func send(_ signalName: String, with parameters: [String: String] = [:]) { send(signalName, for: nil, floatValue: nil, with: parameters) } @@ -288,7 +294,10 @@ public class TelemetryManager { /// /// If you specify a payload, it will be sent in addition to the default payload which includes OS Version, App Version, and more. @_disfavoredOverload - @available(*, deprecated, message: "This call was renamed to `TelemetryDeck.signal(_:parameters:floatValue:customUserID:)`. Please migrate – no fix-it possible due to the changed order of arguments.") + @available( + *, deprecated, + message: "This call was renamed to `TelemetryDeck.signal(_:parameters:floatValue:customUserID:)`. Please migrate – no fix-it possible due to the changed order of arguments." + ) public func send(_ signalName: String, for customUserID: String? = nil, floatValue: Double? = nil, with parameters: [String: String] = [:]) { // make sure to not send any signals when run by Xcode via SwiftUI previews guard !self.configuration.swiftUIPreviewMode, !self.configuration.analyticsDisabled else { return }