From 3036fb74bdfbdb87ab72dbe94eb6160045967ddc Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 19 Jan 2026 09:19:08 -0800 Subject: [PATCH] =?UTF-8?q?Put=20a=20guard=E2=80=99s=20return=20statement?= =?UTF-8?q?=20on=20its=20own=20line.=20It=E2=80=99s=20quicker=20for=20me?= =?UTF-8?q?=20to=20parse=20and=20easier=20to=20set=20a=20breakpoint.=20(Ye?= =?UTF-8?q?s,=20I=20know=20that=20we=20can=20set=20a=20breakpoint=20for=20?= =?UTF-8?q?an=20inline=20return.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainFeedCollectionViewController.swift | 44 ++++++++++++---- iOS/SceneCoordinator.swift | 52 ++++++++++++++----- 2 files changed, 72 insertions(+), 24 deletions(-) diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index df6e704d1..2be641067 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -39,7 +39,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab // If the first responder is the WKWebView (PreloadedWebView) we don't want to supply any keyboard // commands that the system is looking for by going up the responder chain. They will interfere with // the WKWebViews built in hardware keyboard shortcuts, specifically the up and down arrow keys. - guard let current = UIResponder.currentFirstResponder, !(current is PreloadedWebView) else { return nil } + guard let current = UIResponder.currentFirstResponder, !(current is PreloadedWebView) else { + return nil + } return keyboardManager.keyCommands } @@ -225,7 +227,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab dataSource = UICollectionViewDiffableDataSource( collectionView: collectionView ) { [weak self] collectionView, indexPath, feedNode -> UICollectionViewCell? in - guard let self else { return nil } + guard let self else { + return nil + } if feedNode.node.representedObject is Folder { let cell = collectionView.dequeueReusableCell( @@ -246,7 +250,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } dataSource.supplementaryViewProvider = { [weak self] collectionView, kind, indexPath in - guard let self else { return nil } + guard let self else { + return nil + } guard kind == UICollectionView.elementKindSectionHeader else { return UICollectionReusableView() } @@ -549,7 +555,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } func configure(_ cell: MainFeedCollectionViewCell, indexPath: IndexPath) { - guard let node = coordinator.nodeFor(indexPath) else { return } + guard let node = coordinator.nodeFor(indexPath) else { + return + } var indentationLevel = 0 if node.parent?.representedObject is Folder { indentationLevel = 1 @@ -565,7 +573,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab /// Configure folders func configure(_ cell: MainFeedCollectionViewFolderCell, indexPath: IndexPath) { - guard let node = coordinator.nodeFor(indexPath) else { return } + guard let node = coordinator.nodeFor(indexPath) else { + return + } if let folder = node.representedObject as? Folder { cell.folderTitle.text = folder.nameForDisplay @@ -590,7 +600,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } private func reloadAllVisibleCells(completion: (() -> Void)? = nil) { - guard let indexPaths = collectionView.indexPathsForSelectedItems else { return } + guard let indexPaths = collectionView.indexPathsForSelectedItems else { + return + } collectionView.reloadItems(at: indexPaths) restoreSelectionIfNecessary(adjustScroll: false) } @@ -628,7 +640,9 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab let node: Node? = coordinator.rootNode.descendantNodeRepresentingObject(unreadCountProvider as AnyObject) - guard let unreadCountNode = node, let indexPath = coordinator.indexPathFor(unreadCountNode) else { return } + guard let unreadCountNode = node, let indexPath = coordinator.indexPathFor(unreadCountNode) else { + return + } if let cell = collectionView.cellForItem(at: indexPath) as? MainFeedCollectionViewCell { cell.unreadCount = unreadCountProvider.unreadCount @@ -813,7 +827,9 @@ extension MainFeedCollectionViewController { func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration { return UIContextMenuConfiguration(identifier: MainFeedRowIdentifier(indexPath: indexPath), previewProvider: nil, actionProvider: { [ weak self] _ in - guard let self = self else { return nil } + guard let self = self else { + return nil + } var menuElements = [UIMenuElement]() @@ -856,7 +872,9 @@ extension MainFeedCollectionViewController { func makeFolderContextMenu(indexPath: IndexPath) -> UIContextMenuConfiguration { return UIContextMenuConfiguration(identifier: MainFeedRowIdentifier(indexPath: indexPath), previewProvider: nil, actionProvider: { [weak self] _ in - guard let self = self else { return nil } + guard let self = self else { + return nil + } var menuElements = [UIMenuElement]() @@ -1089,7 +1107,9 @@ extension MainFeedCollectionViewController { } func rename(indexPath: IndexPath) { - guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { return } + guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { + return + } let formatString = NSLocalizedString("Rename “%@”", comment: "Rename feed") let title = NSString.localizedStringWithFormat(formatString as NSString, sidebarItem.nameForDisplay) as String @@ -1144,7 +1164,9 @@ extension MainFeedCollectionViewController { } func delete(indexPath: IndexPath) { - guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { return } + guard let sidebarItem = coordinator.nodeFor(indexPath)?.representedObject as? SidebarItem else { + return + } let title: String let message: String diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index d3a3e2e88..1af2839c2 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -275,7 +275,9 @@ struct FeedNode: Hashable, Sendable { } private var currentArticleRow: Int? { - guard let article = currentArticle else { return nil } + guard let article = currentArticle else { + return nil + } return articles.firstIndex(of: article) } @@ -405,7 +407,9 @@ struct FeedNode: Hashable, Sendable { func handle(_ activity: NSUserActivity) { selectFeed(indexPath: nil) { - guard let activityType = ActivityType(rawValue: activity.activityType) else { return } + guard let activityType = ActivityType(rawValue: activity.activityType) else { + return + } switch activityType { case .restoration: break @@ -771,7 +775,9 @@ struct FeedNode: Hashable, Sendable { func cappedIndexPath(_ indexPath: IndexPath) -> IndexPath { let snapshot = mainFeedCollectionViewController.dataSource.snapshot() let numberOfSections = snapshot.numberOfSections - guard numberOfSections > 0 else { return indexPath } + guard numberOfSections > 0 else { + return indexPath + } guard indexPath.section < numberOfSections else { let lastSection = numberOfSections - 1 @@ -835,7 +841,9 @@ struct FeedNode: Hashable, Sendable { /// This is a special function that expects the caller to change the disclosure arrow state outside this function. /// Failure to do so will get the Sidebar into an invalid state. func expand(_ node: Node) { - guard let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else { return } + guard let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else { + return + } lastExpandedContainers.insert(containerID) expand(containerID) } @@ -863,7 +871,9 @@ struct FeedNode: Hashable, Sendable { /// This is a special function that expects the caller to change the disclosure arrow state outside this function. /// Failure to do so will get the Sidebar into an invalid state. func collapse(_ node: Node) { - guard let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else { return } + guard let containerID = (node.representedObject as? ContainerIdentifiable)?.containerID else { + return + } lastExpandedContainers.remove(containerID) collapse(containerID) } @@ -975,7 +985,9 @@ struct FeedNode: Hashable, Sendable { } func selectArticle(_ article: Article?, animations: Animations = [], isShowingExtractedArticle: Bool? = nil, articleWindowScrollY: Int? = nil) { - guard article != currentArticle else { return } + guard article != currentArticle else { + return + } currentArticle = article activityManager.reading(feed: timelineFeed, article: article) @@ -1030,7 +1042,9 @@ struct FeedNode: Hashable, Sendable { func searchArticles(_ searchString: String, _ searchScope: SearchScope) { - guard isSearching else { return } + guard isSearching else { + return + } if searchString.count < 3 { setTimelineFeed(nil, animated: true) @@ -1212,7 +1226,9 @@ struct FeedNode: Hashable, Sendable { } func toggleRead(_ article: Article) { - guard !article.status.read || article.isAvailableToMarkUnread else { return } + guard !article.status.read || article.isAvailableToMarkUnread else { + return + } markArticlesWithUndo([article], statusKey: .read, flag: !article.status.read) } @@ -1378,12 +1394,16 @@ struct FeedNode: Hashable, Sendable { } func showBrowserForArticle(_ article: Article) { - guard let url = article.preferredURL else { return } + guard let url = article.preferredURL else { + return + } UIApplication.shared.open(url, options: [:]) } func showBrowserForCurrentArticle() { - guard let url = currentArticle?.preferredURL else { return } + guard let url = currentArticle?.preferredURL else { + return + } UIApplication.shared.open(url, options: [:]) } @@ -1434,12 +1454,16 @@ struct FeedNode: Hashable, Sendable { /// `SFSafariViewController` or `SettingsViewController`, /// otherwise, this function does nothing. func dismissIfLaunchingFromExternalAction() { - guard let presentedController = mainFeedCollectionViewController.presentedViewController else { return } + guard let presentedController = mainFeedCollectionViewController.presentedViewController else { + return + } if presentedController.isKind(of: SFSafariViewController.self) { presentedController.dismiss(animated: true, completion: nil) } - guard let settings = presentedController.children.first as? SettingsViewController else { return } + guard let settings = presentedController.children.first as? SettingsViewController else { + return + } settings.dismiss(animated: true, completion: nil) } @@ -2211,7 +2235,9 @@ private extension SceneCoordinator { } func handleReadArticle(_ userInfo: [AnyHashable: Any]?) { - guard let userInfo = userInfo else { return } + guard let userInfo = userInfo else { + return + } guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable: Any], let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,