swiftformat now enforces newlines for ifs

This commit is contained in:
Mauro Romito
2026-06-19 13:46:46 +02:00
committed by Mauro
parent f32b9eeb26
commit 3aedd0ccff
17 changed files with 87 additions and 29 deletions
@@ -105,7 +105,9 @@ class AppLockSetupFlowCoordinator: FlowCoordinatorProtocol {
switch (fromState, event) { switch (fromState, event) {
case (.initial, .start): case (.initial, .start):
if presentingFlow == .onboarding { return .createPIN(replacingExitingPIN: false) } if presentingFlow == .onboarding {
return .createPIN(replacingExitingPIN: false)
}
return appLockService.isEnabled ? .unlock : .createPIN(replacingExitingPIN: false) return appLockService.isEnabled ? .unlock : .createPIN(replacingExitingPIN: false)
case (.unlock, .pinEntered): case (.unlock, .pinEntered):
return .settings return .settings
+10 -4
View File
@@ -113,14 +113,20 @@ private func signPow(_ value: Float, _ exp: Float) -> Float {
private func linearTosRGB(_ value: Float) -> Int { private func linearTosRGB(_ value: Float) -> Int {
let v = max(0, min(1, value)) let v = max(0, min(1, value))
if v <= 0.0031308 { return Int(v * 12.92 * 255 + 0.5) } if v <= 0.0031308 {
else { return Int((1.055 * pow(v, 1 / 2.4) - 0.055) * 255 + 0.5) } 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<Type: BinaryInteger>(_ value: Type) -> Float { private func sRGBToLinear<Type: BinaryInteger>(_ value: Type) -> Float {
let v = Float(Int64(value)) / 255 let v = Float(Int64(value)) / 255
if v <= 0.04045 { return v / 12.92 } if v <= 0.04045 {
else { return pow((v + 0.055) / 1.055, 2.4) } return v / 12.92
} else {
return pow((v + 0.055) / 1.055, 2.4)
}
} }
private let encodeCharacters: [String] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".map { String($0) } private let encodeCharacters: [String] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".map { String($0) }
+10 -4
View File
@@ -137,14 +137,20 @@ private func signPow(_ value: Float, _ exp: Float) -> Float {
private func linearTosRGB(_ value: Float) -> Int { private func linearTosRGB(_ value: Float) -> Int {
let v = max(0, min(1, value)) let v = max(0, min(1, value))
if v <= 0.0031308 { return Int(v * 12.92 * 255 + 0.5) } if v <= 0.0031308 {
else { return Int((1.055 * pow(v, 1 / 2.4) - 0.055) * 255 + 0.5) } 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<Type: BinaryInteger>(_ value: Type) -> Float { private func sRGBToLinear<Type: BinaryInteger>(_ value: Type) -> Float {
let v = Float(Int64(value)) / 255 let v = Float(Int64(value)) / 255
if v <= 0.04045 { return v / 12.92 } if v <= 0.04045 {
else { return pow((v + 0.055) / 1.055, 2.4) } return v / 12.92
} else {
return pow((v + 0.055) / 1.055, 2.4)
}
} }
private let encodeCharacters: [String] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".map { String($0) } private let encodeCharacters: [String] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".map { String($0) }
@@ -113,8 +113,12 @@ nonisolated extension String {
let isStrongRTL = (0x0590...0x08FF).contains(value) || let isStrongRTL = (0x0590...0x08FF).contains(value) ||
(0xFB1D...0xFDFF).contains(value) || (0xFB1D...0xFDFF).contains(value) ||
(0xFE70...0xFEFF).contains(value) (0xFE70...0xFEFF).contains(value)
if isStrongRTL { return true } if isStrongRTL {
if scalar.properties.isAlphabetic { return false } return true
}
if scalar.properties.isAlphabetic {
return false
}
} }
return false return false
} }
@@ -43,7 +43,9 @@ struct PINTextField: View {
func sanitize(_ pinCode: String) -> String { func sanitize(_ pinCode: String) -> String {
var sanitized = pinCode 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) return sanitized.filter(\.isNumber)
} }
} }
@@ -274,7 +274,9 @@ extension HomeScreenRoom {
let callBadge = if summary.hasOngoingCall { let callBadge = if summary.hasOngoingCall {
summary.activeCallIntent == .audio ? CallBadgeType.voice : CallBadgeType.video summary.activeCallIntent == .audio ? CallBadgeType.voice : CallBadgeType.video
} else { CallBadgeType.none } } else {
CallBadgeType.none
}
let type: HomeScreenRoom.RoomType = switch summary.joinRequestType { let type: HomeScreenRoom.RoomType = switch summary.joinRequestType {
case .invite(let inviter): .invite(inviterDetails: inviter.map(RoomInviterDetails.init)) case .invite(let inviter): .invite(inviterDetails: inviter.map(RoomInviterDetails.init))
@@ -49,7 +49,9 @@ struct InviteUsersScreenViewState: BindableState {
} }
func isUserDisabled(_ user: UserProfileProxy) -> Bool { func isUserDisabled(_ user: UserProfileProxy) -> Bool {
if isInviteeMandatory(user) { return true } if isInviteeMandatory(user) {
return true
}
let membershipState = membershipState(user) let membershipState = membershipState(user)
return membershipState == .invite || membershipState == .join return membershipState == .invite || membershipState == .join
} }
@@ -38,7 +38,11 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
self.userIndicatorController = userIndicatorController self.userIndicatorController = userIndicatorController
self.appSettings = appSettings 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, super.init(initialViewState: InviteUsersScreenViewState(selectedUsers: mandatoryInvitees,
mandatoryInvitees: mandatoryInvitees, mandatoryInvitees: mandatoryInvitees,
@@ -30,7 +30,9 @@ enum LocationSharingInteractionMode: Hashable {
case viewLive(sender: TimelineItemSender?, initialLiveLocationShare: LiveLocationShare?) case viewLive(sender: TimelineItemSender?, initialLiveLocationShare: LiveLocationShare?)
var isPicker: Bool { var isPicker: Bool {
if case .picker = self { return true } if case .picker = self {
return true
}
return false return false
} }
@@ -97,7 +99,9 @@ struct LocationSharingScreenViewState: BindableState {
case .viewLive: case .viewLive:
return liveLocationShares.compactMap { share in return liveLocationShares.compactMap { share in
guard let geoURI = share.geoURI else { return nil } 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 profile = userProfiles[share.userID] ?? UserProfileProxy(userID: share.userID)
let kind = LocationMarkerKind.liveUser(profile) let kind = LocationMarkerKind.liveUser(profile)
@@ -145,8 +145,12 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati
state.liveLocationShares = liveLocationsShares state.liveLocationShares = liveLocationsShares
.filter { !(isStoppingLiveLocation && ownUserID == $0.userID) } .filter { !(isStoppingLiveLocation && ownUserID == $0.userID) }
.sorted { lhs, rhs in .sorted { lhs, rhs in
if lhs.userID == ownUserID { return true } if lhs.userID == ownUserID {
if rhs.userID == ownUserID { return false } return true
}
if rhs.userID == ownUserID {
return false
}
return lhs.timestamp > rhs.timestamp return lhs.timestamp > rhs.timestamp
} }
@@ -271,8 +271,12 @@ private struct PreviewView: UIViewControllerRepresentable {
private func previewItemTitle(for url: URL) -> String? { private func previewItemTitle(for url: URL) -> String? {
guard let type = UTType(filenameExtension: url.pathExtension) else { return view.title } guard let type = UTType(filenameExtension: url.pathExtension) else { return view.title }
if type.conforms(to: .image) { return L10n.a11yPhotoPreview } if type.conforms(to: .image) {
if type.conforms(to: .movie) || type.conforms(to: .video) { return L10n.a11yVideoPreview } return L10n.a11yPhotoPreview
}
if type.conforms(to: .movie) || type.conforms(to: .video) {
return L10n.a11yVideoPreview
}
return view.title return view.title
} }
@@ -121,7 +121,9 @@ struct RoomScreen: View {
.alert(item: $context.alertInfo) .alert(item: $context.alertInfo)
.timelineMediaPreview(viewModel: $context.mediaPreviewViewModel) .timelineMediaPreview(viewModel: $context.mediaPreviewViewModel)
.onChange(of: pillSourceButtonIsVisible) { _, isVisible in .onChange(of: pillSourceButtonIsVisible) { _, isVisible in
if !isVisible { dismissMarkAsReadPill() } if !isVisible {
dismissMarkAsReadPill()
}
} }
.track(screen: .Room) .track(screen: .Room)
.sentryTrace("\(Self.self)") .sentryTrace("\(Self.self)")
@@ -286,7 +286,9 @@ struct TimelineState {
/// value to ``itemsDictionary``. /// value to ``itemsDictionary``.
mutating func recomputeReadMarkerUniqueID() { mutating func recomputeReadMarkerUniqueID() {
readMarkerUniqueID = itemsDictionary.first { _, viewState in readMarkerUniqueID = itemsDictionary.first { _, viewState in
if case .readMarker = viewState.type { return true } if case .readMarker = viewState.type {
return true
}
return false return false
}?.key }?.key
} }
@@ -103,7 +103,9 @@ class TimelineTableViewController: UIViewController {
var isLive = true { var isLive = true {
didSet { didSet {
// Update isScrolledToBottom when switching back to a live timeline. // Update isScrolledToBottom when switching back to a live timeline.
if isLive { scrollViewDidScroll(tableView) } if isLive {
scrollViewDidScroll(tableView)
}
} }
} }
@@ -113,7 +113,11 @@ struct TimelineItemMenuActionProvider {
} }
if canRedactItem(item) { 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)) secondaryActions.append(.redact(isMedia: isMedia))
} }
@@ -74,7 +74,9 @@ struct SessionVerificationViewModelTests {
let deferred = deferFulfillment(sessionVerificationController.actions let deferred = deferFulfillment(sessionVerificationController.actions
.delay(for: .seconds(0.1), scheduler: DispatchQueue.main)) { callback in .delay(for: .seconds(0.1), scheduler: DispatchQueue.main)) { callback in
if case .finished = callback { return true } if case .finished = callback {
return true
}
return false return false
} }
@@ -92,7 +94,9 @@ struct SessionVerificationViewModelTests {
let deferred = deferFulfillment(sessionVerificationController.actions let deferred = deferFulfillment(sessionVerificationController.actions
.delay(for: .seconds(0.1), scheduler: DispatchQueue.main)) { callback in .delay(for: .seconds(0.1), scheduler: DispatchQueue.main)) { callback in
if case .cancelled = callback { return true } if case .cancelled = callback {
return true
}
return false return false
} }
@@ -98,7 +98,9 @@ public struct ListRowLabel<Icon: View>: View {
var iconForegroundColor: Color { var iconForegroundColor: Color {
guard isEnabled else { return .compound.iconTertiaryAlpha } guard isEnabled else { return .compound.iconTertiaryAlpha }
if role == .destructive { return .compound.iconCriticalPrimary } if role == .destructive {
return .compound.iconCriticalPrimary
}
if hideIconBackground { if hideIconBackground {
return .compound.iconTertiaryAlpha return .compound.iconTertiaryAlpha
} else { } else {
@@ -111,7 +113,9 @@ public struct ListRowLabel<Icon: View>: View {
} }
var iconBackgroundColor: Color { var iconBackgroundColor: Color {
if hideIconBackground { return .clear } if hideIconBackground {
return .clear
}
if #available(iOS 26, *) { if #available(iOS 26, *) {
return .clear return .clear
} else { } else {