From dde9fddae4c3f85283b91ad8d1eddb6e7e7b6e3b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 14 Dec 2025 03:48:07 +0000 Subject: [PATCH] style(swift): fix lint and formatting warnings --- apps/ios/Tests/BridgeClientTests.swift | 37 ++++++++++++------- apps/ios/Tests/DeepLinkParserTests.swift | 7 +++- .../Tests/IOSBridgeChatTransportTests.swift | 1 - .../SettingsNetworkingHelpersTests.swift | 14 ++++--- apps/ios/Tests/SwiftUIRenderSmokeTests.swift | 2 +- apps/ios/project.yml | 2 + .../Bridge/BridgeConnectionHandler.swift | 1 + apps/macos/Sources/Clawdis/Onboarding.swift | 4 +- 8 files changed, 43 insertions(+), 25 deletions(-) diff --git a/apps/ios/Tests/BridgeClientTests.swift b/apps/ios/Tests/BridgeClientTests.swift index c8ba2a226..565083369 100644 --- a/apps/ios/Tests/BridgeClientTests.swift +++ b/apps/ios/Tests/BridgeClientTests.swift @@ -51,7 +51,7 @@ import Testing self.listener.cancel() } - func waitForConnection(timeoutMs: Int = 2_000) async throws -> NWConnection { + func waitForConnection(timeoutMs: Int = 2000) async throws -> NWConnection { let deadline = Date().addingTimeInterval(Double(timeoutMs) / 1000.0) while Date() < deadline { if let connection = self.connection { return connection } @@ -62,7 +62,7 @@ import Testing ]) } - func receiveLine(timeoutMs: Int = 2_000) async throws -> Data? { + func receiveLine(timeoutMs: Int = 2000) async throws -> Data? { let connection = try await self.waitForConnection(timeoutMs: timeoutMs) let deadline = Date().addingTimeInterval(Double(timeoutMs) / 1000.0) @@ -73,18 +73,22 @@ import Testing return Data(line) } - let chunk = try await withCheckedThrowingContinuation(isolation: nil) { (cont: CheckedContinuation) in - connection.receive(minimumIncompleteLength: 1, maximumLength: 64 * 1024) { data, _, isComplete, error in - if let error { - cont.resume(throwing: error) - return + let chunk = try await withCheckedThrowingContinuation(isolation: nil) { (cont: CheckedContinuation< + Data, + Error, + >) in + connection + .receive(minimumIncompleteLength: 1, maximumLength: 64 * 1024) { data, _, isComplete, error in + if let error { + cont.resume(throwing: error) + return + } + if isComplete { + cont.resume(returning: Data()) + return + } + cont.resume(returning: data ?? Data()) } - if isComplete { - cont.resume(returning: Data()) - return - } - cont.resume(returning: data ?? Data()) - } } if chunk.isEmpty { return nil } @@ -124,7 +128,12 @@ import Testing let client = BridgeClient() let token = try await client.pairAndHello( endpoint: .hostPort(host: NWEndpoint.Host("127.0.0.1"), port: port), - hello: BridgeHello(nodeId: "ios-node", displayName: "iOS", token: "existing-token", platform: "ios", version: "1"), + hello: BridgeHello( + nodeId: "ios-node", + displayName: "iOS", + token: "existing-token", + platform: "ios", + version: "1"), onStatus: nil) #expect(token == "existing-token") diff --git a/apps/ios/Tests/DeepLinkParserTests.swift b/apps/ios/Tests/DeepLinkParserTests.swift index d16ba72fe..a26fc1b01 100644 --- a/apps/ios/Tests/DeepLinkParserTests.swift +++ b/apps/ios/Tests/DeepLinkParserTests.swift @@ -32,7 +32,8 @@ import Testing } @Test func parseAgentLinkParsesCommonFields() { - let url = URL(string: "clawdis://agent?message=Hello&deliver=1&sessionKey=node-iris&thinking=low&timeoutSeconds=30")! + let url = + URL(string: "clawdis://agent?message=Hello&deliver=1&sessionKey=node-iris&thinking=low&timeoutSeconds=30")! #expect( DeepLinkParser.parse(url) == .agent( .init( @@ -47,7 +48,9 @@ import Testing } @Test func parseAgentLinkParsesTargetRoutingFields() { - let url = URL(string: "clawdis://agent?message=Hello%20World&deliver=1&to=%2B15551234567&channel=whatsapp&key=secret")! + let url = + URL( + string: "clawdis://agent?message=Hello%20World&deliver=1&to=%2B15551234567&channel=whatsapp&key=secret")! #expect( DeepLinkParser.parse(url) == .agent( .init( diff --git a/apps/ios/Tests/IOSBridgeChatTransportTests.swift b/apps/ios/Tests/IOSBridgeChatTransportTests.swift index 6785c4ec0..0a308c3e8 100644 --- a/apps/ios/Tests/IOSBridgeChatTransportTests.swift +++ b/apps/ios/Tests/IOSBridgeChatTransportTests.swift @@ -31,4 +31,3 @@ import Testing } catch {} } } - diff --git a/apps/ios/Tests/SettingsNetworkingHelpersTests.swift b/apps/ios/Tests/SettingsNetworkingHelpersTests.swift index 4ce123a87..803dbd850 100644 --- a/apps/ios/Tests/SettingsNetworkingHelpersTests.swift +++ b/apps/ios/Tests/SettingsNetworkingHelpersTests.swift @@ -7,7 +7,9 @@ import Testing } @Test func parseHostPortParsesHostnameAndTrims() { - #expect(SettingsNetworkingHelpers.parseHostPort(from: " example.com:80 \n") == .init(host: "example.com", port: 80)) + #expect(SettingsNetworkingHelpers.parseHostPort(from: " example.com:80 \n") == .init( + host: "example.com", + port: 80)) } @Test func parseHostPortParsesBracketedIPv6() { @@ -27,15 +29,18 @@ import Testing } @Test func httpURLStringFormatsIPv4AndPort() { - #expect(SettingsNetworkingHelpers.httpURLString(host: "127.0.0.1", port: 8080, fallback: "fallback") == "http://127.0.0.1:8080") + #expect(SettingsNetworkingHelpers + .httpURLString(host: "127.0.0.1", port: 8080, fallback: "fallback") == "http://127.0.0.1:8080") } @Test func httpURLStringBracketsIPv6() { - #expect(SettingsNetworkingHelpers.httpURLString(host: "2001:db8::1", port: 8080, fallback: "fallback") == "http://[2001:db8::1]:8080") + #expect(SettingsNetworkingHelpers + .httpURLString(host: "2001:db8::1", port: 8080, fallback: "fallback") == "http://[2001:db8::1]:8080") } @Test func httpURLStringLeavesAlreadyBracketedIPv6() { - #expect(SettingsNetworkingHelpers.httpURLString(host: "[2001:db8::1]", port: 8080, fallback: "fallback") == "http://[2001:db8::1]:8080") + #expect(SettingsNetworkingHelpers + .httpURLString(host: "[2001:db8::1]", port: 8080, fallback: "fallback") == "http://[2001:db8::1]:8080") } @Test func httpURLStringFallsBackWhenMissingHostOrPort() { @@ -43,4 +48,3 @@ import Testing #expect(SettingsNetworkingHelpers.httpURLString(host: "example.com", port: nil, fallback: "y") == "http://y") } } - diff --git a/apps/ios/Tests/SwiftUIRenderSmokeTests.swift b/apps/ios/Tests/SwiftUIRenderSmokeTests.swift index 93138a2c2..5277db549 100644 --- a/apps/ios/Tests/SwiftUIRenderSmokeTests.swift +++ b/apps/ios/Tests/SwiftUIRenderSmokeTests.swift @@ -4,7 +4,7 @@ import UIKit @testable import Clawdis @Suite struct SwiftUIRenderSmokeTests { - @MainActor private static func host(_ view: V) -> UIWindow { + @MainActor private static func host(_ view: some View) -> UIWindow { let window = UIWindow(frame: UIScreen.main.bounds) window.rootViewController = UIHostingController(rootView: view) window.makeKeyAndVisible() diff --git a/apps/ios/project.yml b/apps/ios/project.yml index 1c4dc1c58..e3420e906 100644 --- a/apps/ios/project.yml +++ b/apps/ios/project.yml @@ -31,6 +31,7 @@ targets: product: ClawdisChatUI preBuildScripts: - name: SwiftFormat (lint) + basedOnDependencyAnalysis: false script: | set -euo pipefail if ! command -v swiftformat >/dev/null 2>&1; then @@ -41,6 +42,7 @@ targets: "$SRCROOT/Sources" \ "$SRCROOT/../shared/ClawdisKit/Sources" - name: SwiftLint + basedOnDependencyAnalysis: false script: | set -euo pipefail if ! command -v swiftlint >/dev/null 2>&1; then diff --git a/apps/macos/Sources/Clawdis/Bridge/BridgeConnectionHandler.swift b/apps/macos/Sources/Clawdis/Bridge/BridgeConnectionHandler.swift index a2e318413..671fc81d3 100644 --- a/apps/macos/Sources/Clawdis/Bridge/BridgeConnectionHandler.swift +++ b/apps/macos/Sources/Clawdis/Bridge/BridgeConnectionHandler.swift @@ -34,6 +34,7 @@ actor BridgeConnectionHandler { case error(code: String, message: String) } + // swiftlint:disable:next cyclomatic_complexity func run( resolveAuth: @escaping @Sendable (BridgeHello) async -> AuthResult, handlePair: @escaping @Sendable (BridgePairRequest) async -> PairResult, diff --git a/apps/macos/Sources/Clawdis/Onboarding.swift b/apps/macos/Sources/Clawdis/Onboarding.swift index c7a9189ca..e38547c43 100644 --- a/apps/macos/Sources/Clawdis/Onboarding.swift +++ b/apps/macos/Sources/Clawdis/Onboarding.swift @@ -82,11 +82,11 @@ struct OnboardingView: View { init( state: AppState = AppStateStore.shared, permissionMonitor: PermissionMonitor = .shared, - masterDiscovery: MasterDiscoveryModel = MasterDiscoveryModel()) + discoveryModel: MasterDiscoveryModel = MasterDiscoveryModel()) { self._state = ObservedObject(wrappedValue: state) self._permissionMonitor = ObservedObject(wrappedValue: permissionMonitor) - self._masterDiscovery = StateObject(wrappedValue: masterDiscovery) + self._masterDiscovery = StateObject(wrappedValue: discoveryModel) } var body: some View {