Skip to content

Commit

Permalink
Upgrade to Xcode 10.2 and satisfy linter (#94)
Browse files Browse the repository at this point in the history
* Upgrade to Xcode 10.2

* Satisfy linter
  • Loading branch information
shoumikhin authored and temrich committed Jan 29, 2019
1 parent f582acd commit 97e1071
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 40 deletions.
19 changes: 11 additions & 8 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
disabled_rules:
- multiple_closures_with_trailing_closure
- xctfail_message

line_length: 100
function_body_length:
warning: 100
error: 200
type_body_length:
warning: 500
error: 1000
cyclomatic_complexity: 15
file_length:
warning: 1000
error: 2000
function_body_length:
warning: 100
error: 200
large_tuple:
warning: 5
line_length: 100
nesting:
type_level:
warning: 3
error: 5
cyclomatic_complexity: 15
type_body_length:
warning: 500
error: 1000
22 changes: 22 additions & 0 deletions Promises.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@
buildPhases = (
OBJ_250 /* Sources */,
OBJ_266 /* Frameworks */,
031D2CA721FEABB60028E3D1 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -1000,6 +1001,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = OBJ_5;
productRefGroup = OBJ_109 /* Products */;
Expand All @@ -1020,6 +1022,26 @@
};
/* End PBXProject section */

/* Begin PBXShellScriptBuildPhase section */
031D2CA721FEABB60028E3D1 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"note: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
OBJ_130 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
8 changes: 8 additions & 0 deletions Promises.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
1 change: 0 additions & 1 deletion Sources/Promises/Promise+All.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,3 @@ public func all<A, B, C, D>(
}
return promise
}

2 changes: 1 addition & 1 deletion Sources/Promises/Promise+Always.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public extension Promise {
/// - work: A block that always executes, no matter if `self` is rejected or fulfilled.
/// - returns: A new pending promise to be resolved with same resolution as `self`.
@discardableResult
public func always(on queue: DispatchQueue = .promises, _ work: @escaping () -> Void) -> Promise {
func always(on queue: DispatchQueue = .promises, _ work: @escaping () -> Void) -> Promise {
let promise = Promise(objCPromise.__onQueue(queue, always: work))
// Keep Swift wrapper alive for chained promise until `ObjCPromise` counterpart is resolved.
objCPromise.__pendingObjects?.add(promise)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Promises/Promise+Any.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public func != <Value: Equatable>(lhs: Maybe<Value?>, rhs: Maybe<Value?>) -> Boo

public func == <Value: Equatable>(lhs: [Maybe<Value>], rhs: [Maybe<Value>]) -> Bool {
if lhs.count != rhs.count { return false }
for (l, r) in zip(lhs, rhs) where l != r { return false }
for (lhs, rhs) in zip(lhs, rhs) where lhs != rhs { return false }
return true
}

Expand All @@ -266,7 +266,7 @@ public func != <Value: Equatable>(lhs: [Maybe<Value>], rhs: [Maybe<Value>]) -> B

public func == <Value: Equatable>(lhs: [Maybe<Value?>], rhs: [Maybe<Value?>]) -> Bool {
if lhs.count != rhs.count { return false }
for (l, r) in zip(lhs, rhs) where l != r { return false }
for (lhs, rhs) in zip(lhs, rhs) where lhs != rhs { return false }
return true
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Promises/Promise+Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import Foundation

public extension Promise {
public typealias Async = (@escaping (Value) -> Void, @escaping (Error) -> Void) throws -> Void
typealias Async = (@escaping (Value) -> Void, @escaping (Error) -> Void) throws -> Void

/// Creates a pending promise and executes `work` block asynchronously on the given `queue`.
/// - parameters:
/// - queue: A queue to invoke the `work` block on.
/// - work: A block to perform any operations needed to resolve the promise.
public convenience init(on queue: DispatchQueue = .promises, _ work: @escaping Async) {
convenience init(on queue: DispatchQueue = .promises, _ work: @escaping Async) {
let objCPromise = ObjCPromise<AnyObject>.__onQueue(queue) { fulfill, reject in
do {
try work({ value in
Expand Down
4 changes: 2 additions & 2 deletions Sources/Promises/Promise+Catch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation

public extension Promise {
public typealias Catch = (Error) -> Void
typealias Catch = (Error) -> Void

/// Creates a pending promise which eventually gets resolved with same resolution as `self`.
/// If `self` is rejected, then `reject` block is executed asynchronously on the given queue.
Expand All @@ -24,7 +24,7 @@ public extension Promise {
/// - reject: A block to handle the error that `self` was rejected with.
/// - returns: A new pending promise.
@discardableResult
public func `catch`(on queue: DispatchQueue = .promises, _ reject: @escaping Catch) -> Promise {
func `catch`(on queue: DispatchQueue = .promises, _ reject: @escaping Catch) -> Promise {
let promise = Promise(objCPromise.__onQueue(queue, catch: {
// Convert `NSError` to `PromiseError`, if applicable.
let error = PromiseError($0) ?? $0
Expand Down
2 changes: 1 addition & 1 deletion Sources/Promises/Promise+Delay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public extension Promise {
/// - interval: Time to wait in seconds.
/// - returns: A new pending promise that fulfills at least `interval` seconds later than `self`,
/// or rejects with the same error immediately.
public func delay(
func delay(
on queue: DispatchQueue = .promises,
_ interval: TimeInterval
) -> Promise<Value> {
Expand Down
7 changes: 4 additions & 3 deletions Sources/Promises/Promise+Do.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
import Foundation

public extension Promise {
public typealias Do<Value> = () throws -> Value
// swiftlint:disable:next type_name
typealias Do<Value> = () throws -> Value

/// Creates a pending promise to be resolved with the return value of `work` block which is
/// executed asynchronously on the given `queue`.
/// - parameters:
/// - queue: A queue to invoke the `work` block on.
/// - work: A block that returns a value used to resolve the new promise.
public convenience init<Value>(on queue: DispatchQueue = .promises, _ work: @escaping Do<Value>) {
convenience init<Value>(on queue: DispatchQueue = .promises, _ work: @escaping Do<Value>) {
let objCPromise = ObjCPromise<AnyObject>.__onQueue(queue) {
do {
let resolution = try work()
Expand All @@ -41,7 +42,7 @@ public extension Promise {
/// - parameters:
/// - queue: A queue to invoke the `work` block on.
/// - work: A block that returns a promise used to resolve the new promise.
public convenience init<Value>(
convenience init<Value>(
on queue: DispatchQueue = .promises,
_ work: @escaping Do<Promise<Value>>
) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Promises/Promise+Recover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public extension Promise {
/// - returns: A new pending promise to use instead of the rejected one that gets resolved with
/// the same resolution as the promise returned from `recovery` block.
@discardableResult
public func recover(
func recover(
on queue: DispatchQueue = .promises,
_ recovery: @escaping (Error) throws -> Promise
) -> Promise {
Expand All @@ -48,7 +48,7 @@ public extension Promise {
/// - returns: A new pending promise to use instead of the rejected one that gets resolved with
/// the value returned from `recovery` block.
@discardableResult
public func recover(
func recover(
on queue: DispatchQueue = .promises,
_ recovery: @escaping (Error) throws -> Value
) -> Promise {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Promises/Promise+Reduce.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Dispatch

public extension Promise {
public typealias Reducer<Element> = (Value, Element) throws -> Promise<Value>
typealias Reducer<Element> = (Value, Element) throws -> Promise<Value>

/// Sequentially reduces a collection of values to a single promise using a given combining block
/// and the value `self` resolves with as initial value.
Expand All @@ -28,7 +28,7 @@ public extension Promise {
/// - returns: A new pending promise returned from the last `reducer` invocation.
/// Or `self` if `items` is empty.
@discardableResult
public func reduce<Element>(
func reduce<Element>(
on queue: DispatchQueue = .promises,
_ items: Element...,
combine reducer: @escaping Reducer<Element>
Expand All @@ -47,7 +47,7 @@ public extension Promise {
/// - returns: A new pending promise returned from the last `reducer` invocation.
/// Or `self` if `items` is empty.
@discardableResult
public func reduce<Container: Sequence>(
func reduce<Container: Sequence>(
on queue: DispatchQueue = .promises,
_ items: Container,
_ reducer: @escaping Reducer<Container.Element>
Expand Down
8 changes: 4 additions & 4 deletions Sources/Promises/Promise+Then.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation

public extension Promise {
public typealias Then<Result> = (Value) throws -> Result
typealias Then<Result> = (Value) throws -> Result

/// Creates a pending promise which eventually gets resolved with the same resolution as the
/// promise returned from `work` block. The `work` block is executed asynchronously on the given
Expand All @@ -27,7 +27,7 @@ public extension Promise {
/// - returns: A new pending promise to be resolved with the same resolution as the promise
/// returned from the `work` block.
@discardableResult
public func then<Result>(
func then<Result>(
on queue: DispatchQueue = .promises,
_ work: @escaping Then<Promise<Result>>
) -> Promise<Result> {
Expand All @@ -54,7 +54,7 @@ public extension Promise {
/// - work: A block to handle the value that `self` was fulfilled with.
/// - returns: A new pending promise to be resolved with the value returned from the `work` block.
@discardableResult
public func then<Result>(
func then<Result>(
on queue: DispatchQueue = .promises,
_ work: @escaping Then<Result>
) -> Promise<Result> {
Expand Down Expand Up @@ -82,7 +82,7 @@ public extension Promise {
/// - work: A block to handle the value that `self` was fulfilled with.
/// - returns: A new pending promise to be resolved with the value passed into the `work` block.
@discardableResult
public func then(
func then(
on queue: DispatchQueue = .promises,
_ work: @escaping Then<Void>
) -> Promise {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Promises/Promise+Timeout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public extension Promise {
/// - returns: A new pending promise that gets either resolved with same resolution as `self` or
/// rejected with `PromiseError.timedOut` error.
@discardableResult
public func timeout(on queue: DispatchQueue = .promises, _ interval: TimeInterval) -> Promise {
func timeout(on queue: DispatchQueue = .promises, _ interval: TimeInterval) -> Promise {
let promise = Promise(objCPromise.__onQueue(queue, timeout: interval))
// Keep Swift wrapper alive for chained promise until `ObjCPromise` counterpart is resolved.
objCPromise.__pendingObjects?.add(promise)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Promises/Promise+Validate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public extension Promise {
/// - returns: A new pending promise that gets either resolved with same resolution as `self` or
/// rejected with `PromiseError.validationFailure` error.
@discardableResult
public func validate(
func validate(
on queue: DispatchQueue = .promises,
_ predicate: @escaping (Value) -> Bool
) -> Promise {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PromisesTestHelpers/PromisesTestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public func != (lhs: Error?, rhs: Error?) -> Bool {
/// Compare two arrays of the same generic type conforming to `Equatable` protocol.
public func == <T: Equatable>(lhs: [T?], rhs: [T?]) -> Bool {
if lhs.count != rhs.count { return false }
for (l, r) in zip(lhs, rhs) where l != r { return false }
for (lhs, rhs) in zip(lhs, rhs) where lhs != rhs { return false }
return true
}

Expand Down
7 changes: 6 additions & 1 deletion Tests/PromisesTests/Promise+AllTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,12 @@ class PromiseAllTests: XCTestCase {
}

// Act.
let combinedPromise = all(promise1, promise2, promise3, promise4).then { number, string, none, double in
let combinedPromise = all(
promise1,
promise2,
promise3,
promise4
).then { number, string, none, double in
XCTAssert(number == expectedValues.0)
XCTAssert(string == expectedValues.1)
XCTAssert(none == expectedValues.2)
Expand Down
2 changes: 1 addition & 1 deletion Tests/PromisesTests/Promise+ReduceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PromiseReduceTests: XCTestCase {
guard partialString.isEmpty else { throw Test.Error.code42 }
count += 1
return Promise(partialString + String(nextNumber))
}.then { string in
}.then { _ in
XCTFail()
}.catch { error in
XCTAssertTrue(error == Test.Error.code42)
Expand Down
12 changes: 6 additions & 6 deletions Tests/PromisesTests/Promise+RetryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PromiseRetryTests: XCTestCase {
return count == 0 ? Promise(42) : Promise(Test.Error.code42)
}.then { value in
XCTAssertEqual(value, 42)
}.catch { error in
}.catch { _ in
XCTFail("Promise should not be resolved with error.")
}

Expand All @@ -49,7 +49,7 @@ class PromiseRetryTests: XCTestCase {
return Promise(42)
}.then { value in
XCTAssertEqual(value, 42)
}.catch { error in
}.catch { _ in
XCTFail("Promise should not be resolved with error.")
}

Expand All @@ -67,7 +67,7 @@ class PromiseRetryTests: XCTestCase {
retry(attempts: customAttempts) { () -> Promise<Int> in
count -= 1
return Promise(Test.Error.code42)
}.then { value in
}.then { _ in
XCTFail("Promise should not be resolved with value.")
}.catch { error in
XCTAssertTrue(error == Test.Error.code42)
Expand Down Expand Up @@ -95,7 +95,7 @@ class PromiseRetryTests: XCTestCase {
return count == 0 ? Promise(42) : Promise(Test.Error.code42)
}.then { value in
XCTAssertEqual(value, 42)
}.catch { error in
}.catch { _ in
XCTFail("Promise should not be resolved with error.")
}

Expand All @@ -122,7 +122,7 @@ class PromiseRetryTests: XCTestCase {
return count == 0 ? Promise(42) : Promise(Test.Error.code42)
}.then { value in
XCTAssertEqual(value, 42)
}.catch { error in
}.catch { _ in
XCTFail("Promise should not be resolved with error.")
}

Expand All @@ -143,7 +143,7 @@ class PromiseRetryTests: XCTestCase {
}) { () -> Promise<Int> in
count -= 1
return count > 1 ? Promise(Test.Error.code42) : Promise(Test.Error.code13)
}.then { value in
}.then { _ in
XCTFail("Promise should not be resolved with value.")
}.catch { error in
XCTAssertTrue(error == Test.Error.code13)
Expand Down

0 comments on commit 97e1071

Please sign in to comment.