Swift format enforce isEmpty rule (#5843)

* swift format enforce isEmpty rule

* revert scheme

* use trailing closure
This commit is contained in:
Mauro
2026-07-06 15:39:16 +02:00
committed by GitHub
parent d2ef1e71f9
commit 0a77ba6c90
27 changed files with 60 additions and 60 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ extension UIImage {
hash += sizeFlag.encode83(length: 1)
let maximumValue: Float
if ac.count > 0 {
if !ac.isEmpty {
let actualMaximumValue = ac.map { max(abs($0.0), abs($0.1), abs($0.2)) }.max()!
let quantisedMaximumValue = Int(max(0, min(82, floor(actualMaximumValue * 166 - 0.5))))
maximumValue = Float(quantisedMaximumValue + 1) / 166
@@ -24,7 +24,7 @@ nonisolated struct CollapsibleReactionLayout: Layout {
var rowsBeforeCollapsible: Int?
func sizeThatFits(proposal: ProposedViewSize, subviews: some FlowLayoutSubviews, cache: inout ()) -> CGSize {
guard let subviewsByType = getSubviewsByItemType(subviews: Array(subviews)), subviewsByType.reactions.count > 0 else {
guard let subviewsByType = getSubviewsByItemType(subviews: Array(subviews)), !subviewsByType.reactions.isEmpty else {
return .zero
}
@@ -53,7 +53,7 @@ nonisolated struct CollapsibleReactionLayout: Layout {
}
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: some FlowLayoutSubviews, cache: inout ()) {
guard let subviewsByType = getSubviewsByItemType(subviews: Array(subviews)), subviewsByType.reactions.count > 0 else {
guard let subviewsByType = getSubviewsByItemType(subviews: Array(subviews)), !subviewsByType.reactions.isEmpty else {
subviews.forEach { subview in
subview.place(at: Self.pointOffscreen, anchor: .leading, proposal: .zero)
}
@@ -119,7 +119,7 @@ nonisolated struct CollapsibleReactionLayout: Layout {
currentRow.append(subview)
}
// If there are items in the current row remember to append it to the returned value
if currentRow.count > 0 {
if !currentRow.isEmpty {
rows.append(currentRow)
}
return rows
@@ -243,7 +243,7 @@ nonisolated struct CollapsibleReactionLayout: Layout {
addMoreButton = subview
}
}
guard let collapseButton, let addMoreButton, reactions.count > 0 else {
guard let collapseButton, let addMoreButton, !reactions.isEmpty else {
return nil
}
return ReactionSubviews(reactions: reactions, collapseButton: collapseButton, addMoreButton: addMoreButton)
@@ -40,7 +40,7 @@ extension XCUIApplication {
/// app instance anyway, and some of our tests assert that a default focus has been set on the text field,
/// so having a method that would set the focus and show the keyboard isn't always desirable.
func showKeyboardIfNeeded() {
if UIDevice.current.userInterfaceIdiom == .pad, keyboards.count == 0 {
if UIDevice.current.userInterfaceIdiom == .pad, keyboards.isEmpty {
buttons["Keyboard"].tap()
buttons["Show Keyboard"].tap()
}
@@ -347,7 +347,7 @@ nonisolated struct AttributedStringBuilder: AttributedStringBuilderProtocol {
TextParsingMatch(type: .atRoom, range: match.range)
})
guard matches.count > 0 else {
guard !matches.isEmpty else {
return
}
@@ -68,7 +68,7 @@ struct RoomAvatarImage: View {
onTap: onAvatarTap)
case .heroes(let users):
// We will expand upon this with more stack sizes in the future.
if users.count == 0 {
if users.isEmpty {
let _ = assertionFailure("We should never pass empty heroes here.")
PlaceholderAvatarImage(name: nil, contentID: "")
} else if users.count == 2 {
@@ -78,6 +78,6 @@ struct CreateRoomSpaceSelectionSheet_Previews: PreviewProvider, TestablePreview
static var previews: some View {
CreateRoomSpaceSelectionSheet(context: viewModel.context)
.snapshotPreferences(expect: viewModel.context.$viewState.map { $0.editableSpaces.count > 0 })
.snapshotPreferences(expect: viewModel.context.$viewState.map { !$0.editableSpaces.isEmpty })
}
}
@@ -142,7 +142,7 @@ struct HomeScreenContent: View {
guard let scrollView = scrollViewAdapter.scrollView,
scrollViewAdapter.isScrolling.value == false, // Ignore while scrolling
context.searchQuery.isEmpty == true, // Ignore while filtering
context.viewState.visibleRooms.count > 0 else {
!context.viewState.visibleRooms.isEmpty else {
return
}
@@ -81,7 +81,7 @@ struct RoomMembersListScreenViewState: BindableState {
var shouldShowEmptyState: Bool {
switch bindings.mode {
case .banned:
visibleBannedMembers.count == 0
visibleBannedMembers.isEmpty
case .members:
visibleInvitedMembers.count + visibleJoinedMembers.count == 0
}
@@ -105,7 +105,7 @@ class RoomMembersListScreenViewModel: RoomMembersListScreenViewModelType, RoomMe
self.currentUserProxy = members.first { $0.userID == roomProxy.ownUserID }
var newBindings = state.bindings
if roomMembersDetails.bannedMembers.count == 0 {
if roomMembersDetails.bannedMembers.isEmpty {
newBindings.mode = .members
}
self.state = .init(joinedMembersCount: roomProxy.infoPublisher.value.joinedMembersCount,
@@ -279,7 +279,7 @@ private class ElementTextView: UITextView, PillAttachmentViewProviderDelegate {
return false
}
return UIPasteboard.general.itemProviders.filter { !$0.isSupportedForPasteOrDrop }.isEmpty
return !UIPasteboard.general.itemProviders.contains { !$0.isSupportedForPasteOrDrop }
}
override func paste(_ sender: Any?) {
@@ -293,7 +293,7 @@ private class ElementTextView: UITextView, PillAttachmentViewProviderDelegate {
let providers = UIPasteboard.general.itemProviders
// Use the default behavior if there are any unsupported providers
guard providers.filter({ !$0.isSupportedForPasteOrDrop }).isEmpty else {
guard !providers.contains(where: { !$0.isSupportedForPasteOrDrop }) else {
super.paste(sender)
return
}
@@ -82,7 +82,7 @@ private extension RoomInfoProxyProtocol {
return alias
}
guard heroes.count > 0 else {
guard !heroes.isEmpty else {
return ""
}
@@ -136,7 +136,7 @@ struct SpaceScreen: View {
}
.accessibilityIdentifier(A11yIdentifiers.spaceScreen.addExistingRooms)
if context.viewState.rooms.count > 0 {
if !context.viewState.rooms.isEmpty {
Button { context.send(viewAction: .manageChildren) } label: {
Label(L10n.actionManageRooms, icon: \.edit)
}
@@ -116,12 +116,12 @@ extension RoomInfoProxyProtocol {
// Check if the canonical alias matches the homeserver
if let canonicalAlias,
canonicalAlias.range(of: serverName) != nil {
canonicalAlias.contains(serverName) {
return canonicalAlias
}
// Otherwise check the alternative aliases and return the first one that matches
if let matchingAlternativeAlias = alternativeAliases.first(where: { $0.range(of: serverName) != nil }) {
if let matchingAlternativeAlias = alternativeAliases.first(where: { $0.contains(serverName) }) {
return matchingAlternativeAlias
}
@@ -103,7 +103,7 @@ nonisolated extension RoomSummary: CustomStringConvertible {
return alias
}
guard heroes.count > 0 else {
guard !heroes.isEmpty else {
return ""
}
@@ -861,7 +861,7 @@ nonisolated struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
isDM: isDM,
isDeclinedByMe: declinedBy.contains(userID),
isDeclined: declinedBy.count > 0,
isDeclined: !declinedBy.isEmpty,
isVoiceCall: isVoiceCall,
properties: .init())
}