From 3aedd0ccffa4fab34670a699ab59d6ca9366f4d9 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 19 Jun 2026 13:46:46 +0200 Subject: [PATCH] swiftformat now enforces newlines for ifs --- .../AppLockSetupFlowCoordinator.swift | 4 +++- ElementX/Sources/Other/BlurHashDecode.swift | 14 ++++++++++---- ElementX/Sources/Other/BlurHashEncode.swift | 14 ++++++++++---- ElementX/Sources/Other/Extensions/String.swift | 8 ++++++-- .../AppLockSetupPINScreen/View/PINTextField.swift | 4 +++- .../Screens/HomeScreen/HomeScreenModels.swift | 4 +++- .../InviteUsersScreenModels.swift | 4 +++- .../InviteUsersScreenViewModel.swift | 6 +++++- .../LocationSharingScreenModels.swift | 8 ++++++-- .../LocationSharingScreenViewModel.swift | 8 ++++++-- .../View/MediaUploadPreviewScreen.swift | 8 ++++++-- .../Screens/RoomScreen/View/RoomScreen.swift | 4 +++- .../Sources/Screens/Timeline/TimelineModels.swift | 4 +++- .../Timeline/TimelineTableViewController.swift | 4 +++- .../ItemMenu/TimelineItemMenuActionProvider.swift | 6 +++++- .../SessionVerificationViewModelTests.swift | 8 ++++++-- .../Sources/Compound/List/ListRowLabel.swift | 8 ++++++-- 17 files changed, 87 insertions(+), 29 deletions(-) diff --git a/ElementX/Sources/FlowCoordinators/AppLockSetupFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/AppLockSetupFlowCoordinator.swift index bc5a76b8c..df113bda8 100644 --- a/ElementX/Sources/FlowCoordinators/AppLockSetupFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/AppLockSetupFlowCoordinator.swift @@ -105,7 +105,9 @@ class AppLockSetupFlowCoordinator: FlowCoordinatorProtocol { switch (fromState, event) { case (.initial, .start): - if presentingFlow == .onboarding { return .createPIN(replacingExitingPIN: false) } + if presentingFlow == .onboarding { + return .createPIN(replacingExitingPIN: false) + } return appLockService.isEnabled ? .unlock : .createPIN(replacingExitingPIN: false) case (.unlock, .pinEntered): return .settings diff --git a/ElementX/Sources/Other/BlurHashDecode.swift b/ElementX/Sources/Other/BlurHashDecode.swift index 134b70312..2605c54a4 100644 --- a/ElementX/Sources/Other/BlurHashDecode.swift +++ b/ElementX/Sources/Other/BlurHashDecode.swift @@ -113,14 +113,20 @@ private func signPow(_ value: Float, _ exp: Float) -> Float { private func linearTosRGB(_ value: Float) -> Int { let v = max(0, min(1, value)) - if v <= 0.0031308 { return Int(v * 12.92 * 255 + 0.5) } - else { return Int((1.055 * pow(v, 1 / 2.4) - 0.055) * 255 + 0.5) } + if v <= 0.0031308 { + return Int(v * 12.92 * 255 + 0.5) + } else { + return Int((1.055 * pow(v, 1 / 2.4) - 0.055) * 255 + 0.5) + } } private func sRGBToLinear(_ value: Type) -> Float { let v = Float(Int64(value)) / 255 - if v <= 0.04045 { return v / 12.92 } - else { return pow((v + 0.055) / 1.055, 2.4) } + if v <= 0.04045 { + return v / 12.92 + } else { + return pow((v + 0.055) / 1.055, 2.4) + } } private let encodeCharacters: [String] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".map { String($0) } diff --git a/ElementX/Sources/Other/BlurHashEncode.swift b/ElementX/Sources/Other/BlurHashEncode.swift index b32f15d19..01e240c4d 100644 --- a/ElementX/Sources/Other/BlurHashEncode.swift +++ b/ElementX/Sources/Other/BlurHashEncode.swift @@ -137,14 +137,20 @@ private func signPow(_ value: Float, _ exp: Float) -> Float { private func linearTosRGB(_ value: Float) -> Int { let v = max(0, min(1, value)) - if v <= 0.0031308 { return Int(v * 12.92 * 255 + 0.5) } - else { return Int((1.055 * pow(v, 1 / 2.4) - 0.055) * 255 + 0.5) } + if v <= 0.0031308 { + return Int(v * 12.92 * 255 + 0.5) + } else { + return Int((1.055 * pow(v, 1 / 2.4) - 0.055) * 255 + 0.5) + } } private func sRGBToLinear(_ value: Type) -> Float { let v = Float(Int64(value)) / 255 - if v <= 0.04045 { return v / 12.92 } - else { return pow((v + 0.055) / 1.055, 2.4) } + if v <= 0.04045 { + return v / 12.92 + } else { + return pow((v + 0.055) / 1.055, 2.4) + } } private let encodeCharacters: [String] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".map { String($0) } diff --git a/ElementX/Sources/Other/Extensions/String.swift b/ElementX/Sources/Other/Extensions/String.swift index 76515e8bf..e0aa979eb 100644 --- a/ElementX/Sources/Other/Extensions/String.swift +++ b/ElementX/Sources/Other/Extensions/String.swift @@ -113,8 +113,12 @@ nonisolated extension String { let isStrongRTL = (0x0590...0x08FF).contains(value) || (0xFB1D...0xFDFF).contains(value) || (0xFE70...0xFEFF).contains(value) - if isStrongRTL { return true } - if scalar.properties.isAlphabetic { return false } + if isStrongRTL { + return true + } + if scalar.properties.isAlphabetic { + return false + } } return false } diff --git a/ElementX/Sources/Screens/AppLock/AppLockSetupPINScreen/View/PINTextField.swift b/ElementX/Sources/Screens/AppLock/AppLockSetupPINScreen/View/PINTextField.swift index 595a5e82d..8fe709a11 100644 --- a/ElementX/Sources/Screens/AppLock/AppLockSetupPINScreen/View/PINTextField.swift +++ b/ElementX/Sources/Screens/AppLock/AppLockSetupPINScreen/View/PINTextField.swift @@ -43,7 +43,9 @@ struct PINTextField: View { func sanitize(_ pinCode: String) -> String { var sanitized = pinCode - if sanitized.count > maxLength { sanitized = String(pinCode.prefix(maxLength)) } + if sanitized.count > maxLength { + sanitized = String(pinCode.prefix(maxLength)) + } return sanitized.filter(\.isNumber) } } diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift index b741f3491..a68022b9d 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift @@ -274,7 +274,9 @@ extension HomeScreenRoom { let callBadge = if summary.hasOngoingCall { summary.activeCallIntent == .audio ? CallBadgeType.voice : CallBadgeType.video - } else { CallBadgeType.none } + } else { + CallBadgeType.none + } let type: HomeScreenRoom.RoomType = switch summary.joinRequestType { case .invite(let inviter): .invite(inviterDetails: inviter.map(RoomInviterDetails.init)) diff --git a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenModels.swift b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenModels.swift index 0a9ba7f36..adcd80f30 100644 --- a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenModels.swift +++ b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenModels.swift @@ -49,7 +49,9 @@ struct InviteUsersScreenViewState: BindableState { } func isUserDisabled(_ user: UserProfileProxy) -> Bool { - if isInviteeMandatory(user) { return true } + if isInviteeMandatory(user) { + return true + } let membershipState = membershipState(user) return membershipState == .invite || membershipState == .join } diff --git a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift index cf6cb219d..2a441e2b6 100644 --- a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift +++ b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift @@ -38,7 +38,11 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr self.userIndicatorController = userIndicatorController self.appSettings = appSettings - let mandatoryInvitees: [UserProfileProxy] = if case .draft(let invitees) = roomType { invitees } else { [] } + let mandatoryInvitees: [UserProfileProxy] = if case .draft(let invitees) = roomType { + invitees + } else { + [] + } super.init(initialViewState: InviteUsersScreenViewState(selectedUsers: mandatoryInvitees, mandatoryInvitees: mandatoryInvitees, diff --git a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift index 06be38710..9a1660e29 100644 --- a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift +++ b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenModels.swift @@ -30,7 +30,9 @@ enum LocationSharingInteractionMode: Hashable { case viewLive(sender: TimelineItemSender?, initialLiveLocationShare: LiveLocationShare?) var isPicker: Bool { - if case .picker = self { return true } + if case .picker = self { + return true + } return false } @@ -97,7 +99,9 @@ struct LocationSharingScreenViewState: BindableState { case .viewLive: return liveLocationShares.compactMap { share in guard let geoURI = share.geoURI else { return nil } - if share.userID == ownUserID, isStoppingLiveLocation { return nil } + if share.userID == ownUserID, isStoppingLiveLocation { + return nil + } let profile = userProfiles[share.userID] ?? UserProfileProxy(userID: share.userID) let kind = LocationMarkerKind.liveUser(profile) diff --git a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift index b1132d346..2ecd1d3bf 100644 --- a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift +++ b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift @@ -145,8 +145,12 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati state.liveLocationShares = liveLocationsShares .filter { !(isStoppingLiveLocation && ownUserID == $0.userID) } .sorted { lhs, rhs in - if lhs.userID == ownUserID { return true } - if rhs.userID == ownUserID { return false } + if lhs.userID == ownUserID { + return true + } + if rhs.userID == ownUserID { + return false + } return lhs.timestamp > rhs.timestamp } diff --git a/ElementX/Sources/Screens/MediaUploadPreviewScreen/View/MediaUploadPreviewScreen.swift b/ElementX/Sources/Screens/MediaUploadPreviewScreen/View/MediaUploadPreviewScreen.swift index f4b1fb41d..25c1dfc56 100644 --- a/ElementX/Sources/Screens/MediaUploadPreviewScreen/View/MediaUploadPreviewScreen.swift +++ b/ElementX/Sources/Screens/MediaUploadPreviewScreen/View/MediaUploadPreviewScreen.swift @@ -271,8 +271,12 @@ private struct PreviewView: UIViewControllerRepresentable { private func previewItemTitle(for url: URL) -> String? { guard let type = UTType(filenameExtension: url.pathExtension) else { return view.title } - if type.conforms(to: .image) { return L10n.a11yPhotoPreview } - if type.conforms(to: .movie) || type.conforms(to: .video) { return L10n.a11yVideoPreview } + if type.conforms(to: .image) { + return L10n.a11yPhotoPreview + } + if type.conforms(to: .movie) || type.conforms(to: .video) { + return L10n.a11yVideoPreview + } return view.title } diff --git a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift index 7d417292c..5288e643e 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift @@ -121,7 +121,9 @@ struct RoomScreen: View { .alert(item: $context.alertInfo) .timelineMediaPreview(viewModel: $context.mediaPreviewViewModel) .onChange(of: pillSourceButtonIsVisible) { _, isVisible in - if !isVisible { dismissMarkAsReadPill() } + if !isVisible { + dismissMarkAsReadPill() + } } .track(screen: .Room) .sentryTrace("\(Self.self)") diff --git a/ElementX/Sources/Screens/Timeline/TimelineModels.swift b/ElementX/Sources/Screens/Timeline/TimelineModels.swift index 473554085..7e832b34f 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineModels.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineModels.swift @@ -286,7 +286,9 @@ struct TimelineState { /// value to ``itemsDictionary``. mutating func recomputeReadMarkerUniqueID() { readMarkerUniqueID = itemsDictionary.first { _, viewState in - if case .readMarker = viewState.type { return true } + if case .readMarker = viewState.type { + return true + } return false }?.key } diff --git a/ElementX/Sources/Screens/Timeline/TimelineTableViewController.swift b/ElementX/Sources/Screens/Timeline/TimelineTableViewController.swift index 6a8ab1ec4..1a8bcce67 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineTableViewController.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineTableViewController.swift @@ -103,7 +103,9 @@ class TimelineTableViewController: UIViewController { var isLive = true { didSet { // Update isScrolledToBottom when switching back to a live timeline. - if isLive { scrollViewDidScroll(tableView) } + if isLive { + scrollViewDidScroll(tableView) + } } } diff --git a/ElementX/Sources/Screens/Timeline/View/ItemMenu/TimelineItemMenuActionProvider.swift b/ElementX/Sources/Screens/Timeline/View/ItemMenu/TimelineItemMenuActionProvider.swift index 544ee3002..d00a98f27 100644 --- a/ElementX/Sources/Screens/Timeline/View/ItemMenu/TimelineItemMenuActionProvider.swift +++ b/ElementX/Sources/Screens/Timeline/View/ItemMenu/TimelineItemMenuActionProvider.swift @@ -113,7 +113,11 @@ struct TimelineItemMenuActionProvider { } if canRedactItem(item) { - let isMedia = if case .media = timelineKind { true } else { false } + let isMedia = if case .media = timelineKind { + true + } else { + false + } secondaryActions.append(.redact(isMedia: isMedia)) } diff --git a/UnitTests/Sources/SessionVerificationViewModelTests.swift b/UnitTests/Sources/SessionVerificationViewModelTests.swift index da78303a9..f94be527e 100644 --- a/UnitTests/Sources/SessionVerificationViewModelTests.swift +++ b/UnitTests/Sources/SessionVerificationViewModelTests.swift @@ -74,7 +74,9 @@ struct SessionVerificationViewModelTests { let deferred = deferFulfillment(sessionVerificationController.actions .delay(for: .seconds(0.1), scheduler: DispatchQueue.main)) { callback in - if case .finished = callback { return true } + if case .finished = callback { + return true + } return false } @@ -92,7 +94,9 @@ struct SessionVerificationViewModelTests { let deferred = deferFulfillment(sessionVerificationController.actions .delay(for: .seconds(0.1), scheduler: DispatchQueue.main)) { callback in - if case .cancelled = callback { return true } + if case .cancelled = callback { + return true + } return false } diff --git a/compound-ios/Sources/Compound/List/ListRowLabel.swift b/compound-ios/Sources/Compound/List/ListRowLabel.swift index a024f0385..6eea34bb9 100644 --- a/compound-ios/Sources/Compound/List/ListRowLabel.swift +++ b/compound-ios/Sources/Compound/List/ListRowLabel.swift @@ -98,7 +98,9 @@ public struct ListRowLabel: View { var iconForegroundColor: Color { guard isEnabled else { return .compound.iconTertiaryAlpha } - if role == .destructive { return .compound.iconCriticalPrimary } + if role == .destructive { + return .compound.iconCriticalPrimary + } if hideIconBackground { return .compound.iconTertiaryAlpha } else { @@ -111,7 +113,9 @@ public struct ListRowLabel: View { } var iconBackgroundColor: Color { - if hideIconBackground { return .clear } + if hideIconBackground { + return .clear + } if #available(iOS 26, *) { return .clear } else {