diff --git a/.swiftlint.yml b/.swiftlint.yml index 87b7f273d..749e6941b 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -25,11 +25,14 @@ disabled_rules: - type_body_length - function_parameter_count - line_length + - operator_whitespace excluded: - Modules/Secrets/Sources/Secrets/SecretKey.swift - Modules/Account/Tests/AccountTests/Feedly/ + - Modules/Account/Sources/Account/Feedly/ - Widget/Resources/Localized.swift - Shared/Extensions/NSAttributedString+NetNewsWire.swift + - buildscripts/ diff --git a/Mac/Inspector/FolderInspectorViewController.swift b/Mac/Inspector/FolderInspectorViewController.swift index b88bf7732..2c785c6fb 100644 --- a/Mac/Inspector/FolderInspectorViewController.swift +++ b/Mac/Inspector/FolderInspectorViewController.swift @@ -35,11 +35,7 @@ final class FolderInspectorViewController: NSViewController, Inspector { var windowTitle: String = NSLocalizedString("Folder Inspector", comment: "Folder Inspector window title") func canInspect(_ objects: [Any]) -> Bool { - - guard let _ = singleFolder(from: objects) else { - return false - } - return true + singleFolder(from: objects) != nil } // MARK: NSViewController diff --git a/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift b/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift index dce4e3eea..457919e6c 100644 --- a/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift +++ b/Mac/MainWindow/Timeline/Cell/TimelineCellAppearance.swift @@ -65,7 +65,7 @@ struct TimelineCellAppearance: Equatable { extension NSEdgeInsets: @retroactive Equatable { - public static func == (lhs: NSEdgeInsets, rhs: NSEdgeInsets) -> Bool { + public static func ==(lhs: NSEdgeInsets, rhs: NSEdgeInsets) -> Bool { return lhs.left == rhs.left && lhs.top == rhs.top && lhs.right == rhs.right && lhs.bottom == rhs.bottom } } diff --git a/Mac/Scriptability/Account+Scriptability.swift b/Mac/Scriptability/Account+Scriptability.swift index 5b7c5fc06..e424e2327 100644 --- a/Mac/Scriptability/Account+Scriptability.swift +++ b/Mac/Scriptability/Account+Scriptability.swift @@ -153,28 +153,28 @@ class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectConta } @objc(accountType) - var accountType: OSType { - var osType: String = "" - switch self.account.type { - case .onMyMac: - osType = "Locl" + var accountType: OSType { + var osType: String = "" + switch self.account.type { + case .onMyMac: + osType = "Locl" case .cloudKit: - osType = "Clkt" - case .feedly: - osType = "Fdly" - case .feedbin: - osType = "Fdbn" - case .newsBlur: - osType = "NBlr" + osType = "Clkt" + case .feedly: + osType = "Fdly" + case .feedbin: + osType = "Fdbn" + case .newsBlur: + osType = "NBlr" case .freshRSS: - osType = "Frsh" + osType = "Frsh" case .inoreader: - osType = "Inrd" + osType = "Inrd" case .bazQux: - osType = "Bzqx" + osType = "Bzqx" case .theOldReader: - osType = "Tord" - } - return osType.fourCharCode - } + osType = "Tord" + } + return osType.fourCharCode + } } diff --git a/Mac/Scriptability/AppDelegate+Scriptability.swift b/Mac/Scriptability/AppDelegate+Scriptability.swift index cea394199..c7955b1c6 100644 --- a/Mac/Scriptability/AppDelegate+Scriptability.swift +++ b/Mac/Scriptability/AppDelegate+Scriptability.swift @@ -24,7 +24,7 @@ protocol AppDelegateAppleEvents { func getURL(_ event: NSAppleEventDescriptor, _ withReplyEvent: NSAppleEventDescriptor) } -protocol ScriptingAppDelegate { +protocol ScriptingAppDelegate: AnyObject { var scriptingCurrentArticle: Article? {get} var scriptingSelectedArticles: [Article] {get} var scriptingMainWindowController: ScriptingMainWindowController? {get} @@ -171,14 +171,14 @@ class NetNewsWireExistsCommand: NSExistsCommand { // to be another object type. e.g., 'permalink of the current article' parses as // of of // cocoa would send the top level object (the app) a doesExist message for a nested property, and - // it errors out because it doesn't know how to handle that + // it errors out because it doesn't know how to handle that` // What we do instead is simply see if the defaultImplementation errors, and if it does, the object // must not exist. Otherwise, we return the result of the defaultImplementation // The wrinkle is that it is possible that the direct object is a list, so we need to // handle that case as well override func performDefaultImplementation() -> Any? { - guard let result = super.performDefaultImplementation() else { return NSNumber(booleanLiteral: false) } + guard let result = super.performDefaultImplementation() else { return NSNumber(value: false) } return result } } diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index fefc9a582..5a75ee1fb 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -388,11 +388,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return grantingType.oauthAuthorizationCodeGrantRequest() } - public static func requestOAuthAccessToken(with response: OAuthAuthorizationResponse, - client: OAuthAuthorizationClient, - accountType: AccountType, - transport: Transport = URLSession.webserviceTransport(), - completion: @escaping (Result) -> Void) { + public static func requestOAuthAccessToken( + with response: OAuthAuthorizationResponse, + client: OAuthAuthorizationClient, + accountType: AccountType, + transport: Transport = URLSession.webserviceTransport(), + completion: @escaping (Result) -> Void) { + let grantingType: OAuthAuthorizationGranting.Type switch accountType { @@ -994,7 +996,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, // MARK: - Equatable - public class func ==(lhs: Account, rhs: Account) -> Bool { + public static func ==(lhs: Account, rhs: Account) -> Bool { return lhs === rhs } } diff --git a/Modules/Account/Sources/Account/AccountManager.swift b/Modules/Account/Sources/Account/AccountManager.swift index 0bf280a9b..c66005cfe 100644 --- a/Modules/Account/Sources/Account/AccountManager.swift +++ b/Modules/Account/Sources/Account/AccountManager.swift @@ -410,7 +410,7 @@ public final class AccountManager: UnreadCountProvider { // MARK: - Notifications @objc func unreadCountDidInitialize(_ notification: Notification) { - guard let _ = notification.object as? Account else { + guard notification.object is Account else { return } if isUnreadCountsInitialized { @@ -419,7 +419,7 @@ public final class AccountManager: UnreadCountProvider { } @objc dynamic func unreadCountDidChange(_ notification: Notification) { - guard let _ = notification.object as? Account else { + guard notification.object is Account else { return } updateUnreadCount() diff --git a/Modules/Account/Sources/Account/ContainerIdentifier.swift b/Modules/Account/Sources/Account/ContainerIdentifier.swift index 9a73fb16f..702471c78 100644 --- a/Modules/Account/Sources/Account/ContainerIdentifier.swift +++ b/Modules/Account/Sources/Account/ContainerIdentifier.swift @@ -60,13 +60,13 @@ extension ContainerIdentifier: Encodable { enum CodingKeys: CodingKey { case type case accountID - case folderName - } + case folderName + } - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - switch self { - case .smartFeedController: + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + switch self { + case .smartFeedController: try container.encode("smartFeedController", forKey: .type) case .account(let accountID): try container.encode("account", forKey: .type) @@ -75,8 +75,8 @@ extension ContainerIdentifier: Encodable { try container.encode("folder", forKey: .type) try container.encode(accountID, forKey: .accountID) try container.encode(folderName, forKey: .folderName) - } - } + } + } } extension ContainerIdentifier: Decodable { diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinSubscription.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinSubscription.swift index d122978d7..c7ee76b65 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinSubscription.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinSubscription.swift @@ -32,7 +32,7 @@ struct FeedbinSubscription: Hashable, Codable { hasher.combine(subscriptionID) } - static func == (lhs: FeedbinSubscription, rhs: FeedbinSubscription) -> Bool { + static func ==(lhs: FeedbinSubscription, rhs: FeedbinSubscription) -> Bool { return lhs.subscriptionID == rhs.subscriptionID } diff --git a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift index 936f0554e..25ecc53ce 100644 --- a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift +++ b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift @@ -277,10 +277,12 @@ extension NewsBlurAccountDelegate { return Set(parsedItems) } - func sendStoryStatuses(_ statuses: [SyncStatus], - throttle: Bool, - apiCall: ([String], @escaping (Result) -> Void) -> Void, - completion: @escaping (Result) -> Void) { + func sendStoryStatuses( + _ statuses: [SyncStatus], + throttle: Bool, + apiCall: ([String], @escaping (Result) -> Void) -> Void, + completion: @escaping (Result) -> Void) { + guard !statuses.isEmpty else { completion(.success(())) return diff --git a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index 14de3c16f..8bdce2c24 100644 --- a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -616,7 +616,7 @@ final class NewsBlurAccountDelegate: AccountDelegate { caller.logout { _ in } } - class func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL? = nil, completion: @escaping (Result) -> Void) { + static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL? = nil, completion: @escaping (Result) -> Void) { let caller = NewsBlurAPICaller(transport: transport) caller.credentials = credentials caller.validateCredentials { result in diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift index f7ef1d509..99fdc9203 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift @@ -64,16 +64,14 @@ final class ReaderAPICaller: NSObject { } private var apiBaseURL: URL? { - get { - switch variant { - case .generic, .freshRSS: - guard let accountMetadata = accountMetadata else { - return nil - } - return accountMetadata.endpointURL - default: - return URL(string: variant.host) + switch variant { + case .generic, .freshRSS: + guard let accountMetadata = accountMetadata else { + return nil } + return accountMetadata.endpointURL + default: + return URL(string: variant.host) } } @@ -234,13 +232,14 @@ final class ReaderAPICaller: NSObject { let oldTagName = "user/-/label/\(encodedOldName)" let newTagName = "user/-/label/\(encodedNewName)" - let postData = "T=\(token)&s=\(oldTagName)&dest=\(newTagName)".data(using: String.Encoding.utf8) + let postDataString = "T=\(token)&s=\(oldTagName)&dest=\(newTagName)" + let postData = Data(postDataString.utf8) - self.transport.send(request: request, method: HTTPMethod.post, payload: postData!, completion: { (result) in + self.transport.send(request: request, method: HTTPMethod.post, payload: postData, completion: { (result) in switch result { case .success: completion(.success(())) - case .failure(let error): + case .failure(let error): completion(.failure(error)) } }) @@ -270,13 +269,14 @@ final class ReaderAPICaller: NSObject { request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") request.httpMethod = "POST" - let postData = "T=\(token)&s=\(folderExternalID)".data(using: String.Encoding.utf8) + let postDataString = "T=\(token)&s=\(folderExternalID)" + let postData = Data(postDataString.utf8) - self.transport.send(request: request, method: HTTPMethod.post, payload: postData!, completion: { (result) in + self.transport.send(request: request, method: HTTPMethod.post, payload: postData, completion: { (result) in switch result { case .success: completion(.success(())) - case .failure(let error): + case .failure(let error): completion(.failure(error)) } }) @@ -362,9 +362,10 @@ final class ReaderAPICaller: NSObject { completion(.failure(ReaderAPIAccountDelegateError.invalidParameter)) return } - let postData = "T=\(token)&quickadd=\(encodedFeedURL)".data(using: String.Encoding.utf8) + let postDataString = "T=\(token)&quickadd=\(encodedFeedURL)" + let postData = Data(postDataString.utf8) - self.transport.send(request: request, method: HTTPMethod.post, data: postData!, resultType: ReaderAPIQuickAddResult.self, completion: { (result) in + self.transport.send(request: request, method: HTTPMethod.post, data: postData, resultType: ReaderAPIQuickAddResult.self, completion: { (result) in switch result { case .success(let (_, subResult)): @@ -412,13 +413,14 @@ final class ReaderAPICaller: NSObject { request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") request.httpMethod = "POST" - let postData = "T=\(token)&s=\(subscriptionID)&ac=unsubscribe".data(using: String.Encoding.utf8) + let postDataString = "T=\(token)&s=\(subscriptionID)&ac=unsubscribe" + let postData = Data(postDataString.utf8) - self.transport.send(request: request, method: HTTPMethod.post, payload: postData!, completion: { (result) in + self.transport.send(request: request, method: HTTPMethod.post, payload: postData, completion: { (result) in switch result { case .success: completion(.success(())) - case .failure(let error): + case .failure(let error): completion(.failure(error)) } }) @@ -480,7 +482,7 @@ final class ReaderAPICaller: NSObject { completion(.failure(error)) } }) - + case .failure(let error): completion(.failure(error)) } @@ -518,9 +520,10 @@ final class ReaderAPICaller: NSObject { } }).joined(separator: "&") - let postData = "T=\(token)&output=json&\(idsToFetch)".data(using: String.Encoding.utf8) + let postDataString = "T=\(token)&output=json&\(idsToFetch)" + let postData = Data(postDataString.utf8) - self.transport.send(request: request, method: HTTPMethod.post, data: postData!, resultType: ReaderAPIEntryWrapper.self, completion: { (result) in + self.transport.send(request: request, method: HTTPMethod.post, data: postData, resultType: ReaderAPIEntryWrapper.self, completion: { (result) in switch result { case .success(let (_, entryWrapper)): guard let entryWrapper = entryWrapper else { @@ -713,9 +716,10 @@ private extension ReaderAPICaller { let actionIndicator = add ? "a" : "r" - let postData = "T=\(token)&\(idsToFetch)&\(actionIndicator)=\(state.rawValue)".data(using: String.Encoding.utf8) + let postDataString = "T=\(token)&\(idsToFetch)&\(actionIndicator)=\(state.rawValue)" + let postData = Data(postDataString.utf8) - self.transport.send(request: request, method: HTTPMethod.post, payload: postData!, completion: { (result) in + self.transport.send(request: request, method: HTTPMethod.post, payload: postData, completion: { (result) in switch result { case .success: completion(.success(())) diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/SearchTable.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/SearchTable.swift index cf2ebdc5d..509449c70 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/SearchTable.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/SearchTable.swift @@ -72,7 +72,7 @@ final class ArticleSearchInfo: Hashable { // MARK: Equatable - static func == (lhs: ArticleSearchInfo, rhs: ArticleSearchInfo) -> Bool { + static func ==(lhs: ArticleSearchInfo, rhs: ArticleSearchInfo) -> Bool { return lhs.articleID == rhs.articleID && lhs.title == rhs.title && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.summary == rhs.summary && lhs.authorsNames == rhs.authorsNames && lhs.searchRowID == rhs.searchRowID } } diff --git a/Modules/RSCore/Sources/RSCore/AppKit/Keyboard.swift b/Modules/RSCore/Sources/RSCore/AppKit/Keyboard.swift index b43f0b89a..8800d44fc 100644 --- a/Modules/RSCore/Sources/RSCore/AppKit/Keyboard.swift +++ b/Modules/RSCore/Sources/RSCore/AppKit/Keyboard.swift @@ -131,8 +131,8 @@ public struct KeyboardKey: Hashable { integerValue = KeyboardKey.deleteKeyCode case "[deletefunction]": integerValue = NSDeleteFunctionKey - case "[tab]": - integerValue = NSTabCharacter + case "[tab]": + integerValue = NSTabCharacter default: guard let unwrappedIntegerValue = s.keyboardIntegerValue else { return nil diff --git a/Modules/RSCore/Sources/RSCore/AppKit/NSOutlineView+RSCore.swift b/Modules/RSCore/Sources/RSCore/AppKit/NSOutlineView+RSCore.swift index be87c9e60..e9caa7f4a 100755 --- a/Modules/RSCore/Sources/RSCore/AppKit/NSOutlineView+RSCore.swift +++ b/Modules/RSCore/Sources/RSCore/AppKit/NSOutlineView+RSCore.swift @@ -64,7 +64,7 @@ public extension NSOutlineView { while true { row += 1 - if let _ = item(atRow: row) { + if item(atRow: row) != nil { if canSelect(row) { selectRowAndScrollToVisible(row) return diff --git a/Modules/RSCore/Sources/RSCore/AppKit/NSResponder-Extensions.swift b/Modules/RSCore/Sources/RSCore/AppKit/NSResponder-Extensions.swift index 435a09647..420de6805 100755 --- a/Modules/RSCore/Sources/RSCore/AppKit/NSResponder-Extensions.swift +++ b/Modules/RSCore/Sources/RSCore/AppKit/NSResponder-Extensions.swift @@ -17,7 +17,7 @@ public extension NSResponder { if nomad === ancestor { return true } - if let _ = nomad.nextResponder { + if nomad.nextResponder != nil { nomad = nomad.nextResponder! } else { break diff --git a/Modules/RSCore/Sources/RSCore/MainThreadOperationQueue.swift b/Modules/RSCore/Sources/RSCore/MainThreadOperationQueue.swift index bfa936a78..bcae354ff 100644 --- a/Modules/RSCore/Sources/RSCore/MainThreadOperationQueue.swift +++ b/Modules/RSCore/Sources/RSCore/MainThreadOperationQueue.swift @@ -342,7 +342,7 @@ private extension MainThreadOperationQueue { func allOperationIDsAreInStorage(_ operationIDs: [Int]) -> Bool { // Used by an assert. for operationID in operationIDs { - guard let _ = operations[operationID] else { + if operations[operationID] == nil { return false } }