Skip to content

Commit

Permalink
Update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kolyasev committed Jul 11, 2022
1 parent a997ffa commit 33e03c9
Show file tree
Hide file tree
Showing 22 changed files with 171 additions and 270 deletions.
7 changes: 7 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
included:
- Sources
- Tests

disabled_rules:
- identifier_name
- todo
1 change: 0 additions & 1 deletion Sources/Libraries/Atomic/Atomic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public final class Atomic<Value> {
_value = value
}


/// Atomically replaces the contents of the variable.
///
/// Returns the old value.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftJSONRPC/Client/RPCClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open class RPCClient {

// MARK: - Properties

public var requestRetrier: RequestRetrier? = nil
public var requestRetrier: RequestRetrier?

public var coder = Coder()

Expand Down
8 changes: 3 additions & 5 deletions Sources/SwiftJSONRPC/Client/Retrier/RequestRetrier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
//
// ----------------------------------------------------------------------------

public protocol RequestRetrier
{
// MARK: - Functions
public protocol RequestRetrier {

// MARK: - Functions

func should(client: RPCClient, retryRequest request: Request, afterResponse response: Response) -> Bool

}

// ----------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion Sources/SwiftJSONRPC/Coder/Coder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct Coder {

func decode<Result: InvocationResult>(_ type: Result.Type, from result: Response.Result) throws -> Result {
guard Result.self != VoidInvocationResult.self else {
return VoidInvocationResult() as! Result
return VoidInvocationResult() as! Result // swiftlint:disable:this force_cast
}
do {
let data = try JSONSerialization.data(withJSONObject: result, options: .fragmentsAllowed)
Expand Down
6 changes: 1 addition & 5 deletions Sources/SwiftJSONRPC/Error/InvocationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
//
// ----------------------------------------------------------------------------

public enum InvocationError: Error
{
public enum InvocationError: Error {
case applicationError(cause: Error)
case rpcError(error: RPCError)
case canceled
}

// ----------------------------------------------------------------------------

34 changes: 13 additions & 21 deletions Sources/SwiftJSONRPC/Error/RPCError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,28 @@
//
// ----------------------------------------------------------------------------

public struct RPCError: Error
{
// MARK: - Construction
public struct RPCError: Error {

init(code: Int, message: String, data: Any?)
{
// Init instance variables
self.code = code
self.message = message
self.data = data
}
// MARK: - Properties

// MARK: - Properties
public let code: Int

public let code: Int
public let message: String

public let message: String
public let data: Any?

public let data: Any?
// MARK: - Initialization

init(code: Int, message: String, data: Any?) {
self.code = code
self.message = message
self.data = data
}
}

// ----------------------------------------------------------------------------
extension RPCError {

extension RPCError
{
// MARK: - Constants
// MARK: - Constants

/// Invalid JSON was received by the server.
/// An error occurred on the server while parsing the JSON text.
Expand All @@ -51,6 +46,3 @@ extension RPCError
public static let internalError = RPCError(code: -32603, message: "Internal error", data: nil)

}

// ----------------------------------------------------------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
//
// ----------------------------------------------------------------------------

open class DefaultHTTPRequestAdapter: HTTPRequestAdapter
{
// MARK: - Construction
open class DefaultHTTPRequestAdapter: HTTPRequestAdapter {

// MARK: - Initialization

public init() { }

// MARK: - Functions
// MARK: - Functions

open func adapt(request: HTTPRequest) -> HTTPRequest {
return request
}

}

// ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
//
// ----------------------------------------------------------------------------

open class DefaultHTTPResponseAdapter: HTTPResponseAdapter
{
// MARK: - Construction
open class DefaultHTTPResponseAdapter: HTTPResponseAdapter {

// MARK: - Initialization

public init() { }

// MARK: - Functions
// MARK: - Functions

open func adapt(response: HTTPResponse, forRequest request: HTTPRequest) throws -> HTTPResponse
{
open func adapt(response: HTTPResponse, forRequest request: HTTPRequest) throws -> HTTPResponse {
guard (200..<300).contains(response.code) else {
throw HTTPResponseStatusCodeError(cause: nil)
}

return response
}

}

// ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
//
// ----------------------------------------------------------------------------

public protocol HTTPRequestAdapter
{
// MARK: - Functions
public protocol HTTPRequestAdapter {

// MARK: - Functions

func adapt(request: HTTPRequest) throws -> HTTPRequest

}

// ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
//
// ----------------------------------------------------------------------------

public protocol HTTPResponseAdapter
{
// MARK: - Functions
public protocol HTTPResponseAdapter {

// MARK: - Functions

func adapt(response: HTTPResponse, forRequest request: HTTPRequest) throws -> HTTPResponse

}

// ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension HTTPRequest: Equatable {

// MARK: - Functions

public static func ==(lhs: HTTPRequest, rhs: HTTPRequest) -> Bool {
public static func == (lhs: HTTPRequest, rhs: HTTPRequest) -> Bool {
return lhs.method == rhs.method &&
lhs.url == rhs.url &&
lhs.headers == rhs.headers &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

import Foundation

// ----------------------------------------------------------------------------
public struct HTTPResponse {

public struct HTTPResponse
{
// MARK: - Properties
// MARK: - Properties

public var url: URL

Expand All @@ -23,5 +21,3 @@ public struct HTTPResponse
public var body: Data

}

// ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct URLSessionHTTPClient: HTTPClient {

}

extension HTTPRequest {
extension HTTPRequest {

// MARK: - Functions

Expand Down
Loading

0 comments on commit 33e03c9

Please sign in to comment.