mirror of
https://github.com/google/promises
synced 2026-11-09 22:26:00 +05:45
Upgrade to Xcode 10.2 and satisfy linter (#94)
* Upgrade to Xcode 10.2 * Satisfy linter
This commit is contained in:
1 parent
f582acd93f
commit
97e1071d32
19 files changed
+78
-40
No files matched your search
+11
-8
@@ -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
|
||||
@@ -898,6 +898,7 @@
|
||||
buildPhases = (
|
||||
OBJ_250 /* Sources */,
|
||||
OBJ_266 /* Frameworks */,
|
||||
031D2CA721FEABB60028E3D1 /* ShellScript */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
@@ -1000,6 +1001,7 @@
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = OBJ_5;
|
||||
productRefGroup = OBJ_109 /* Products */;
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
@@ -180,4 +180,3 @@ public func all<A, B, C, D>(
|
||||
}
|
||||
return promise
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
@@ -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
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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()
|
||||
@@ -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>>
|
||||
) {
|
||||
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
@@ -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> {
|
||||
@@ -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> {
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.")
|
||||
}
|
||||
|
||||
@@ -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.")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -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.")
|
||||
}
|
||||
|
||||
@@ -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.")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user