Skip to content

Commit

Permalink
chore: fix swiftlint and swiftformat config
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7061 committed Feb 14, 2025
1 parent 25d8bf3 commit f249f9e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 50 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions example/.swiftlint.yml → example/ios/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ opt_in_rules:
analyzer_rules: # rules run by `swiftlint analyze`
- explicit_self
included:
- abrevva-sdk-ios/lib
- ../../ios
excluded:
- Carthage
- Pods
Expand All @@ -21,8 +21,8 @@ force_try:
severity: warning
line_length: 120
type_body_length:
warning: 400
error: 500
warning: 550
error: 650
file_length:
warning: 600
error: 1200
Expand Down
50 changes: 42 additions & 8 deletions example/ios/ExampleAppExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ExampleAppExample" */;
buildPhases = (
AA1E527239C7DC8BC535B9F1 /* [CP] Check Pods Manifest.lock */,
0714C2562D5F2897004E0943 /* Run SwiftLint */,
0714C2572D5F31AD004E0943 /* Run SwiftFormat */,
13B07F871A680F5B00A75B9A /* Sources */,
13B07F8C1A680F5B00A75B9A /* Frameworks */,
13B07F8E1A680F5B00A75B9A /* Resources */,
Expand Down Expand Up @@ -262,6 +264,44 @@
shellPath = /bin/sh;
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
};
0714C2562D5F2897004E0943 /* Run SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run SwiftLint";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "${PODS_ROOT}/SwiftLint/swiftlint --fix --format && ${PODS_ROOT}/SwiftLint/swiftlint\n";
};
0714C2572D5F31AD004E0943 /* Run SwiftFormat */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run SwiftFormat";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "${PODS_ROOT}/SwiftFormat/CommandLineTool/swiftformat --swiftversion 6.0 $SRCROOT\n";
};
14EBE08067923129DD66A4E5 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -593,10 +633,7 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down Expand Up @@ -679,10 +716,7 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
3 changes: 2 additions & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ end
target 'ExampleAppExample' do
config = use_native_modules!
use_frameworks!

pod 'SwiftLint', '~> 0.54.0'
pod 'SwiftFormat/CLI', '~> 0.49'

use_react_native!(
:path => config[:reactNativePath],
# Enables Flipper.
Expand Down
52 changes: 23 additions & 29 deletions ios/ble/AbrevvaBle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class AbrevvaBle: RCTEventEmitter {
settingsURL,
completionHandler: { success in
resolve([
"value": success,
"value": success
])
}
)
Expand All @@ -126,22 +126,19 @@ public class AbrevvaBle: RCTEventEmitter {
let allowDuplicates = optionsSwift["allowDuplicates"] as? Bool ?? false
let timeout = optionsSwift["timeout"] as? Int ?? 10000

bleManager.startScan(
{ device in
self.bleDeviceMap[device.getAddress()] = device
self.sendEvent(
withName: "onScanResult", body: self.getAdvertismentData(device)
)
},
{ error in
self.sendEvent(withName: "onScanStart", body: error == nil)
},
{ error in
self.sendEvent(withName: "onScanStop", body: error == nil)
},
macFilter,
allowDuplicates,
timeout
bleManager.startScan({ device in
self.bleDeviceMap[device.getAddress()] = device
self.sendEvent(
withName: "onScanResult", body: self.getAdvertismentData(device)
)
}, { error in
self.sendEvent(withName: "onScanStart", body: error == nil)
}, { error in
self.sendEvent(withName: "onScanStop", body: error == nil)
},
macFilter,
allowDuplicates,
timeout
)
}

Expand Down Expand Up @@ -196,8 +193,7 @@ public class AbrevvaBle: RCTEventEmitter {
let timeout = optionsSwift["timeout"] as? Int ?? 10000
Task {
let success = await self.bleManager!.connect(
device,
{ address in
device, { address in
self.sendEvent(
withName: "onDisconnect|\(address)", body: ["address": address]
)
Expand Down Expand Up @@ -350,12 +346,11 @@ public class AbrevvaBle: RCTEventEmitter {
let timeout = optionsSwift["timeout"] as? Int ?? nil
Task {
let success = await device.setNotifications(
characteristic.0, characteristic.1, true,
{ value in
characteristic.0, characteristic.1, true, { value in
let key =
"notification|\(device.getAddress().lowercased())|"
+ "\(characteristic.0.uuidString.lowercased())|"
+ "\(characteristic.1.uuidString.lowercased())"
+ "\(characteristic.0.uuidString.lowercased())|"
+ "\(characteristic.1.uuidString.lowercased())"

if value != nil {
self.sendEvent(withName: key, body: ["value": dataToString(value!)])
Expand Down Expand Up @@ -407,11 +402,11 @@ public class AbrevvaBle: RCTEventEmitter {
var bleDeviceData: [String: Any?] = [
"deviceId": device.getAddress(),
"name": device.getName(),
"raw": device.advertisementData?.rawData,
"raw": device.advertisementData?.rawData
]

var advertismentData: [String: Any?] = [
"rssi": device.advertisementData?.rssi,
"rssi": device.advertisementData?.rssi
]
if let isConnectable = device.advertisementData?.isConnectable {
advertismentData["isConnectable"] = isConnectable
Expand Down Expand Up @@ -441,7 +436,7 @@ public class AbrevvaBle: RCTEventEmitter {
"subFirmwareVersionMinor": mfData.subFirmwareVersionMinor,
"subFirmwareVersionPatch": mfData.subFirmwareVersionPatch,
"subComponentIdentifier": mfData.subComponentIdentifier,
"componentType": getComponentType(mfData.componentType),
"componentType": getComponentType(mfData.componentType)
]

advertismentData["manufacturerData"] = manufacturerData
Expand Down Expand Up @@ -469,8 +464,7 @@ public class AbrevvaBle: RCTEventEmitter {
}

private func getBleManager(_ reject: @escaping RCTPromiseRejectBlock)
-> BleManager?
{
-> BleManager? {
guard let bleManager else {
reject("getBleManager(): not initialized", nil, nil)
return nil
Expand Down Expand Up @@ -544,7 +538,7 @@ public class AbrevvaBle: RCTEventEmitter {

private func getBleDeviceDict(_ device: BleDevice) -> [String: String] {
var bleDevice = [
"deviceId": device.getAddress(),
"deviceId": device.getAddress()
]
if device.getName() != nil {
bleDevice["name"] = device.getName()
Expand Down
18 changes: 9 additions & 9 deletions ios/crypto/AbrevvaCrypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AbrevvaCrypto: NSObject {
} else {
resolve([
"cipherText": [UInt8](ct[..<pt.count]).toHexString(),
"authTag": [UInt8](ct[pt.count...]).toHexString(),
"authTag": [UInt8](ct[pt.count...]).toHexString()
])
}
}
Expand Down Expand Up @@ -61,7 +61,7 @@ public class AbrevvaCrypto: NSObject {
} else {
resolve([
"plainText": pt,
"authOk": true,
"authOk": true
])
}
}
Expand All @@ -74,7 +74,7 @@ public class AbrevvaCrypto: NSObject {

resolve([
"privateKey": keyPair[0].toHexString(),
"publicKey": keyPair[1].toHexString(),
"publicKey": keyPair[1].toHexString()
])
}

Expand All @@ -96,7 +96,7 @@ public class AbrevvaCrypto: NSObject {
)

resolve([
"sharedSecret": sharedSecret?.toHexString(),
"sharedSecret": sharedSecret?.toHexString()
])
}

Expand All @@ -121,7 +121,7 @@ public class AbrevvaCrypto: NSObject {
reject("encryption failed", nil, nil)
} else {
resolve([
"opOk": operationResult,
"opOk": operationResult
])
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ public class AbrevvaCrypto: NSObject {
reject("Encryption has failed", nil, nil)
} else {
resolve([
"opOk": operationResult,
"opOk": operationResult
])
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ public class AbrevvaCrypto: NSObject {
reject("Decryption has failed", nil, nil)
} else {
resolve([
"opOk": operationResult,
"opOk": operationResult
])
}
}
Expand All @@ -214,7 +214,7 @@ public class AbrevvaCrypto: NSObject {
reject("random generation failed", nil, nil)
} else {
resolve([
"value": rnd,
"value": rnd
])
}
}
Expand All @@ -240,7 +240,7 @@ public class AbrevvaCrypto: NSObject {
reject("derivation failed", nil, nil)
} else {
resolve([
"value": derived,
"value": derived
])
}
}
Expand Down

0 comments on commit f249f9e

Please sign in to comment.