Skip to content

Commit f474fe7

Browse files
enedwerediver
authored andcommitted
swiftlint config and iniital format
1 parent 59332e8 commit f474fe7

File tree

12 files changed

+56
-36
lines changed

12 files changed

+56
-36
lines changed

.swiftlint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
disabled_rules:
2+
- cyclomatic_complexity
3+
- identifier_name
4+
- multiple_closures_with_trailing_closure
5+
- nesting
6+
- type_name
7+
- unused_closure_parameter
8+
9+
excluded: # case-sensitive paths to ignore during linting. Takes precedence over `included`
10+
- Pods
11+
- "**/*.pb.swift" # exclude files with a wildcard
12+
13+
line_length: 300
14+
type_body_length:
15+
- 600
16+
17+
function_body_length:
18+
- 150
19+
20+
file_length:
21+
warning: 800
22+
23+
reporter: "xcode"

packages/reactive_ble_mobile/ios/Classes/BleData extras/BLEStatus.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import enum CoreBluetooth.CBManagerState
22

33
func encode(_ centralState: CBManagerState) -> Int32 {
4-
switch (centralState) {
4+
switch centralState {
55
case .unknown, .resetting:
66
return 0
77
case .unsupported:

packages/reactive_ble_mobile/ios/Classes/BleData extras/FailureCodes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ enum MaximumWriteValueLengthRetrieval: Int {
2525
}
2626

2727
enum RequestConnectionPriorityFailure: Int {
28-
28+
2929
case operationNotSupported = 1
3030
}

packages/reactive_ble_mobile/ios/Classes/Plugin/Common/EventSink.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@ struct EventSink {
2929
}
3030
}
3131
}
32-

packages/reactive_ble_mobile/ios/Classes/Plugin/PluginController.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class PluginController {
2222
}
2323
}
2424
}
25-
var messageQueue: [CharacteristicValueInfo] = [];
25+
var messageQueue: [CharacteristicValueInfo] = []
2626
var connectedDeviceSink: EventSink?
2727
var characteristicValueUpdateSink: EventSink?
2828

@@ -128,11 +128,11 @@ final class PluginController {
128128
}
129129
}
130130
let sink = context.characteristicValueUpdateSink
131-
if (sink != nil) {
131+
if sink != nil {
132132
sink!.add(.success(message))
133133
} else {
134134
// In case message arrives before sink is created
135-
context.messageQueue.append(message);
135+
context.messageQueue.append(message)
136136
}
137137

138138
}
@@ -205,8 +205,7 @@ final class PluginController {
205205
let servicesWithCharacteristicsToDiscover: ServicesWithCharacteristicsToDiscover
206206
if args.hasServicesWithCharacteristicsToDiscover {
207207
let items = args.servicesWithCharacteristicsToDiscover.items.reduce(
208-
into: [ServiceID: [CharacteristicID]](),
209-
{ dict, item in
208+
into: [ServiceID: [CharacteristicID]](), { dict, item in
210209
let serviceID = CBUUID(data: item.serviceID.data)
211210
let characteristicIDs = item.characteristics.map { CBUUID(data: $0.data) }
212211

@@ -221,7 +220,7 @@ final class PluginController {
221220
let timeout = args.timeoutInMs > 0 ? TimeInterval(args.timeoutInMs) / 1000 : nil
222221

223222
completion(.success(nil))
224-
223+
225224
if let sink = connectedDeviceSink {
226225
let message = DeviceInfo.with {
227226
$0.id = args.deviceID
@@ -231,7 +230,7 @@ final class PluginController {
231230
} else {
232231
print("Warning! No event channel set up to report a connection update")
233232
}
234-
233+
235234
do {
236235
try central.connect(
237236
to: deviceID,
@@ -296,10 +295,10 @@ final class PluginController {
296295
Uuid.with { $0.data = characteristic.uuid.data }
297296
}
298297
$0.characteristics = (service.characteristics ?? []).map { characteristic in
299-
DiscoveredCharacteristic.with{
300-
$0.characteristicID = Uuid.with{$0.data = characteristic.uuid.data}
298+
DiscoveredCharacteristic.with {
299+
$0.characteristicID = Uuid.with {$0.data = characteristic.uuid.data}
301300
if characteristic.service?.uuid.data != nil {
302-
$0.serviceID = Uuid.with{$0.data = characteristic.service!.uuid.data}
301+
$0.serviceID = Uuid.with {$0.data = characteristic.service!.uuid.data}
303302
}
304303
$0.isReadable = characteristic.properties.contains(.read)
305304
$0.isWritableWithResponse = characteristic.properties.contains(.write)
@@ -308,7 +307,7 @@ final class PluginController {
308307
$0.isIndicatable = characteristic.properties.contains(.indicate)
309308
}
310309
}
311-
310+
312311
$0.includedServices = (service.includedServices ?? []).map(makeDiscoveredService)
313312
}
314313
}
@@ -463,20 +462,20 @@ final class PluginController {
463462
completion(.success(result))
464463
}
465464
}
466-
465+
467466
func writeCharacteristicWithoutResponse(name: String, args: WriteCharacteristicRequest, completion: @escaping PlatformMethodCompletionHandler) {
468467
guard let central = central
469468
else {
470469
completion(.failure(PluginError.notInitialized.asFlutterError))
471470
return
472471
}
473-
472+
474473
guard let characteristic = QualifiedCharacteristicIDFactory().make(from: args.characteristic)
475474
else {
476475
completion(.failure(PluginError.invalidMethodCall(method: name, details: "characteristic, service, and peripheral IDs are required").asFlutterError))
477476
return
478477
}
479-
478+
480479
let result: WriteCharacteristicInfo
481480
do {
482481
try central.writeWithoutResponse(

packages/reactive_ble_mobile/ios/Classes/Plugin/SwiftReactiveBlePlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public class SwiftReactiveBlePlugin: NSObject, FlutterPlugin {
137137
}),
138138
AnyPlatformMethod(UnaryPlatformMethod(name: "negotiateMtuSize") { (name, context, args: NegotiateMtuRequest, completion) in
139139
context.reportMaximumWriteValueLength(name: name, args: args, completion: completion)
140-
}),
140+
})
141141
])
142142

143143
public func handle(_ call: FlutterMethodCall, result completion: @escaping FlutterResult) {

packages/reactive_ble_mobile/ios/Classes/ReactiveBle/Central.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ final class Central {
143143
discover: servicesWithCharacteristicsToDiscover,
144144
completion: central.onServicesWithCharacteristicsInitialDiscovery
145145
)
146-
case .failedToConnect(_), .disconnected(_):
146+
case .failedToConnect, .disconnected:
147147
break
148148
}
149149
}
@@ -172,7 +172,7 @@ final class Central {
172172
for peripheralID: PeripheralID,
173173
discover servicesWithCharacteristicsToDiscover: ServicesWithCharacteristicsToDiscover,
174174
completion: @escaping ServicesWithCharacteristicsDiscoveryHandler
175-
) throws -> Void {
175+
) throws {
176176
let peripheral = try resolve(connected: peripheralID)
177177

178178
discoverServicesWithCharacteristics(
@@ -186,7 +186,7 @@ final class Central {
186186
for peripheral: CBPeripheral,
187187
discover servicesWithCharacteristicsToDiscover: ServicesWithCharacteristicsToDiscover,
188188
completion: @escaping ServicesWithCharacteristicsDiscoveryHandler
189-
) -> Void {
189+
) {
190190
servicesWithCharacteristicsDiscoveryRegistry.registerTask(
191191
key: peripheral.identifier,
192192
params: .init(servicesWithCharacteristicsToDiscover: servicesWithCharacteristicsToDiscover),
@@ -226,10 +226,10 @@ final class Central {
226226

227227
guard characteristic.properties.contains(.read)
228228
else { throw Failure.notReadable(qualifiedCharacteristic) }
229-
229+
230230
guard let peripheral = characteristic.service?.peripheral
231231
else { throw Failure.peripheralIsUnknown(qualifiedCharacteristic.peripheralID) }
232-
232+
233233
peripheral.readValue(for: characteristic)
234234

235235
}
@@ -251,16 +251,16 @@ final class Central {
251251
completion(central, qualifiedCharacteristic, error)
252252
}
253253
)
254-
254+
255255
guard let peripheral = characteristic.service?.peripheral
256-
else{ throw Failure.peripheralIsUnknown(qualifiedCharacteristic.peripheralID) }
256+
else { throw Failure.peripheralIsUnknown(qualifiedCharacteristic.peripheralID) }
257257

258258
characteristicWriteRegistry.updateTask(
259259
key: qualifiedCharacteristic,
260260
action: { $0.start(peripheral: peripheral) }
261261
)
262262
}
263-
263+
264264
func writeWithoutResponse(
265265
value: Data,
266266
characteristic qualifiedCharacteristic: QualifiedCharacteristic
@@ -269,10 +269,10 @@ final class Central {
269269

270270
guard characteristic.properties.contains(.writeWithoutResponse)
271271
else { throw Failure.notWritable(qualifiedCharacteristic) }
272-
272+
273273
guard let response = characteristic.service?.peripheral?.writeValue(value, for: characteristic, type: .withoutResponse)
274274
else { throw Failure.characteristicNotFound(qualifiedCharacteristic) }
275-
275+
276276
return response
277277
}
278278

packages/reactive_ble_mobile/ios/Classes/ReactiveBle/CentralManagerDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class CentralManagerDelegate: NSObject, CBCentralManagerDelegate {
3030
onStateChange(central.state)
3131
}
3232

33-
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi: NSNumber) {
33+
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi: NSNumber) {
3434
onDiscovery(peripheral, advertisementData, rssi.intValue)
3535
}
3636

packages/reactive_ble_mobile/ios/Classes/ReactiveBle/Tasks/CharacteristicNotify/CharacteristicNotifyTaskController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct CharacteristicNotifyTaskController: PeripheralTaskController {
1313
func start(characteristic: CBCharacteristic) -> SubjectTask {
1414
guard let peripheral = characteristic.service?.peripheral
1515
else { return task.with(state: task.state.finished(CharacteristicNotifyError.unExpected)) }
16-
16+
1717
peripheral.setNotifyValue(task.params.state.isOn, for: characteristic)
1818
return task.with(state: task.state.processing(.applying))
1919
}
@@ -26,7 +26,7 @@ struct CharacteristicNotifyTaskController: PeripheralTaskController {
2626
return task.with(state: task.state.finished(error))
2727
}
2828

29-
private enum CharacteristicNotifyError: Error{
30-
case unExpected;
29+
private enum CharacteristicNotifyError: Error {
30+
case unExpected
3131
}
3232
}

packages/reactive_ble_mobile/ios/Classes/ReactiveBle/Tasks/Connect/ConnectTaskController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct ConnectTaskController: PeripheralTaskController {
3939
case .processing(since: _, .connecting):
4040
centralManager.cancelPeripheralConnection(peripheral)
4141
return task.with(state: task.state.finished(.failedToConnect(error)))
42-
case .finished(in: _, _):
42+
case .finished:
4343
assert(false)
4444
return task
4545
}

0 commit comments

Comments
 (0)