Skip to content

Commit

Permalink
Fix all SwiftLint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed May 23, 2024
1 parent d52db7e commit b7ecc1a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
1 change: 0 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sources/TelemetryClient/CryptoHashing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions Sources/TelemetryClient/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/TelemetryClient/SignalEnricher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
28 changes: 14 additions & 14 deletions Sources/TelemetryClient/SignalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)"
}
}
Expand Down
17 changes: 13 additions & 4 deletions Sources/TelemetryClient/TelemetryClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import TVUIKit
#endif

let TelemetryClientVersion = "2.0.0"
let telemetryClientVersion = "2.0.0"

/// Configuration for TelemetryManager
///
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 }
Expand Down

0 comments on commit b7ecc1a

Please sign in to comment.