Skip to content

Commit

Permalink
Add additional opt in rules for SwiftLint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Chiang committed Dec 6, 2018
1 parent f35e043 commit 4e8e9bc
Show file tree
Hide file tree
Showing 34 changed files with 163 additions and 144 deletions.
18 changes: 18 additions & 0 deletions Bluejay/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,21 @@ large_tuple:
identifier_name:
excluded:
- id

opt_in_rules:
- closure_end_indentation
- closure_spacing
- empty_count
- explicit_init
- fatal_error_message
- first_where
- multiline_parameters
- operator_usage_whitespace
- private_outlet
- trailing_closure
- unneeded_parentheses_in_closure_argument
- implicit_return
- prohibited_super_call
- redundant_nil_coalescing
- sorted_imports
- let_var_whitespace
14 changes: 6 additions & 8 deletions Bluejay/Bluejay/Bluejay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

/**
Bluejay is a simple wrapper around CoreBluetooth that focuses on making a common usage case as straight forward as possible: a single connected peripheral that the user is interacting with regularly (think most personal electronics devices that have an associated iOS app: fitness trackers, guitar amps, etc).
Expand Down Expand Up @@ -980,7 +980,7 @@ extension Bluejay: CBCentralManagerDelegate {
// try to trigger a reconnect if we have a stored
// peripheral
if let id = peripheralIdentifierToRestore {
connect(id, timeout: previousConnectionTimeout ?? .none, completion: { _ in })
connect(id, timeout: previousConnectionTimeout ?? .none) { _ in }
}

return
Expand All @@ -996,7 +996,7 @@ extension Bluejay: CBCentralManagerDelegate {
case .connecting:
precondition(connectedPeripheral == nil,
"Connected peripheral is not nil during willRestoreState for state: connecting.")
connect(PeripheralIdentifier(uuid: cbPeripheral.identifier), timeout: .none, completion: { _ in})
connect(PeripheralIdentifier(uuid: cbPeripheral.identifier), timeout: .none, completion: { _ in })
case .connected:
precondition(connectingPeripheral == nil,
"Connecting peripheral is not nil during willRestoreState for state: connected.")
Expand All @@ -1021,7 +1021,7 @@ extension Bluejay: CBCentralManagerDelegate {
When connected, update Bluejay's states by updating the values for `connectingPeripheral`, `connectedPeripheral`, and `shouldAutoReconnect`. Also, make sure to broadcast the event to observers, and notify the queue so that the current operation in-flight can process this event and get a chance to finish.
*/
public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
let backgroundTask = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
let backgroundTask = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)

log("Did connect to: \(peripheral.name ?? peripheral.identifier.uuidString)")

Expand Down Expand Up @@ -1049,7 +1049,7 @@ extension Bluejay: CBCentralManagerDelegate {
*/
public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
// swiftlint:disable:previous cyclomatic_complexity
let backgroundTask = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
let backgroundTask = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)

let peripheralString = peripheral.name ?? peripheral.identifier.uuidString
let errorString = error?.localizedDescription
Expand Down Expand Up @@ -1167,9 +1167,7 @@ extension Bluejay: CBCentralManagerDelegate {
log("Disconnect clean up: issuing reconnect to: \(peripheral.name ?? peripheral.identifier.uuidString)")
weakSelf.connect(
PeripheralIdentifier(uuid: peripheral.identifier),
timeout: weakSelf.previousConnectionTimeout ?? .none,
completion: {_ in }
)
timeout: weakSelf.previousConnectionTimeout ?? .none) { _ in }
}

log("End of disconnect clean up.")
Expand Down
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/CBManagerState+ReturnString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

@available(iOS 10.0, *)
extension CBManagerState {
Expand Down
4 changes: 2 additions & 2 deletions Bluejay/Bluejay/CBPeripheral+FindService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

extension CBPeripheral {

/// Find a service on a peripheral by CBUUID.
public func service(with uuid: CBUUID) -> CBService? {
return services?.first(where: { $0.uuid == uuid })
return services?.first { $0.uuid == uuid }
}

}
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/CBPeripheralState+ReturnString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

extension CBPeripheralState {

Expand Down
4 changes: 2 additions & 2 deletions Bluejay/Bluejay/CBService+FindCharacteristic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

extension CBService {

/// Find a characteristic on a service by CBUUID.
public func characteristic(with uuid: CBUUID) -> CBCharacteristic? {
return characteristics?.first(where: { $0.uuid == uuid })
return characteristics?.first { $0.uuid == uuid }
}

}
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/CharacteristicIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

/// A wrapper for CBUUID specific to a characteristic to help distinguish it from a CBUUID of a service.
public struct CharacteristicIdentifier {
Expand Down
6 changes: 3 additions & 3 deletions Bluejay/Bluejay/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

/// Types of connection time outs. Can specify a time out in seconds, or no time out.
public enum Timeout {
Expand Down Expand Up @@ -63,9 +63,9 @@ class Connection: Queueable {

if let timeOut = timeout, case let .seconds(timeoutInterval) = timeOut {
if #available(iOS 10.0, *) {
connectionTimer = Timer.scheduledTimer(withTimeInterval: timeoutInterval, repeats: false, block: { (_) in
connectionTimer = Timer.scheduledTimer(withTimeInterval: timeoutInterval, repeats: false) { _ in
self.timedOut()
})
}
} else {
// Fallback on earlier versions
connectionTimer = Timer.scheduledTimer(
Expand Down
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/Data+Extractable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension Data {
throw BluejayError.dataOutOfBounds(start: start, length: length, count: self.count)
}

return self.subdata(in: start..<start+length).withUnsafeBytes { $0.pointee }
return self.subdata(in: start..<start + length).withUnsafeBytes { $0.pointee }
}

}
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/Disconnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

/// A disconnection operation.
class Disconnection: Queueable {
Expand Down
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/DiscoverCharacteristic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

class DiscoverCharacteristic: Operation {

Expand Down
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/DiscoverService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

class DiscoverService: Operation {

Expand Down
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

/// The available events a queue can and should respond to.
enum Event {
Expand Down
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/Integer+Transferable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension BinaryInteger {
public func toBluetoothData() -> Data {
var tmp = self
return withUnsafePointer(to: &tmp) {
return Data(bytes: $0, count: MemoryLayout<Self>.size)
Data(bytes: $0, count: MemoryLayout<Self>.size)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/ListenCharacteristic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

/// A listen operation.
class ListenCharacteristic: Operation {
Expand Down
2 changes: 1 addition & 1 deletion Bluejay/Bluejay/Operation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2017 Steamclock Software. All rights reserved.
//

import Foundation
import CoreBluetooth
import Foundation

/**
A more specific Queueable for operations such as, discovering, reading, writing, and listening to characteristics.
Expand Down
Loading

0 comments on commit 4e8e9bc

Please sign in to comment.