瀏覽代碼

fix all swift warnings (#1937)

* fix 'unneeded override' warnings

* fix 'unneccessary brackets' warning

* fix spacing warnings

* fix 'result unused' warnings

* increase random limits; in practise, this is not used for new code anyways

* remove unneeded warning switches

* remove unneeded 'let'

* do not force-cast
bjoern 1 年之前
父節點
當前提交
e586e69cba

+ 3 - 3
.swiftlint.yml

@@ -22,10 +22,10 @@ identifier_name:
   min_length:
     warning: 1
     error: 0
-  max_length: 40
+  max_length: 50
 
 line_length:
-  warning: 160
+  warning: 200
   error: 200
   ignores_function_declarations: true
   ignores_comments: true
@@ -39,7 +39,7 @@ function_body_length:
   error: 500
 
 function_parameter_count:
-  warning: 6
+  warning: 8
   error: 8
 
 file_length:

+ 1 - 3
deltachat-ios/Chat/Views/Cells/ImageTextCell.swift

@@ -54,9 +54,7 @@ class ImageTextCell: BaseMessageCell {
         tag = msg.id
 
         if let url = msg.fileURL,
-           (msg.type == DC_MSG_IMAGE ||
-            msg.type == DC_MSG_GIF ||
-                msg.type == DC_MSG_STICKER) {
+            msg.type == DC_MSG_IMAGE || msg.type == DC_MSG_GIF || msg.type == DC_MSG_STICKER {
             contentImageView.sd_setImage(with: url,
                                          placeholderImage: UIImage(color: UIColor.init(alpha: 0,
                                                                                        red: 255,

+ 0 - 5
deltachat-ios/Chat/Views/Cells/TextMessageCell.swift

@@ -22,9 +22,4 @@ class TextMessageCell: BaseMessageCell {
                      searchText: searchText,
                      highlight: highlight)
     }
-
-    override func prepareForReuse() {
-        super.prepareForReuse()
-    }
-    
 }

+ 1 - 1
deltachat-ios/Chat/Views/MediaPreview.swift

@@ -36,7 +36,7 @@ class MediaPreview: DraftPreview {
             return
         }
         
-        if (draft.viewType == DC_MSG_GIF || draft.viewType == DC_MSG_IMAGE), let path = draft.attachment {
+        if draft.viewType == DC_MSG_GIF || draft.viewType == DC_MSG_IMAGE, let path = draft.attachment {
             contentImageView.sd_setImage(with: URL(fileURLWithPath: path, isDirectory: false), completed: { image, error, _, _ in
                 if let error = error {
                     logger.error("could not load draft image: \(error)")

+ 0 - 1
deltachat-ios/Chat/Views/MessageLabel.swift

@@ -507,7 +507,6 @@ open class MessageLabel: UILabel {
             }
         }
     }
-    // swiftlint:enable cyclomatic_complexity
 
     private func handleAddress(_ addressComponents: [String: String]) {
         delegate?.didSelectAddress(addressComponents)

+ 7 - 13
deltachat-ios/Controller/AccountSetup/AccountSetupController.swift

@@ -293,10 +293,6 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         handleLoginButton()
     }
 
-    override func viewDidAppear(_ animated: Bool) {
-        super.viewDidAppear(animated)
-    }
-
     override func viewWillDisappear(_ animated: Bool) {
         resignFirstResponderOnAllCells()
         progressObserver = nil
@@ -523,7 +519,6 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
 //
 //         if let url = URL(string: oAuth2Url) {
 //             let title = "Continue with simplified setup"
-//             // swiftlint:disable all
 //             let message = "The entered e-mail address supports a simplified setup (oAuth2).\n\nIn the next step, please allow Delta Chat to act as your Chat with E-Mail app.\n\nThere are no Delta Chat servers, your data stays on your device."
 //
 //             let oAuthAlertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
@@ -570,10 +565,9 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
             forName: dcNotificationConfigureProgress,
             object: nil,
             queue: nil
-        ) {
-            notification in
+        ) { notification in
             if let ui = notification.userInfo {
-                if ui["error"] as! Bool {
+                if let error = ui["error"] as? Bool, error {
                     self.dcAccounts.startIo()
                     var errorMessage = ui["errorMessage"] as? String
                     if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
@@ -584,7 +578,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
                         errorMessage = "\(errorMessage ?? "no message")\n\n(warning=\(self.dcContext.lastWarningString) (progress=\(self.dcContext.maxConfigureProgress))"
                     }
                     self.updateProgressAlert(error: errorMessage)
-                } else if ui["done"] as! Bool {
+                } else if let done = ui["done"] as? Bool, done {
                     self.dcAccounts.startIo()
                     self.updateProgressAlertSuccess(completion: self.handleLoginSuccess)
                 } else {
@@ -627,7 +621,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
             appDelegate.registerForNotifications()
         }
 
-        initSelectionCells();
+        initSelectionCells()
         if let onLoginSuccess = self.onLoginSuccess {
             onLoginSuccess()
         } else {
@@ -642,11 +636,11 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     }
 
     private func resignFirstResponderOnAllCells() {
-        let _ = basicSectionCells.map({
+        _ = basicSectionCells.map({
             resignCell(cell: $0)
         })
 
-        let _ = advancedSectionCells.map({
+        _ = advancedSectionCells.map({
             resignCell(cell: $0)
         })
     }
@@ -733,7 +727,7 @@ extension AccountSetupController: UITextFieldDelegate {
 
     func textFieldDidEndEditing(_ textField: UITextField) {
         if textField.tag == tagTextFieldEmail {
-            let _ = showOAuthAlertIfNeeded(emailAddress: textField.text ?? "", handleCancel: {
+            _ = showOAuthAlertIfNeeded(emailAddress: textField.text ?? "", handleCancel: {
                 self.passwordCell.textField.becomeFirstResponder()
             })
             updateProviderInfo()

+ 1 - 1
deltachat-ios/Controller/ChatListController.swift

@@ -707,7 +707,7 @@ class ChatListController: UITableViewController {
         }
     }
     
-    func updateMarkArchivedReadButton(){
+    func updateMarkArchivedReadButton() {
         self.markArchivedReadButton.isEnabled = dcContext.getUnreadMessages(chatId: Int(DC_CHAT_ID_ARCHIVED_LINK)) != 0
     }
 

+ 0 - 4
deltachat-ios/Controller/Settings/AutodelOverviewViewController.swift

@@ -54,10 +54,6 @@ class AutodelOverviewViewController: UITableViewController {
         fatalError("init(coder:) has not been implemented")
     }
 
-    override func viewDidLoad() {
-        super.viewDidLoad()
-    }
-
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
         tableView.reloadData() // needed to update footer

+ 0 - 4
deltachat-ios/Controller/Settings/DownloadOnDemandViewController.swift

@@ -26,10 +26,6 @@ class DownloadOnDemandViewController: UITableViewController {
         fatalError("init(coder:) has not been implemented")
     }
 
-    override func viewDidLoad() {
-        super.viewDidLoad()
-    }
-
     static func getValString(val: Int) -> String {
         switch val {
         case 0:

+ 0 - 4
deltachat-ios/Controller/Settings/EmailOptionsViewController.swift

@@ -26,10 +26,6 @@ class EmailOptionsViewController: UITableViewController {
         fatalError("init(coder:) has not been implemented")
     }
 
-    override func viewDidLoad() {
-        super.viewDidLoad()
-    }
-
     static public func getValString(val: Int) -> String {
         switch Int32(val) {
         case DC_SHOW_EMAILS_OFF:

+ 0 - 4
deltachat-ios/Controller/Settings/MediaQualityViewController.swift

@@ -26,10 +26,6 @@ class MediaQualityViewController: UITableViewController {
         fatalError("init(coder:) has not been implemented")
     }
 
-    override func viewDidLoad() {
-        super.viewDidLoad()
-    }
-
     static func getValString(val: Int) -> String {
         switch Int32(val) {
         case DC_MEDIA_QUALITY_BALANCED:

+ 0 - 2
deltachat-ios/Extensions/UIEdgeInsets+Extensions.swift

@@ -25,8 +25,6 @@
 import Foundation
 import UIKit
 
-// swiftlint:disable explicit_acl
-
 internal extension UIEdgeInsets {
 
     var vertical: CGFloat {

+ 1 - 1
deltachat-ios/Helper/ChatDropInteraction.swift

@@ -92,7 +92,7 @@ public class ChatDropInteraction {
     }
 
     private func loadTextObjects(session: UIDropSession) {
-        session.loadObjects(ofClass: String.self) { [weak self] stringItems in
+        _ = session.loadObjects(ofClass: String.self) { [weak self] stringItems in
             guard !stringItems.isEmpty else { return }
             self?.delegate?.onTextDragAndDropped(text: stringItems[0])
         }

+ 0 - 5
deltachat-ios/View/ActionCell.swift

@@ -38,11 +38,6 @@ class ActionCell: UITableViewCell {
         fatalError("init(coder:) has not been implemented")
     }
 
-    override func awakeFromNib() {
-        super.awakeFromNib()
-        // Initialization code
-    }
-
     private func setupSubviews() {
         contentView.addSubview(actionLabel)
         actionLabel.translatesAutoresizingMaskIntoConstraints = false