Skip to content

Commit

Permalink
chore(swift): format config (#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluf22 committed Feb 15, 2024
1 parent e2fd88a commit 2a38b86
Show file tree
Hide file tree
Showing 26 changed files with 36 additions and 238 deletions.
4 changes: 2 additions & 2 deletions clients/algoliasearch-client-swift/.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@
--enable leadingDelimiters
--enable linebreakAtEndOfFile
--enable linebreaks
--enable markTypes
--enable modifierOrder
--enable noExplicitOwnership
--enable numberFormatting
--enable opaqueGenericParameters
--enable organizeDeclarations
--enable preferKeyPath
--enable redundantClosure
--enable redundantExtensionACL
Expand Down Expand Up @@ -144,6 +142,8 @@
--disable applicationMain
--disable blankLinesBetweenImports
--disable fileHeader
--disable markTypes
--disable organizeDeclarations
--disable preferForLoop
--disable redundantBackticks
--disable redundantBreak
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@

import Foundation

// MARK: - CallType

/// Indicate whether the HTTP call performed is of type [read] (GET) or [write] (POST, PUT ..).
/// Used to determine which timeout duration to use.
public enum CallType {
case read
case write
}

// MARK: CustomStringConvertible

extension CallType: CustomStringConvertible {
public var description: String {
switch self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@

import Foundation

// MARK: - DecodingErrorPrettyPrinter

struct DecodingErrorPrettyPrinter: CustomStringConvertible, CustomDebugStringConvertible {
// MARK: Lifecycle

init(decodingError: DecodingError) {
self.decodingError = decodingError
}

// MARK: Internal

let decodingError: DecodingError

var description: String {
Expand All @@ -28,8 +22,6 @@ struct DecodingErrorPrettyPrinter: CustomStringConvertible, CustomDebugStringCon
self.description
}

// MARK: Private

private let prefix = "Decoding error"

private func codingKeyDescription(_ key: CodingKey) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,17 @@

import Foundation

// MARK: - GenericError

public struct GenericError: Error, CustomStringConvertible {
// MARK: Lifecycle

public init(description: String) {
self.description = description
}

// MARK: Public

public var description: String
}

// MARK: - ErrorMessage

public struct ErrorMessage: Codable, CustomStringConvertible {
// MARK: Public

public let description: String

// MARK: Internal

enum CodingKeys: String, CodingKey {
case description = "message"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ import Logging

typealias SwiftLog = Logging.Logger

// MARK: - Logger

public struct Logger {
// MARK: Lifecycle

private init() {}

// MARK: Public

public static var loggingService: Loggable = {
var swiftLog = SwiftLog(label: "com.algolia.searchClientSwift")
print(
Expand All @@ -38,8 +32,6 @@ public struct Logger {
}
}

// MARK: Internal

static func trace(_ message: String) {
self.loggingService.log(level: .trace, message: message)
}
Expand Down Expand Up @@ -69,8 +61,6 @@ public struct Logger {
}
}

// MARK: - LogLevel

public enum LogLevel {
case trace
case debug
Expand Down Expand Up @@ -119,16 +109,12 @@ extension LogLevel {
}
}

// MARK: - Loggable

public protocol Loggable {
var minSeverityLevel: LogLevel { get set }

func log(level: LogLevel, message: String)
}

// MARK: - SwiftLog + Loggable

extension SwiftLog: Loggable {
public var minSeverityLevel: LogLevel {
get {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
import Foundation

public struct Region: StringOption, ProvidingCustomOption {
// MARK: Lifecycle

public init(rawValue: String) {
self.rawValue = rawValue
}

// MARK: Public

public static var us: Self { .init(rawValue: #function) }

/// European (Germany) region for Insights and Analytics APIs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import Foundation

public class RequestOptions {
// MARK: Lifecycle

public init(
headers: [String: String]? = nil,
queryParameters: [String: Any?]? = nil,
Expand All @@ -24,8 +22,6 @@ public class RequestOptions {
self.body = body
}

// MARK: Public

public static func +(lhs: RequestOptions, rhs: RequestOptions?) -> RequestOptions {
guard let rhs else {
return lhs
Expand Down Expand Up @@ -86,8 +82,6 @@ public class RequestOptions {
return self
}

// MARK: Internal

private(set) var headers: [String: String]?
private(set) var queryParameters: [String: Any?]?
private(set) var readTimeout: TimeInterval?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import Foundation

// MARK: - StringOption

public protocol StringOption: Codable, Equatable, RawRepresentable where RawValue == String {}

public extension StringOption {
Expand All @@ -17,8 +15,6 @@ public extension StringOption {
}
}

// MARK: - ProvidingCustomOption

public protocol ProvidingCustomOption {
static func custom(_ value: String) -> Self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import Foundation

open class CodableHelper {
// MARK: Open

open class func decode<T>(_ type: T.Type, from data: Data) -> Swift.Result<T, Error>
where T: Decodable {
Swift.Result { try self.jsonDecoder.decode(type, from: data) }
Expand All @@ -18,8 +16,6 @@ open class CodableHelper {
Swift.Result { try self.jsonEncoder.encode(value) }
}

// MARK: Public

public static var dateFormatter: DateFormatter {
get { customDateFormatter ?? defaultDateFormatter }
set { customDateFormatter = newValue }
Expand All @@ -35,8 +31,6 @@ open class CodableHelper {
set { customJSONEncoder = newValue }
}

// MARK: Private

private static var customDateFormatter: DateFormatter?
private static var defaultDateFormatter: DateFormatter = OpenISO8601DateFormatter()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,42 @@ import Foundation
import AnyCodable
#endif

// MARK: - Bool + JSONEncodable

extension Bool: JSONEncodable {
public func encodeToJSON() -> Any { self }
}

// MARK: - Float + JSONEncodable

extension Float: JSONEncodable {
public func encodeToJSON() -> Any { self }
}

// MARK: - Int + JSONEncodable

extension Int: JSONEncodable {
public func encodeToJSON() -> Any { self }
}

// MARK: - Int32 + JSONEncodable

extension Int32: JSONEncodable {
public func encodeToJSON() -> Any { self }
}

// MARK: - Int64 + JSONEncodable

extension Int64: JSONEncodable {
public func encodeToJSON() -> Any { self }
}

// MARK: - Double + JSONEncodable

extension Double: JSONEncodable {
public func encodeToJSON() -> Any { self }
}

// MARK: - Decimal + JSONEncodable

extension Decimal: JSONEncodable {
public func encodeToJSON() -> Any { self }
}

// MARK: - String + JSONEncodable

extension String: JSONEncodable {
public func encodeToJSON() -> Any { self }
}

// MARK: - URL + JSONEncodable

extension URL: JSONEncodable {
public func encodeToJSON() -> Any { self }
}

// MARK: - UUID + JSONEncodable

extension UUID: JSONEncodable {
public func encodeToJSON() -> Any { self }
}
Expand All @@ -84,24 +64,18 @@ private func encodeIfPossible(_ object: some Any) -> Any {
}
}

// MARK: - Array + JSONEncodable

extension Array: JSONEncodable {
public func encodeToJSON() -> Any {
map(encodeIfPossible)
}
}

// MARK: - Set + JSONEncodable

extension Set: JSONEncodable {
public func encodeToJSON() -> Any {
Array(self).encodeToJSON()
}
}

// MARK: - Dictionary + JSONEncodable

extension Dictionary: JSONEncodable where Key == String {
public func encodeToJSON() -> Any {
var dictionary = [String: Any]()
Expand All @@ -112,8 +86,6 @@ extension Dictionary: JSONEncodable where Key == String {
}
}

// MARK: - Data + JSONEncodable

extension Data: JSONEncodable {
public func encodeToJSON() -> Any {
guard let selfString = String(data: self, encoding: .utf8) else {
Expand All @@ -130,8 +102,6 @@ extension Data: JSONEncodable {
}
}

// MARK: - Date + JSONEncodable

extension Date: JSONEncodable {
public func encodeToJSON() -> Any {
CodableHelper.dateFormatter.string(from: self)
Expand All @@ -153,8 +123,6 @@ public extension JSONEncodable where Self: Encodable {
}
}

// MARK: - String + CodingKey

extension String: CodingKey {
public var stringValue: String {
self
Expand Down Expand Up @@ -284,8 +252,6 @@ extension HTTPURLResponse {
}
}

// MARK: - URLRequest.FormatError

public extension URLRequest {
enum FormatError: LocalizedError {
case missingURL
Expand All @@ -294,8 +260,6 @@ public extension URLRequest {
case invalidPath(String)
case invalidQueryItems

// MARK: Public

public var errorDescription: String? {
let contactUs = "Please contact [email protected] if this problem occurs."
switch self {
Expand Down
Loading

0 comments on commit 2a38b86

Please sign in to comment.