diff --git a/.swiftlint.yml b/.swiftlint.yml index 37baa8f0c..caae28055 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,6 +1,5 @@ disabled_rules: - todo - - variable_name - force_try included: @@ -18,3 +17,13 @@ trailing_comma: line_length: ignores_comments: true ignores_function_declarations: true + +identifier_name: + excluded: + - x + - l + - r + - e + - n1 + - n2 + - to diff --git a/Sources/Nimble/Adapters/AdapterProtocols.swift b/Sources/Nimble/Adapters/AdapterProtocols.swift index 2e58fdf94..abaf5328f 100644 --- a/Sources/Nimble/Adapters/AdapterProtocols.swift +++ b/Sources/Nimble/Adapters/AdapterProtocols.swift @@ -13,5 +13,6 @@ public protocol AssertionHandler { /// /// @see AssertionHandler public var NimbleAssertionHandler: AssertionHandler = { () -> AssertionHandler in + // swiftlint:disable:previous identifier_name return isXCTestAvailable() ? NimbleXCTestHandler() : NimbleXCTestUnavailableHandler() }() diff --git a/Sources/Nimble/Adapters/NMBExpectation.swift b/Sources/Nimble/Adapters/NMBExpectation.swift index 5e1afd573..3c53bcafa 100644 --- a/Sources/Nimble/Adapters/NMBExpectation.swift +++ b/Sources/Nimble/Adapters/NMBExpectation.swift @@ -30,11 +30,13 @@ internal struct ObjCMatcherWrapper: Matcher { // Equivalent to Expectation, but for Nimble's Objective-C interface public class NMBExpectation: NSObject { + // swiftlint:disable identifier_name internal let _actualBlock: () -> NSObject? internal var _negative: Bool internal let _file: FileString internal let _line: UInt internal var _timeout: TimeInterval = 1.0 + // swiftlint:enable identifier_name @objc public init(actualBlock: @escaping () -> NSObject?, negative: Bool, file: FileString, line: UInt) { self._actualBlock = actualBlock diff --git a/Sources/Nimble/Adapters/NMBObjCMatcher.swift b/Sources/Nimble/Adapters/NMBObjCMatcher.swift index 0288b75ba..c11a2cdf0 100644 --- a/Sources/Nimble/Adapters/NMBObjCMatcher.swift +++ b/Sources/Nimble/Adapters/NMBObjCMatcher.swift @@ -8,8 +8,10 @@ public typealias FullMatcherBlock = (_ actualExpression: Expression, _ // swiftlint:enable line_length public class NMBObjCMatcher: NSObject, NMBMatcher { + // swiftlint:disable identifier_name let _match: MatcherBlock let _doesNotMatch: MatcherBlock + // swiftlint:enable identifier_name let canMatchNil: Bool public init(canMatchNil: Bool, matcher: @escaping MatcherBlock, notMatcher: @escaping MatcherBlock) { diff --git a/Sources/Nimble/Adapters/NimbleXCTestHandler.swift b/Sources/Nimble/Adapters/NimbleXCTestHandler.swift index de3844b42..4be22e12d 100644 --- a/Sources/Nimble/Adapters/NimbleXCTestHandler.swift +++ b/Sources/Nimble/Adapters/NimbleXCTestHandler.swift @@ -42,6 +42,7 @@ class NimbleXCTestUnavailableHandler: AssertionHandler { private(set) var currentTestCase: XCTestCase? + // swiftlint:disable:next identifier_name private var stashed_swift_reportFatalErrorsToDebugger: Bool = false @objc func testCaseWillStart(_ testCase: XCTestCase) { diff --git a/Sources/Nimble/DSL.swift b/Sources/Nimble/DSL.swift index 69179be05..7ff771729 100644 --- a/Sources/Nimble/DSL.swift +++ b/Sources/Nimble/DSL.swift @@ -44,11 +44,12 @@ internal func nimblePrecondition( let result = expr() if !result { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - let e = NSException( + let exception = NSException( name: NSExceptionName(name()), reason: message(), - userInfo: nil) - e.raise() + userInfo: nil + ) + exception.raise() #else preconditionFailure("\(name()) - \(message())", file: file, line: line) #endif diff --git a/Sources/Nimble/ExpectationMessage.swift b/Sources/Nimble/ExpectationMessage.swift index 992ee0ef9..9c41ae242 100644 --- a/Sources/Nimble/ExpectationMessage.swift +++ b/Sources/Nimble/ExpectationMessage.swift @@ -75,6 +75,7 @@ public indirect enum ExpectationMessage { } internal func visitLeafs(_ f: (ExpectationMessage) -> ExpectationMessage) -> ExpectationMessage { + // swiftlint:disable:previous identifier_name switch self { case .fail, .expectedTo, .expectedActualValueTo, .expectedCustomValueTo: return f(self) @@ -90,6 +91,7 @@ public indirect enum ExpectationMessage { /// Replaces a primary expectation with one returned by f. Preserves all composite expectations /// that were built upon it (aka - all appended(message:) and appended(details:). public func replacedExpectation(_ f: @escaping (ExpectationMessage) -> ExpectationMessage) -> ExpectationMessage { + // swiftlint:disable:previous identifier_name func walk(_ msg: ExpectationMessage) -> ExpectationMessage { switch msg { case .fail, .expectedTo, .expectedActualValueTo, .expectedCustomValueTo: @@ -181,28 +183,28 @@ public indirect enum ExpectationMessage { extension FailureMessage { internal func toExpectationMessage() -> ExpectationMessage { - let defaultMsg = FailureMessage() - if expected != defaultMsg.expected || _stringValueOverride != nil { + let defaultMessage = FailureMessage() + if expected != defaultMessage.expected || _stringValueOverride != nil { return .fail(stringValue) } - var msg: ExpectationMessage = .fail(userDescription ?? "") + var message: ExpectationMessage = .fail(userDescription ?? "") if actualValue != "" && actualValue != nil { - msg = .expectedCustomValueTo(postfixMessage, actualValue ?? "") - } else if postfixMessage != defaultMsg.postfixMessage { + message = .expectedCustomValueTo(postfixMessage, actualValue ?? "") + } else if postfixMessage != defaultMessage.postfixMessage { if actualValue == nil { - msg = .expectedTo(postfixMessage) + message = .expectedTo(postfixMessage) } else { - msg = .expectedActualValueTo(postfixMessage) + message = .expectedActualValueTo(postfixMessage) } } - if postfixActual != defaultMsg.postfixActual { - msg = .appends(msg, postfixActual) + if postfixActual != defaultMessage.postfixActual { + message = .appends(message, postfixActual) } - if let m = extendedMessage { - msg = .details(msg, m) + if let extended = extendedMessage { + message = .details(message, extended) } - return msg + return message } } diff --git a/Sources/Nimble/Expression.swift b/Sources/Nimble/Expression.swift index 5a233fd99..b6b2ee30f 100644 --- a/Sources/Nimble/Expression.swift +++ b/Sources/Nimble/Expression.swift @@ -24,8 +24,10 @@ internal func memoizedClosure(_ closure: @escaping () throws -> T) -> (Bool) /// This provides a common consumable API for matchers to utilize to allow /// Nimble to change internals to how the captured closure is managed. public struct Expression { + // swiftlint:disable identifier_name internal let _expression: (Bool) throws -> T? internal let _withoutCaching: Bool + // swiftlint:enable identifier_name public let location: SourceLocation public let isClosure: Bool diff --git a/Sources/Nimble/FailureMessage.swift b/Sources/Nimble/FailureMessage.swift index 2bc57ebd4..503b540e8 100644 --- a/Sources/Nimble/FailureMessage.swift +++ b/Sources/Nimble/FailureMessage.swift @@ -28,6 +28,7 @@ public class FailureMessage: NSObject { } } + // swiftlint:disable:next identifier_name internal var _stringValueOverride: String? internal var hasOverriddenStringValue: Bool { return _stringValueOverride != nil diff --git a/Sources/Nimble/Matchers/BeCloseTo.swift b/Sources/Nimble/Matchers/BeCloseTo.swift index 34fa1b827..7e386e662 100644 --- a/Sources/Nimble/Matchers/BeCloseTo.swift +++ b/Sources/Nimble/Matchers/BeCloseTo.swift @@ -1,5 +1,6 @@ import Foundation +// swiftlint:disable:next identifier_name public let DefaultDelta = 0.0001 internal func isCloseTo(_ actualValue: NMBDoubleConvertible?, @@ -36,8 +37,10 @@ public func beCloseTo(_ expectedValue: NMBDoubleConvertible, within delta: Doubl #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) public class NMBObjCBeCloseToMatcher: NSObject, NMBMatcher { + // swiftlint:disable identifier_name var _expected: NSNumber var _delta: CDouble + // swiftlint:enable identifier_name init(expected: NSNumber, within: CDouble) { _expected = expected _delta = within @@ -98,14 +101,17 @@ public func beCloseTo(_ expectedValues: [Double], within delta: Double = Default infix operator ≈ : ComparisonPrecedence +// swiftlint:disable:next identifier_name public func ≈(lhs: Expectation<[Double]>, rhs: [Double]) { lhs.to(beCloseTo(rhs)) } +// swiftlint:disable:next identifier_name public func ≈(lhs: Expectation, rhs: NMBDoubleConvertible) { lhs.to(beCloseTo(rhs)) } +// swiftlint:disable:next identifier_name public func ≈(lhs: Expectation, rhs: (expected: NMBDoubleConvertible, delta: Double)) { lhs.to(beCloseTo(rhs.expected, within: rhs.delta)) } @@ -121,6 +127,7 @@ precedencegroup PlusMinusOperatorPrecedence { } infix operator ± : PlusMinusOperatorPrecedence +// swiftlint:disable:next identifier_name public func ±(lhs: NMBDoubleConvertible, rhs: Double) -> (expected: NMBDoubleConvertible, delta: Double) { return (expected: lhs, delta: rhs) } diff --git a/Sources/Nimble/Matchers/PostNotification.swift b/Sources/Nimble/Matchers/PostNotification.swift index 0708fa7ca..62dc5c805 100644 --- a/Sources/Nimble/Matchers/PostNotification.swift +++ b/Sources/Nimble/Matchers/PostNotification.swift @@ -16,10 +16,10 @@ internal class NotificationCollector { func startObserving() { // swiftlint:disable:next line_length - self.token = self.notificationCenter.addObserver(forName: nil, object: nil, queue: nil, using: { [weak self] n in + self.token = self.notificationCenter.addObserver(forName: nil, object: nil, queue: nil) { [weak self] notification in // linux-swift gets confused by .append(n) - self?.observedNotifications.append(n) - }) + self?.observedNotifications.append(notification) + } } deinit { diff --git a/Sources/Nimble/Matchers/Predicate.swift b/Sources/Nimble/Matchers/Predicate.swift index f8123443f..1eb48e26e 100644 --- a/Sources/Nimble/Matchers/Predicate.swift +++ b/Sources/Nimble/Matchers/Predicate.swift @@ -218,6 +218,7 @@ extension Predicate: Matcher { extension Predicate { // Someday, make this public? Needs documentation internal func after(f: @escaping (Expression, PredicateResult) throws -> PredicateResult) -> Predicate { + // swiftlint:disable:previous identifier_name return Predicate { actual -> PredicateResult in let result = try self.satisfies(actual) return try f(actual, result) diff --git a/Sources/Nimble/Matchers/RaisesException.swift b/Sources/Nimble/Matchers/RaisesException.swift index 3e7f2dfc5..b556ff0c7 100644 --- a/Sources/Nimble/Matchers/RaisesException.swift +++ b/Sources/Nimble/Matchers/RaisesException.swift @@ -117,10 +117,12 @@ internal func exceptionMatchesNonNilFieldsOrClosure( } public class NMBObjCRaiseExceptionMatcher: NSObject, NMBMatcher { + // swiftlint:disable identifier_name internal var _name: String? internal var _reason: String? internal var _userInfo: NSDictionary? internal var _block: ((NSException) -> Void)? + // swiftlint:enable identifier_name internal init(name: String?, reason: String?, userInfo: NSDictionary?, block: ((NSException) -> Void)?) { _name = name diff --git a/Sources/Nimble/Utils/Functional.swift b/Sources/Nimble/Utils/Functional.swift index 6c5126a41..2bd650162 100644 --- a/Sources/Nimble/Utils/Functional.swift +++ b/Sources/Nimble/Utils/Functional.swift @@ -1,9 +1,9 @@ import Foundation extension Sequence { - internal func all(_ fn: (Iterator.Element) -> Bool) -> Bool { + internal func all(_ predicate: (Iterator.Element) -> Bool) -> Bool { for item in self { - if !fn(item) { + if !predicate(item) { return false } } diff --git a/Tests/NimbleTests/Matchers/ThrowErrorTest.swift b/Tests/NimbleTests/Matchers/ThrowErrorTest.swift index 5a1ff6e88..7a7253fc0 100644 --- a/Tests/NimbleTests/Matchers/ThrowErrorTest.swift +++ b/Tests/NimbleTests/Matchers/ThrowErrorTest.swift @@ -30,8 +30,10 @@ func == (lhs: EquatableError, rhs: EquatableError) -> Bool { } enum CustomDebugStringConvertibleError: Error { + // swiftlint:disable identifier_name case a case b + // swiftlint:enable identifier_name } extension CustomDebugStringConvertibleError: CustomDebugStringConvertible {