From 4b1b285d0b6209d11c85fa4ca0fc9fed8c843345 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 23 Jan 2025 22:52:36 -0800 Subject: [PATCH] Fix lint issues. --- .swiftlint.yml | 3 ++ Mac/AppDefaults.swift | 6 ++-- Mac/ShareExtension/ShareViewController.swift | 1 + Shared/ArticleRendering/ArticleRenderer.swift | 1 - Shared/Extensions/ArticleUtilities.swift | 1 - iOS/Add/AddFeedFolderViewController.swift | 4 +-- iOS/AppDefaults.swift | 8 ++--- .../AccountInspectorViewController.swift | 5 +++- iOS/MainFeed/MainFeedViewController.swift | 10 ++++++- iOS/MainFeed/ShadowTableChanges.swift | 7 ----- .../Cell/MainTimelineTableViewCell.swift | 6 +++- iOS/MainTimeline/MainTimelineDataSource.swift | 2 +- iOS/MainTimeline/MainTimelineTitleView.swift | 7 +++-- .../MarkAsReadAlertController.swift | 26 +++++++++------- iOS/MainTimeline/TimelineViewController.swift | 20 +++++++++++-- iOS/Settings/AddAccountViewController.swift | 1 + iOS/Settings/SettingsViewController.swift | 2 ++ .../TimelinePreviewTableViewController.swift | 30 ++++++++++++++++--- iOS/ShareExtension/ShareViewController.swift | 1 + 19 files changed, 98 insertions(+), 43 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index a3b1a5127..3715ce1e6 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,6 +1,7 @@ identifier_name: min_length: 1 max_length: 50 + allowed_symbols: "_" line_length: warning: 200 @@ -18,6 +19,8 @@ disabled_rules: - file_length - force_cast - force_try + - cyclomatic_complexity + - generic_type_name excluded: - Modules/Secrets/Sources/Secrets/SecretKey.swift diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index 065304cdb..dafe67470 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -65,10 +65,10 @@ final class AppDefaults { }() var isFirstRun: Bool = { - if let _ = UserDefaults.standard.object(forKey: Key.firstRunDate) as? Date { - return false + if UserDefaults.standard.object(forKey: Key.firstRunDate) as? Date == nil { + firstRunDate = Date() + return true } - firstRunDate = Date() return true }() diff --git a/Mac/ShareExtension/ShareViewController.swift b/Mac/ShareExtension/ShareViewController.swift index 9301f78a3..30144f2e1 100644 --- a/Mac/ShareExtension/ShareViewController.swift +++ b/Mac/ShareExtension/ShareViewController.swift @@ -23,6 +23,7 @@ class ShareViewController: NSViewController { return NSNib.Name("ShareViewController") } + // swiftlint:disable:next function_body_length override func loadView() { super.loadView() diff --git a/Shared/ArticleRendering/ArticleRenderer.swift b/Shared/ArticleRendering/ArticleRenderer.swift index 6ef1517aa..77a9f3996 100644 --- a/Shared/ArticleRendering/ArticleRenderer.swift +++ b/Shared/ArticleRendering/ArticleRenderer.swift @@ -264,7 +264,6 @@ private extension ArticleRenderer { return d } - // swiftlint:disable:next cyclomatic_complexity func byline() -> String { guard let authors = article?.authors ?? article?.feed?.authors, !authors.isEmpty else { return "" diff --git a/Shared/Extensions/ArticleUtilities.swift b/Shared/Extensions/ArticleUtilities.swift index f9ae31797..c0548c351 100644 --- a/Shared/Extensions/ArticleUtilities.swift +++ b/Shared/Extensions/ArticleUtilities.swift @@ -138,7 +138,6 @@ extension Article { } } - // swiftlint:disable:next cyclomatic_complexity func byline() -> String { guard let authors = authors ?? feed?.authors, !authors.isEmpty else { return "" diff --git a/iOS/Add/AddFeedFolderViewController.swift b/iOS/Add/AddFeedFolderViewController.swift index 8240ace44..991b928fd 100644 --- a/iOS/Add/AddFeedFolderViewController.swift +++ b/iOS/Add/AddFeedFolderViewController.swift @@ -10,13 +10,13 @@ import UIKit import RSCore import Account -protocol AddFeedFolderViewControllerDelegate { +protocol AddFeedFolderViewControllerDelegate: AnyObject { func didSelect(container: Container) } class AddFeedFolderViewController: UITableViewController { - var delegate: AddFeedFolderViewControllerDelegate? + weak var delegate: AddFeedFolderViewControllerDelegate? var initialContainer: Container? var containers = [Container]() diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index 66dd18809..1f2b0647f 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -68,11 +68,11 @@ final class AppDefaults { }() let isFirstRun: Bool = { - if let _ = AppDefaults.store.object(forKey: Key.firstRunDate) as? Date { - return false + if AppDefaults.store.object(forKey: Key.firstRunDate) as? Date == nil { + firstRunDate = Date() + return true } - firstRunDate = Date() - return true + return false }() static var userInterfaceColorPalette: UserInterfaceColorPalette { diff --git a/iOS/Inspector/AccountInspectorViewController.swift b/iOS/Inspector/AccountInspectorViewController.swift index d553756c1..d64c88f95 100644 --- a/iOS/Inspector/AccountInspectorViewController.swift +++ b/iOS/Inspector/AccountInspectorViewController.swift @@ -96,7 +96,10 @@ class AccountInspectorViewController: UITableViewController { let message: String = { switch account.type { case .feedly: - return NSLocalizedString("Are you sure you want to remove this account? NetNewsWire will no longer be able to access articles and feeds unless the account is added again.", comment: "Log Out and Remove Account") + return NSLocalizedString( + "Are you sure you want to remove this account? NetNewsWire will no longer be able to access articles and feeds unless the account is added again.", + comment: "Log Out and Remove Account" + ) default: return NSLocalizedString("Are you sure you want to remove this account? This cannot be undone.", comment: "Remove Account") } diff --git a/iOS/MainFeed/MainFeedViewController.swift b/iOS/MainFeed/MainFeedViewController.swift index 3d22ad32e..7e473ae52 100644 --- a/iOS/MainFeed/MainFeedViewController.swift +++ b/iOS/MainFeed/MainFeedViewController.swift @@ -767,7 +767,15 @@ private extension MainFeedViewController { let unreadCountView = MainFeedUnreadCountView() unreadCountView.unreadCount = 10 - let layout = MainFeedTableViewCellLayout(cellWidth: tableView.bounds.size.width, insets: tableView.safeAreaInsets, label: titleLabel, unreadCountView: unreadCountView, showingEditingControl: false, indent: false, shouldShowDisclosure: false) + let layout = MainFeedTableViewCellLayout( + cellWidth: tableView.bounds.size.width, + insets: tableView.safeAreaInsets, + label: titleLabel, + unreadCountView: unreadCountView, + showingEditingControl: false, + indent: false, + shouldShowDisclosure: false + ) tableView.estimatedRowHeight = layout.height } diff --git a/iOS/MainFeed/ShadowTableChanges.swift b/iOS/MainFeed/ShadowTableChanges.swift index ad5e9a73f..eae2653da 100644 --- a/iOS/MainFeed/ShadowTableChanges.swift +++ b/iOS/MainFeed/ShadowTableChanges.swift @@ -65,11 +65,4 @@ struct ShadowTableChanges { var inserts: Set? var moves: Set? var rowChanges: [RowChanges]? - - init(deletes: Set?, inserts: Set?, moves: Set?, rowChanges: [RowChanges]?) { - self.deletes = deletes - self.inserts = inserts - self.moves = moves - self.rowChanges = rowChanges - } } diff --git a/iOS/MainTimeline/Cell/MainTimelineTableViewCell.swift b/iOS/MainTimeline/Cell/MainTimelineTableViewCell.swift index d32ca7b63..cebad12b5 100644 --- a/iOS/MainTimeline/Cell/MainTimelineTableViewCell.swift +++ b/iOS/MainTimeline/Cell/MainTimelineTableViewCell.swift @@ -293,7 +293,11 @@ private extension MainTimelineTableViewCell { } func showOrHideView(_ view: UIView, _ shouldHide: Bool) { - shouldHide ? hideView(view) : showView(view) + if shouldHide { + hideView(view) + } else { + showView(view) + } } func updateSubviews() { diff --git a/iOS/MainTimeline/MainTimelineDataSource.swift b/iOS/MainTimeline/MainTimelineDataSource.swift index c959aaec1..f0822ee82 100644 --- a/iOS/MainTimeline/MainTimelineDataSource.swift +++ b/iOS/MainTimeline/MainTimelineDataSource.swift @@ -8,10 +8,10 @@ import UIKit +// swiftlint:disable:next line_length class MainTimelineDataSource: UITableViewDiffableDataSource where SectionIdentifierType: Hashable, ItemIdentifierType: Hashable { override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return true } - } diff --git a/iOS/MainTimeline/MainTimelineTitleView.swift b/iOS/MainTimeline/MainTimelineTitleView.swift index 7099ec881..abaac5fe0 100644 --- a/iOS/MainTimeline/MainTimelineTitleView.swift +++ b/iOS/MainTimeline/MainTimelineTitleView.swift @@ -19,7 +19,6 @@ class MainTimelineTitleView: UIView { }() override var accessibilityLabel: String? { - set { } get { if let name = label.text { let unreadLabel = NSLocalizedString("unread", comment: "Unread label for accessibility") @@ -28,6 +27,8 @@ class MainTimelineTitleView: UIView { return nil } } + set { + } } func buttonize() { @@ -47,8 +48,8 @@ extension MainTimelineTitleView: UIPointerInteractionDelegate { func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? { var rect = self.frame - rect.origin.x = rect.origin.x - 10 - rect.size.width = rect.width + 20 + rect.origin.x -= 10 + rect.size.width += 20 return UIPointerStyle(effect: .automatic(UITargetedPreview(view: self)), shape: .roundedRect(rect)) } diff --git a/iOS/MainTimeline/MarkAsReadAlertController.swift b/iOS/MainTimeline/MarkAsReadAlertController.swift index 92f334860..50488ef9e 100644 --- a/iOS/MainTimeline/MarkAsReadAlertController.swift +++ b/iOS/MainTimeline/MarkAsReadAlertController.swift @@ -16,12 +16,14 @@ extension UIBarButtonItem: MarkAsReadAlertControllerSourceType {} struct MarkAsReadAlertController { - static func confirm(_ controller: UIViewController?, - coordinator: SceneCoordinator?, - confirmTitle: String, - sourceType: T, - cancelCompletion: (() -> Void)? = nil, - completion: @escaping () -> Void) where T: MarkAsReadAlertControllerSourceType { + static func confirm( + _ controller: UIViewController?, + coordinator: SceneCoordinator?, + confirmTitle: String, + sourceType: T, + cancelCompletion: (() -> Void)? = nil, + completion: @escaping () -> Void + ) where T: MarkAsReadAlertControllerSourceType { guard let controller = controller, let coordinator = coordinator else { completion() @@ -38,11 +40,13 @@ struct MarkAsReadAlertController { } } - private static func alert(coordinator: SceneCoordinator, - confirmTitle: String, - cancelCompletion: (() -> Void)?, - sourceType: T, - completion: @escaping (UIAlertAction) -> Void) -> UIAlertController where T: MarkAsReadAlertControllerSourceType { + private static func alert( + coordinator: SceneCoordinator, + confirmTitle: String, + cancelCompletion: (() -> Void)?, + sourceType: T, + completion: @escaping (UIAlertAction) -> Void + ) -> UIAlertController where T: MarkAsReadAlertControllerSourceType { let title = NSLocalizedString("Mark As Read", comment: "Mark As Read") let message = NSLocalizedString("You can turn this confirmation off in Settings.", diff --git a/iOS/MainTimeline/TimelineViewController.swift b/iOS/MainTimeline/TimelineViewController.swift index f75f9bcd0..d4e08b66c 100644 --- a/iOS/MainTimeline/TimelineViewController.swift +++ b/iOS/MainTimeline/TimelineViewController.swift @@ -563,7 +563,23 @@ class TimelineViewController: UITableViewController, UndoableCommandRunner { let prototypeID = "prototype" let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, dateArrived: Date()) - let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, feedID: prototypeID, uniqueID: prototypeID, title: Constants.prototypeText, contentHTML: nil, contentText: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, datePublished: nil, dateModified: nil, authors: nil, status: status) + let prototypeArticle = Article( + accountID: prototypeID, + articleID: prototypeID, + feedID: prototypeID, + uniqueID: prototypeID, + title: Constants.prototypeText, + contentHTML: nil, + contentText: nil, + url: nil, + externalURL: nil, + summary: nil, + imageURL: nil, + datePublished: nil, + dateModified: nil, + authors: nil, + status: status + ) let prototypeCellData = MainTimelineCellData(article: prototypeArticle, showFeedName: .feed, feedName: "Prototype Feed Name", byline: nil, iconImage: nil, showIcon: false, numberOfLines: numberOfTextLines, iconSize: iconSize) @@ -574,9 +590,7 @@ class TimelineViewController: UITableViewController, UndoableCommandRunner { let layout = MainTimelineDefaultCellLayout(width: tableView.bounds.width, insets: tableView.safeAreaInsets, cellData: prototypeCellData) tableView.estimatedRowHeight = layout.height } - } - } // MARK: Searching diff --git a/iOS/Settings/AddAccountViewController.swift b/iOS/Settings/AddAccountViewController.swift index 89e5e7ecd..3b0473291 100644 --- a/iOS/Settings/AddAccountViewController.swift +++ b/iOS/Settings/AddAccountViewController.swift @@ -10,6 +10,7 @@ import Account import UIKit import RSCore +// swiftlint:disable:next class_delegate_protocol protocol AddAccountDismissDelegate: UIViewController { func dismiss() } diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index f0bfc502f..a97c32423 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -13,6 +13,7 @@ import SafariServices import SwiftUI import UniformTypeIdentifiers +// swiftlint:disable:next type_body_length class SettingsViewController: UITableViewController { private weak var opmlAccount: Account? @@ -155,6 +156,7 @@ class SettingsViewController: UITableViewController { return cell } + // swiftlint:disable:next function_body_length override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { switch indexPath.section { diff --git a/iOS/Settings/TimelinePreviewTableViewController.swift b/iOS/Settings/TimelinePreviewTableViewController.swift index f0c2713c2..ae38d5423 100644 --- a/iOS/Settings/TimelinePreviewTableViewController.swift +++ b/iOS/Settings/TimelinePreviewTableViewController.swift @@ -63,15 +63,37 @@ class TimelinePreviewTableViewController: UIViewController, UITableViewDelegate, private extension TimelinePreviewTableViewController { var prototypeCellData: MainTimelineCellData { - let longTitle = "Enim ut tellus elementum sagittis vitae et. Nibh praesent tristique magna sit amet purus gravida quis blandit. Neque volutpat ac tincidunt vitae semper quis lectus nulla. Massa id neque aliquam vestibulum morbi blandit. Ultrices vitae auctor eu augue. Enim eu turpis egestas pretium aenean pharetra magna. Eget gravida cum sociis natoque. Sit amet consectetur adipiscing elit. Auctor eu augue ut lectus arcu bibendum. Maecenas volutpat blandit aliquam etiam erat velit. Ut pharetra sit amet aliquam id diam maecenas ultricies. In hac habitasse platea dictumst quisque sagittis purus sit amet." + let longTitle = Constants.prototypeText let prototypeID = "prototype" let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, dateArrived: Date()) - let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, feedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, datePublished: nil, dateModified: nil, authors: nil, status: status) + let prototypeArticle = Article( + accountID: prototypeID, + articleID: prototypeID, + feedID: prototypeID, + uniqueID: prototypeID, + title: longTitle, contentHTML: nil, + contentText: nil, + url: nil, + externalURL: nil, + summary: nil, + imageURL: nil, + datePublished: nil, + dateModified: nil, + authors: nil, + status: status + ) let iconImage = IconImage(AppAssets.faviconTemplateImage.withTintColor(AppAssets.secondaryAccentColor)) - return MainTimelineCellData(article: prototypeArticle, showFeedName: .feed, feedName: "Feed Name", byline: nil, iconImage: iconImage, showIcon: true, numberOfLines: AppDefaults.shared.timelineNumberOfLines, iconSize: AppDefaults.shared.timelineIconSize) + return MainTimelineCellData( + article: prototypeArticle, + showFeedName: .feed, + feedName: "Feed Name", + byline: nil, iconImage: iconImage, + showIcon: true, + numberOfLines: AppDefaults.shared.timelineNumberOfLines, + iconSize: AppDefaults.shared.timelineIconSize + ) } - } diff --git a/iOS/ShareExtension/ShareViewController.swift b/iOS/ShareExtension/ShareViewController.swift index 425c3748e..29d3c3dbd 100644 --- a/iOS/ShareExtension/ShareViewController.swift +++ b/iOS/ShareExtension/ShareViewController.swift @@ -22,6 +22,7 @@ class ShareViewController: SLComposeServiceViewController, ShareFolderPickerCont private var selectedContainer: ExtensionContainer? private var folderItem: SLComposeSheetConfigurationItem! + // swiftlint:disable:next function_body_length override func viewDidLoad() { extensionContainers = ExtensionContainersFile.read()