From d9216a327506089d7f7ba5550abd22ffed98d80e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 2 Jan 2026 15:58:36 -0800 Subject: [PATCH] Fix various SwiftLint warnings. --- .swiftlint.yml | 1 + Modules/Account/Sources/Account/Feed.swift | 2 +- Shared/Commands/DeleteCommand.swift | 19 ++++---- Shared/Timeline/ArticleArray.swift | 5 +- iOS/Add/AddFolderViewController.swift | 2 +- iOS/AppDefaults.swift | 21 ++++---- iOS/ErrorHandler.swift | 2 +- iOS/IconView.swift | 9 ++-- .../FeedInspectorViewController.swift | 6 +-- iOS/KeyboardManager.swift | 2 +- .../MainTimelineViewController.swift | 48 ++++++++++--------- iOS/RootSplitViewController.swift | 2 +- 12 files changed, 56 insertions(+), 63 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 63b33d8bb..d705795a2 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -27,6 +27,7 @@ disabled_rules: - line_length - operator_whitespace - nesting + - class_delegate_protocol excluded: - ".build" diff --git a/Modules/Account/Sources/Account/Feed.swift b/Modules/Account/Sources/Account/Feed.swift index 8321d3094..e0bb8e512 100644 --- a/Modules/Account/Sources/Account/Feed.swift +++ b/Modules/Account/Sources/Account/Feed.swift @@ -322,7 +322,7 @@ extension Feed: OPMLRepresentable { return Set(map { $0.feedID }) } - func sorted() -> Array { + func sorted() -> [Feed] { return sorted(by: { (feed1, feed2) -> Bool in if feed1.nameForDisplay.localizedStandardCompare(feed2.nameForDisplay) == .orderedSame { return feed1.url < feed2.url diff --git a/Shared/Commands/DeleteCommand.swift b/Shared/Commands/DeleteCommand.swift index c4e4539df..956d19c7e 100644 --- a/Shared/Commands/DeleteCommand.swift +++ b/Shared/Commands/DeleteCommand.swift @@ -19,11 +19,11 @@ final class DeleteCommand: UndoableCommand { var redoActionName: String { undoActionName } - let errorHandler: (Error) -> () + let errorHandler: (Error) -> Void private let itemSpecifiers: [SidebarItemSpecifier] - @MainActor init?(nodesToDelete: [Node], treeController: TreeController? = nil, undoManager: UndoManager, errorHandler: @escaping (Error) -> ()) { + @MainActor init?(nodesToDelete: [Node], treeController: TreeController? = nil, undoManager: UndoManager, errorHandler: @escaping (Error) -> Void) { guard DeleteCommand.canDelete(nodesToDelete) else { return nil @@ -77,10 +77,7 @@ final class DeleteCommand: UndoableCommand { } for node in nodes { - if let _ = node.representedObject as? Feed { - continue - } - if let _ = node.representedObject as? Folder { + if node.representedObject is Feed || node.representedObject is Folder { continue } return false @@ -100,7 +97,7 @@ final class DeleteCommand: UndoableCommand { private let folder: Folder? private let feed: Feed? private let path: ContainerPath - private let errorHandler: (Error) -> () + private let errorHandler: (Error) -> Void private var container: Container? { if let parentFolder = parentFolder { @@ -165,9 +162,9 @@ final class DeleteCommand: UndoableCommand { } func restore() { - if let _ = feed { + if feed != nil { restoreFeed() - } else if let _ = folder { + } else if folder != nil { restoreFolder() } } @@ -257,9 +254,9 @@ private struct DeleteActionName { var numberOfFolders = 0 for node in nodes { - if let _ = node.representedObject as? Feed { + if node.representedObject as? Feed != nil { numberOfFeeds += 1 - } else if let _ = node.representedObject as? Folder { + } else if node.representedObject as? Folder != nil { numberOfFolders += 1 } else { return nil // Delete only Feeds and Folders. diff --git a/Shared/Timeline/ArticleArray.swift b/Shared/Timeline/ArticleArray.swift index c1c4b40d0..071d1fae5 100644 --- a/Shared/Timeline/ArticleArray.swift +++ b/Shared/Timeline/ArticleArray.swift @@ -27,10 +27,10 @@ typealias ArticleArray = [Article] func orderedRowIndexes(fromIndex startIndex: Int, wrappingToTop wrapping: Bool) -> [Int] { if startIndex >= self.count { // Wrap around to the top if specified - return wrapping ? Array(0..(startIndex..(0.. Int? { @@ -132,5 +132,4 @@ typealias ArticleArray = [Article] articlesBelow.removeFirst() return articlesBelow } - } diff --git a/iOS/Add/AddFolderViewController.swift b/iOS/Add/AddFolderViewController.swift index eeb1c2931..bd7438d7a 100644 --- a/iOS/Add/AddFolderViewController.swift +++ b/iOS/Add/AddFolderViewController.swift @@ -108,7 +108,7 @@ final class AddFolderViewController: UITableViewController { extension AddFolderViewController: UIPickerViewDataSource, UIPickerViewDelegate { - func numberOfComponents(in pickerView: UIPickerView) ->Int { + func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 } diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index ab85440af..498167acf 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -84,7 +84,7 @@ final class AppDefaults: Sendable { }() let isFirstRun: Bool = { - if let _ = AppDefaults.store.object(forKey: Key.firstRunDate) as? Date { + if AppDefaults.store.object(forKey: Key.firstRunDate) as? Date != nil { return false } firstRunDate = Date() @@ -443,8 +443,7 @@ private extension AppDefaults { static func setSortDirection(for key: String, _ value: ComparisonResult) { if value == .orderedAscending { setInt(for: key, ComparisonResult.orderedAscending.rawValue) - } - else { + } else { setInt(for: key, ComparisonResult.orderedDescending.rawValue) } } @@ -462,14 +461,14 @@ struct StateRestorationInfo { let isShowingExtractedArticle: Bool init(hideReadFeeds: Bool, - expandedContainers: Set, - selectedSidebarItem: SidebarItemIdentifier?, - smartFeedsHidingReadArticles: Set, - feedsHidingReadArticles: [String: Set], - foldersShowingReadArticles: [String: Set], - selectedArticle: ArticleSpecifier?, - articleWindowScrollY: Int, - isShowingExtractedArticle: Bool) { + expandedContainers: Set, + selectedSidebarItem: SidebarItemIdentifier?, + smartFeedsHidingReadArticles: Set, + feedsHidingReadArticles: [String: Set], + foldersShowingReadArticles: [String: Set], + selectedArticle: ArticleSpecifier?, + articleWindowScrollY: Int, + isShowingExtractedArticle: Bool) { self.hideReadFeeds = hideReadFeeds self.expandedContainers = expandedContainers self.selectedSidebarItem = selectedSidebarItem diff --git a/iOS/ErrorHandler.swift b/iOS/ErrorHandler.swift index 7b6afbf6e..10f8517d4 100644 --- a/iOS/ErrorHandler.swift +++ b/iOS/ErrorHandler.swift @@ -14,7 +14,7 @@ struct ErrorHandler: Sendable { private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ErrorHandler") - @Sendable public static func present(_ viewController: UIViewController) -> @Sendable (Error) -> () { + @Sendable public static func present(_ viewController: UIViewController) -> @Sendable (Error) -> Void { return { [weak viewController] error in Task { @MainActor in if UIApplication.shared.applicationState == .active { diff --git a/iOS/IconView.swift b/iOS/IconView.swift index 11ea4f64d..ef18e6496 100644 --- a/iOS/IconView.swift +++ b/iOS/IconView.swift @@ -12,7 +12,7 @@ import RSCore @IBDesignable final class IconView: UIView { - var iconImage: IconImage? = nil { + var iconImage: IconImage? { didSet { guard iconImage !== oldValue else { return @@ -21,8 +21,7 @@ final class IconView: UIView { if traitCollection.userInterfaceStyle == .dark { let isDark = iconImage?.isDark ?? false isDiscernable = !isDark - } - else { + } else { let isBright = iconImage?.isBright ?? false isDiscernable = !isBright } @@ -99,8 +98,7 @@ private extension IconView { } let offset = floor((viewSize.height - imageSize.height) / 2.0) return CGRect(x: offset, y: offset, width: imageSize.width, height: imageSize.height) - } - else if imageSize.height > imageSize.width { + } else if imageSize.height > imageSize.width { let factor = viewSize.height / imageSize.height let width = imageSize.width * factor let originX = floor((viewSize.width - width) / 2.0) @@ -122,4 +120,3 @@ private extension IconView { } } } - diff --git a/iOS/Inspector/FeedInspectorViewController.swift b/iOS/Inspector/FeedInspectorViewController.swift index 47cb1cc58..89a035624 100644 --- a/iOS/Inspector/FeedInspectorViewController.swift +++ b/iOS/Inspector/FeedInspectorViewController.swift @@ -84,7 +84,7 @@ final class FeedInspectorViewController: UITableViewController { } else if authorizationStatus == .authorized { feed.isNotifyAboutNewArticles = notifyAboutNewArticlesSwitch.isOn } else { - UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in + UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { granted, _ in Task { @MainActor in self.updateNotificationSettings() if granted { @@ -122,8 +122,6 @@ final class FeedInspectorViewController: UITableViewController { } return section } - - } // MARK: Table View @@ -214,7 +212,7 @@ extension FeedInspectorViewController { func notificationUpdateErrorAlert() -> UIAlertController { let alert = UIAlertController(title: NSLocalizedString("Enable Notifications", comment: "Notifications"), message: NSLocalizedString("Notifications need to be enabled in the Settings app.", comment: "Notifications need to be enabled in the Settings app."), preferredStyle: .alert) - let openSettings = UIAlertAction(title: NSLocalizedString("Open Settings", comment: "Open Settings"), style: .default) { (action) in + let openSettings = UIAlertAction(title: NSLocalizedString("Open Settings", comment: "Open Settings"), style: .default) { _ in UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly: false], completionHandler: nil) } let dismiss = UIAlertAction(title: NSLocalizedString("Dismiss", comment: "Dismiss"), style: .cancel, handler: nil) diff --git a/iOS/KeyboardManager.swift b/iOS/KeyboardManager.swift index 32c948109..5c507f0ad 100644 --- a/iOS/KeyboardManager.swift +++ b/iOS/KeyboardManager.swift @@ -42,7 +42,7 @@ enum KeyboardType: String, Sendable { let specificFile = Bundle.main.path(forResource: type.rawValue, ofType: "plist")! let specificEntries = NSArray(contentsOfFile: specificFile)! as! [[String: Any]] - _keyCommands.append(contentsOf: specificEntries.compactMap { KeyboardManager.createKeyCommand(keyEntry: $0) } ) + _keyCommands.append(contentsOf: specificEntries.compactMap { KeyboardManager.createKeyCommand(keyEntry: $0) }) } static func createKeyCommand(title: String, action: String, input: String, modifiers: UIKeyModifierFlags) -> UIKeyCommand { diff --git a/iOS/MainTimeline/MainTimelineViewController.swift b/iOS/MainTimeline/MainTimelineViewController.swift index e2c963678..08b7758f2 100644 --- a/iOS/MainTimeline/MainTimelineViewController.swift +++ b/iOS/MainTimeline/MainTimelineViewController.swift @@ -231,7 +231,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu } } if traitCollection.userInterfaceIdiom == .phone { - if let _ = coordinator?.currentArticle { + if coordinator?.currentArticle != nil { if let indexPath = tableView.indexPathForSelectedRow { tableView.deselectRow(at: indexPath, animated: true) } @@ -262,7 +262,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu coordinator?.markAllAsReadInTimeline() } - @IBAction func markAllAsRead(_ sender: Any) { + @IBAction func markAllAsRead(_ sender: Any?) { let title = NSLocalizedString("Mark All as Read", comment: "Mark All as Read") if let source = sender as? UIBarButtonItem { @@ -271,7 +271,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu } } - if let _ = sender as? UIKeyCommand { + if sender as? UIKeyCommand != nil { guard let indexPath = tableView.indexPathForSelectedRow, let contentView = tableView.cellForRow(at: indexPath)?.contentView else { return } @@ -402,7 +402,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu NSLocalizedString("Mark as Unread", comment: "Mark as Unread") : NSLocalizedString("Mark as Read", comment: "Mark as Read") - let readAction = UIContextualAction(style: .normal, title: readTitle) { [weak self] (action, view, completion) in + let readAction = UIContextualAction(style: .normal, title: readTitle) { [weak self] _, _, completion in self?.toggleRead(article) completion(true) } @@ -422,7 +422,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu NSLocalizedString("Unstar", comment: "Unstar") : NSLocalizedString("Star", comment: "Star") - let starAction = UIContextualAction(style: .normal, title: starTitle) { [weak self] (action, view, completion) in + let starAction = UIContextualAction(style: .normal, title: starTitle) { [weak self] _, _, completion in self?.toggleStar(article) completion(true) } @@ -488,7 +488,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu guard let article = dataSource.itemIdentifier(for: indexPath) else { return nil } - return UIContextMenuConfiguration(identifier: indexPath.row as NSCopying, previewProvider: nil, actionProvider: { [weak self] suggestedActions in + return UIContextMenuConfiguration(identifier: indexPath.row as NSCopying, previewProvider: nil, actionProvider: { [weak self] _ in guard let self = self else { return nil } @@ -855,7 +855,7 @@ private extension MainTimelineViewController { NSLocalizedString("Mark as Read", comment: "Mark as Read") let image = article.status.read ? Assets.Images.circleClosed : Assets.Images.circleOpen - let action = UIAction(title: title, image: image) { [weak self] action in + let action = UIAction(title: title, image: image) { [weak self] _ in self?.toggleRead(article) } @@ -874,7 +874,7 @@ private extension MainTimelineViewController { NSLocalizedString("Mark as Starred", comment: "Mark as Starred") let image = article.status.starred ? Assets.Images.starOpen : Assets.Images.starClosed - let action = UIAction(title: title, image: image) { [weak self] action in + let action = UIAction(title: title, image: image) { [weak self] _ in self?.toggleStar(article) } @@ -898,7 +898,7 @@ private extension MainTimelineViewController { let title = NSLocalizedString("Mark Above as Read", comment: "Mark Above as Read") let image = Assets.Images.markAboveAsRead - let action = UIAction(title: title, image: image) { [weak self] action in + let action = UIAction(title: title, image: image) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in self?.markAboveAsRead(article) } @@ -923,7 +923,7 @@ private extension MainTimelineViewController { let title = NSLocalizedString("Mark Below as Read", comment: "Mark Below as Read") let image = Assets.Images.markBelowAsRead - let action = UIAction(title: title, image: image) { [weak self] action in + let action = UIAction(title: title, image: image) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in self?.markBelowAsRead(article) } @@ -941,7 +941,7 @@ private extension MainTimelineViewController { completion(true) } - let action = UIAlertAction(title: title, style: .default) { [weak self] action in + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in self?.markAboveAsRead(article) completion(true) @@ -960,7 +960,7 @@ private extension MainTimelineViewController { completion(true) } - let action = UIAlertAction(title: title, style: .default) { [weak self] action in + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in self?.markBelowAsRead(article) completion(true) @@ -984,7 +984,7 @@ private extension MainTimelineViewController { !timelineFeedIsEqualTo(feed) else { return nil } let title = NSLocalizedString("Go to Feed", comment: "Go to Feed") - let action = UIAction(title: title, image: Assets.Images.openInSidebar) { [weak self] action in + let action = UIAction(title: title, image: Assets.Images.openInSidebar) { [weak self] _ in self?.discloseFeed(feed, animations: [.scroll, .navigation]) } return action @@ -995,7 +995,7 @@ private extension MainTimelineViewController { !timelineFeedIsEqualTo(feed) else { return nil } let title = NSLocalizedString("Go to Feed", comment: "Go to Feed") - let action = UIAlertAction(title: title, style: .default) { [weak self] action in + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in self?.discloseFeed(feed, animations: [.scroll, .navigation]) completion(true) } @@ -1021,7 +1021,7 @@ private extension MainTimelineViewController { let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command") let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String - let action = UIAction(title: title, image: Assets.Images.markAllAsRead) { [weak self] action in + let action = UIAction(title: title, image: Assets.Images.markAllAsRead) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in self?.markAllAsRead(articles) } @@ -1046,7 +1046,7 @@ private extension MainTimelineViewController { completion(true) } - let action = UIAlertAction(title: title, style: .default) { [weak self] action in + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in self?.markAllAsRead(articles) completion(true) @@ -1058,7 +1058,7 @@ private extension MainTimelineViewController { func copyArticleURLAction(_ article: Article) -> UIAction? { guard let url = article.preferredURL else { return nil } let title = NSLocalizedString("Copy Article URL", comment: "Copy Article URL") - let action = UIAction(title: title, image: Assets.Images.copy) { action in + let action = UIAction(title: title, image: Assets.Images.copy) { _ in UIPasteboard.general.url = url } return action @@ -1067,7 +1067,7 @@ private extension MainTimelineViewController { func copyExternalURLAction(_ article: Article) -> UIAction? { guard let externalLink = article.externalLink, externalLink != article.preferredLink, let url = URL(string: externalLink) else { return nil } let title = NSLocalizedString("Copy External URL", comment: "Copy External URL") - let action = UIAction(title: title, image: Assets.Images.copy) { action in + let action = UIAction(title: title, image: Assets.Images.copy) { _ in UIPasteboard.general.url = url } return action @@ -1081,7 +1081,7 @@ private extension MainTimelineViewController { func openInBrowserAction(_ article: Article) -> UIAction? { guard let _ = article.preferredURL else { return nil } let title = NSLocalizedString("Open in Browser", comment: "Open in Browser") - let action = UIAction(title: title, image: Assets.Images.safari) { [weak self] action in + let action = UIAction(title: title, image: Assets.Images.safari) { [weak self] _ in self?.showBrowserForArticle(article) } return action @@ -1091,7 +1091,7 @@ private extension MainTimelineViewController { guard let _ = article.preferredURL else { return nil } let title = NSLocalizedString("Open in Browser", comment: "Open in Browser") - let action = UIAlertAction(title: title, style: .default) { [weak self] action in + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in self?.showBrowserForArticle(article) completion(true) } @@ -1101,7 +1101,9 @@ private extension MainTimelineViewController { func shareDialogForTableCell(indexPath: IndexPath, url: URL, title: String?) { let activityViewController = UIActivityViewController(url: url, title: title, applicationActivities: nil) - guard let cell = tableView.cellForRow(at: indexPath) else { return } + guard let cell = tableView.cellForRow(at: indexPath) else { + return + } let popoverController = activityViewController.popoverPresentationController popoverController?.sourceView = cell popoverController?.sourceRect = CGRect(x: 0, y: 0, width: cell.frame.size.width, height: cell.frame.size.height) @@ -1112,7 +1114,7 @@ private extension MainTimelineViewController { func shareAction(_ article: Article, indexPath: IndexPath) -> UIAction? { guard let url = article.preferredURL else { return nil } let title = NSLocalizedString("Share", comment: "Share") - let action = UIAction(title: title, image: Assets.Images.share) { [weak self] action in + let action = UIAction(title: title, image: Assets.Images.share) { [weak self] _ in self?.shareDialogForTableCell(indexPath: indexPath, url: url, title: article.title) } return action @@ -1121,7 +1123,7 @@ private extension MainTimelineViewController { func shareAlertAction(_ article: Article, indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? { guard let url = article.preferredURL else { return nil } let title = NSLocalizedString("Share", comment: "Share") - let action = UIAlertAction(title: title, style: .default) { [weak self] action in + let action = UIAlertAction(title: title, style: .default) { [weak self] _ in completion(true) self?.shareDialogForTableCell(indexPath: indexPath, url: url, title: article.title) } diff --git a/iOS/RootSplitViewController.swift b/iOS/RootSplitViewController.swift index ea45abc9e..1b5730fa6 100644 --- a/iOS/RootSplitViewController.swift +++ b/iOS/RootSplitViewController.swift @@ -58,7 +58,7 @@ final class RootSplitViewController: UISplitViewController { } @objc func markAllAsReadAndGoToNextUnread(_ sender: Any?) { - coordinator.markAllAsReadInTimeline() { + coordinator.markAllAsReadInTimeline { self.coordinator.selectNextUnread() } }