diff --git a/.swiftlint.yml b/.swiftlint.yml
index a3d9f70..c79ff47 100644
--- a/.swiftlint.yml
+++ b/.swiftlint.yml
@@ -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
diff --git a/Promises.xcodeproj/project.pbxproj b/Promises.xcodeproj/project.pbxproj
index 06eef17..a17bbbd 100644
--- a/Promises.xcodeproj/project.pbxproj
+++ b/Promises.xcodeproj/project.pbxproj
@@ -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;
diff --git a/Promises.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Promises.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
new file mode 100644
index 0000000..18d9810
--- /dev/null
+++ b/Promises.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
@@ -0,0 +1,8 @@
+
+
+
+
+ IDEDidComputeMac32BitWarning
+
+
+
diff --git a/Sources/Promises/Promise+All.swift b/Sources/Promises/Promise+All.swift
index f461055..48ef3fb 100644
--- a/Sources/Promises/Promise+All.swift
+++ b/Sources/Promises/Promise+All.swift
@@ -180,4 +180,3 @@ public func all(
}
return promise
}
-
diff --git a/Sources/Promises/Promise+Always.swift b/Sources/Promises/Promise+Always.swift
index 5f45e28..836cf46 100644
--- a/Sources/Promises/Promise+Always.swift
+++ b/Sources/Promises/Promise+Always.swift
@@ -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)
diff --git a/Sources/Promises/Promise+Any.swift b/Sources/Promises/Promise+Any.swift
index b367fe4..26e2992 100644
--- a/Sources/Promises/Promise+Any.swift
+++ b/Sources/Promises/Promise+Any.swift
@@ -256,7 +256,7 @@ public func != (lhs: Maybe, rhs: Maybe) -> Boo
public func == (lhs: [Maybe], rhs: [Maybe]) -> 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 != (lhs: [Maybe], rhs: [Maybe]) -> B
public func == (lhs: [Maybe], rhs: [Maybe]) -> 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
}
diff --git a/Sources/Promises/Promise+Async.swift b/Sources/Promises/Promise+Async.swift
index aa7227e..9e33db7 100644
--- a/Sources/Promises/Promise+Async.swift
+++ b/Sources/Promises/Promise+Async.swift
@@ -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.__onQueue(queue) { fulfill, reject in
do {
try work({ value in
diff --git a/Sources/Promises/Promise+Catch.swift b/Sources/Promises/Promise+Catch.swift
index 53378b8..bcb4e54 100644
--- a/Sources/Promises/Promise+Catch.swift
+++ b/Sources/Promises/Promise+Catch.swift
@@ -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
diff --git a/Sources/Promises/Promise+Delay.swift b/Sources/Promises/Promise+Delay.swift
index 9a8ba09..dff1db2 100644
--- a/Sources/Promises/Promise+Delay.swift
+++ b/Sources/Promises/Promise+Delay.swift
@@ -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 {
diff --git a/Sources/Promises/Promise+Do.swift b/Sources/Promises/Promise+Do.swift
index 624d884..05292dc 100644
--- a/Sources/Promises/Promise+Do.swift
+++ b/Sources/Promises/Promise+Do.swift
@@ -15,14 +15,15 @@
import Foundation
public extension Promise {
- public typealias Do = () throws -> Value
+ // swiftlint:disable:next type_name
+ typealias Do = () 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(on queue: DispatchQueue = .promises, _ work: @escaping Do) {
+ convenience init(on queue: DispatchQueue = .promises, _ work: @escaping Do) {
let objCPromise = ObjCPromise.__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(
+ convenience init(
on queue: DispatchQueue = .promises,
_ work: @escaping Do>
) {
diff --git a/Sources/Promises/Promise+Recover.swift b/Sources/Promises/Promise+Recover.swift
index 6db8299..e8ffa4b 100644
--- a/Sources/Promises/Promise+Recover.swift
+++ b/Sources/Promises/Promise+Recover.swift
@@ -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 {
diff --git a/Sources/Promises/Promise+Reduce.swift b/Sources/Promises/Promise+Reduce.swift
index c4fe3d3..2ff1cab 100644
--- a/Sources/Promises/Promise+Reduce.swift
+++ b/Sources/Promises/Promise+Reduce.swift
@@ -15,7 +15,7 @@
import Dispatch
public extension Promise {
- public typealias Reducer = (Value, Element) throws -> Promise
+ typealias Reducer = (Value, Element) throws -> Promise
/// 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(
+ func reduce(
on queue: DispatchQueue = .promises,
_ items: Element...,
combine reducer: @escaping Reducer
@@ -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(
+ func reduce(
on queue: DispatchQueue = .promises,
_ items: Container,
_ reducer: @escaping Reducer
diff --git a/Sources/Promises/Promise+Then.swift b/Sources/Promises/Promise+Then.swift
index a3f4746..2e7ffef 100644
--- a/Sources/Promises/Promise+Then.swift
+++ b/Sources/Promises/Promise+Then.swift
@@ -15,7 +15,7 @@
import Foundation
public extension Promise {
- public typealias Then = (Value) throws -> Result
+ typealias Then = (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(
+ func then(
on queue: DispatchQueue = .promises,
_ work: @escaping Then>
) -> Promise {
@@ -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(
+ func then(
on queue: DispatchQueue = .promises,
_ work: @escaping Then
) -> Promise {
@@ -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
) -> Promise {
diff --git a/Sources/Promises/Promise+Timeout.swift b/Sources/Promises/Promise+Timeout.swift
index 1498f68..b5fd413 100644
--- a/Sources/Promises/Promise+Timeout.swift
+++ b/Sources/Promises/Promise+Timeout.swift
@@ -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)
diff --git a/Sources/Promises/Promise+Validate.swift b/Sources/Promises/Promise+Validate.swift
index f26a95b..548d4a3 100644
--- a/Sources/Promises/Promise+Validate.swift
+++ b/Sources/Promises/Promise+Validate.swift
@@ -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 {
diff --git a/Sources/PromisesTestHelpers/PromisesTestHelpers.swift b/Sources/PromisesTestHelpers/PromisesTestHelpers.swift
index 19870b8..31b5ee0 100644
--- a/Sources/PromisesTestHelpers/PromisesTestHelpers.swift
+++ b/Sources/PromisesTestHelpers/PromisesTestHelpers.swift
@@ -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 == (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
}
diff --git a/Tests/PromisesTests/Promise+AllTests.swift b/Tests/PromisesTests/Promise+AllTests.swift
index e3c8aae..8199a75 100644
--- a/Tests/PromisesTests/Promise+AllTests.swift
+++ b/Tests/PromisesTests/Promise+AllTests.swift
@@ -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)
diff --git a/Tests/PromisesTests/Promise+ReduceTests.swift b/Tests/PromisesTests/Promise+ReduceTests.swift
index 08f4218..71c31b6 100644
--- a/Tests/PromisesTests/Promise+ReduceTests.swift
+++ b/Tests/PromisesTests/Promise+ReduceTests.swift
@@ -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)
diff --git a/Tests/PromisesTests/Promise+RetryTests.swift b/Tests/PromisesTests/Promise+RetryTests.swift
index 11406f4..fb925be 100644
--- a/Tests/PromisesTests/Promise+RetryTests.swift
+++ b/Tests/PromisesTests/Promise+RetryTests.swift
@@ -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 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 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)