Skip to content

Commit

Permalink
[SwiftLint] Remove identifier_name from disabled_rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Jul 6, 2018
1 parent 50fa589 commit 6a6d499
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 21 deletions.
11 changes: 10 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
disabled_rules:
- todo
- variable_name
- force_try

included:
Expand All @@ -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
1 change: 1 addition & 0 deletions Sources/Nimble/Adapters/AdapterProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public protocol AssertionHandler {
///
/// @see AssertionHandler
public var NimbleAssertionHandler: AssertionHandler = { () -> AssertionHandler in
// swiftlint:disable:previous identifier_name
return isXCTestAvailable() ? NimbleXCTestHandler() : NimbleXCTestUnavailableHandler()
}()
2 changes: 2 additions & 0 deletions Sources/Nimble/Adapters/NMBExpectation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Sources/Nimble/Adapters/NMBObjCMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public typealias FullMatcherBlock = (_ actualExpression: Expression<NSObject>, _
// 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) {
Expand Down
1 change: 1 addition & 0 deletions Sources/Nimble/Adapters/NimbleXCTestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions Sources/Nimble/DSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions Sources/Nimble/ExpectationMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/Nimble/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ internal func memoizedClosure<T>(_ 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<T> {
// 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

Expand Down
1 change: 1 addition & 0 deletions Sources/Nimble/FailureMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class FailureMessage: NSObject {
}
}

// swiftlint:disable:next identifier_name
internal var _stringValueOverride: String?
internal var hasOverriddenStringValue: Bool {
return _stringValueOverride != nil
Expand Down
7 changes: 7 additions & 0 deletions Sources/Nimble/Matchers/BeCloseTo.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation

// swiftlint:disable:next identifier_name
public let DefaultDelta = 0.0001

internal func isCloseTo(_ actualValue: NMBDoubleConvertible?,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<NMBDoubleConvertible>, rhs: NMBDoubleConvertible) {
lhs.to(beCloseTo(rhs))
}

// swiftlint:disable:next identifier_name
public func (lhs: Expectation<NMBDoubleConvertible>, rhs: (expected: NMBDoubleConvertible, delta: Double)) {
lhs.to(beCloseTo(rhs.expected, within: rhs.delta))
}
Expand All @@ -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)
}
6 changes: 3 additions & 3 deletions Sources/Nimble/Matchers/PostNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions Sources/Nimble/Matchers/Predicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ extension Predicate: Matcher {
extension Predicate {
// Someday, make this public? Needs documentation
internal func after(f: @escaping (Expression<T>, PredicateResult) throws -> PredicateResult) -> Predicate<T> {
// swiftlint:disable:previous identifier_name
return Predicate { actual -> PredicateResult in
let result = try self.satisfies(actual)
return try f(actual, result)
Expand Down
2 changes: 2 additions & 0 deletions Sources/Nimble/Matchers/RaisesException.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sources/Nimble/Utils/Functional.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/NimbleTests/Matchers/ThrowErrorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6a6d499

Please sign in to comment.