Enable SwiftLint rule 'multiline_arguments_brackets' and fix all violations

This commit is contained in:
Danny Moesch 2020-07-05 00:16:22 +02:00 committed by Mingshen Sun
parent b4c25726a5
commit c87f4e9792
18 changed files with 286 additions and 220 deletions

View file

@ -48,29 +48,32 @@ class AdvancedSettingsTableViewController: UITableViewController {
tableView.deselectRow(at: indexPath, animated: true)
if tableView.cellForRow(at: indexPath) == eraseDataTableViewCell {
let alert = UIAlertController(title: "ErasePasswordStoreData?".localize(), message: "EraseExplanation.".localize(), preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive, handler: { [unowned self] (_) -> Void in
SVProgressHUD.show(withStatus: "Erasing...".localize())
self.passwordStore.erase()
self.navigationController!.popViewController(animated: true)
SVProgressHUD.showSuccess(withStatus: "Done".localize())
SVProgressHUD.dismiss(withDelay: 1)
}))
alert.addAction(
UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive) { [unowned self] (_) -> Void in
SVProgressHUD.show(withStatus: "Erasing...".localize())
self.passwordStore.erase()
self.navigationController!.popViewController(animated: true)
SVProgressHUD.showSuccess(withStatus: "Done".localize())
SVProgressHUD.dismiss(withDelay: 1)
}
)
alert.addAction(UIAlertAction.dismiss())
present(alert, animated: true, completion: nil)
} else if tableView.cellForRow(at: indexPath) == discardChangesTableViewCell {
let alert = UIAlertController(title: "DiscardAllLocalChanges?".localize(), message: "DiscardExplanation.".localize(), preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "DiscardAllLocalChanges".localize(), style: UIAlertAction.Style.destructive, handler: { [unowned self] (_) -> Void in
SVProgressHUD.show(withStatus: "Resetting...".localize())
do {
let numberDiscarded = try self.passwordStore.reset()
self.navigationController!.popViewController(animated: true)
SVProgressHUD.showSuccess(withStatus: "DiscardedCommits(%d)".localize(numberDiscarded))
SVProgressHUD.dismiss(withDelay: 1)
} catch {
Utils.alert(title: "Error".localize(), message: error.localizedDescription, controller: self, completion: nil)
alert.addAction(
UIAlertAction(title: "DiscardAllLocalChanges".localize(), style: UIAlertAction.Style.destructive) { [unowned self] (_) -> Void in
SVProgressHUD.show(withStatus: "Resetting...".localize())
do {
let numberDiscarded = try self.passwordStore.reset()
self.navigationController!.popViewController(animated: true)
SVProgressHUD.showSuccess(withStatus: "DiscardedCommits(%d)".localize(numberDiscarded))
SVProgressHUD.dismiss(withDelay: 1)
} catch {
Utils.alert(title: "Error".localize(), message: error.localizedDescription, controller: self, completion: nil)
}
}
}))
)
alert.addAction(UIAlertAction.dismiss())
present(alert, animated: true, completion: nil)
}

View file

@ -146,9 +146,11 @@ class GitRepositorySettingsTableViewController: UITableViewController {
if passwordStore.repositoryExists() {
let overwriteAlert: UIAlertController = {
let alert = UIAlertController(title: "Overwrite?".localize(), message: "OperationWillOverwriteData.".localize(), preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Overwrite".localize(), style: .destructive) { _ in
self.cloneAndSegueIfSuccess()
})
alert.addAction(
UIAlertAction(title: "Overwrite".localize(), style: .destructive) { _ in
self.cloneAndSegueIfSuccess()
}
)
alert.addAction(UIAlertAction.cancel())
return alert
}()
@ -174,26 +176,32 @@ class GitRepositorySettingsTableViewController: UITableViewController {
SVProgressHUD.showProgress(progress, status: "CheckingOutBranch".localize(self.gitBranchName))
}
try self.passwordStore.cloneRepository(remoteRepoURL: self.gitUrl,
credential: self.gitCredential,
branchName: self.gitBranchName,
requestCredentialPassword: self.requestCredentialPassword,
transferProgressBlock: transferProgressBlock,
checkoutProgressBlock: checkoutProgressBlock)
try self.passwordStore.cloneRepository(
remoteRepoURL: self.gitUrl,
credential: self.gitCredential,
branchName: self.gitBranchName,
requestCredentialPassword: self.requestCredentialPassword,
transferProgressBlock: transferProgressBlock,
checkoutProgressBlock: checkoutProgressBlock
)
SVProgressHUD.dismiss {
let savePassphraseAlert: UIAlertController = {
let alert = UIAlertController(title: "Done".localize(), message: "WantToSaveGitCredential?".localize(), preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "No".localize(), style: .default) { _ in
Defaults.isRememberGitCredentialPassphraseOn = false
self.passwordStore.gitPassword = nil
self.passwordStore.gitSSHPrivateKeyPassphrase = nil
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
})
alert.addAction(UIAlertAction(title: "Yes".localize(), style: .destructive) { _ in
Defaults.isRememberGitCredentialPassphraseOn = true
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
})
alert.addAction(
UIAlertAction(title: "No".localize(), style: .default) { _ in
Defaults.isRememberGitCredentialPassphraseOn = false
self.passwordStore.gitPassword = nil
self.passwordStore.gitSSHPrivateKeyPassphrase = nil
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
}
)
alert.addAction(
UIAlertAction(title: "Yes".localize(), style: .destructive) { _ in
Defaults.isRememberGitCredentialPassphraseOn = true
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
}
)
return alert
}()
DispatchQueue.main.async {
@ -244,35 +252,47 @@ class GitRepositorySettingsTableViewController: UITableViewController {
private func showSSHKeyActionSheet() {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
optionMenu.addAction(UIAlertAction(title: SSHKeyUrlImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setGitSSHKeyByURLSegue", sender: self)
})
optionMenu.addAction(UIAlertAction(title: SSHKeyArmorImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setGitSSHKeyByArmorSegue", sender: self)
})
optionMenu.addAction(UIAlertAction(title: SSHKeyFileImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setGitSSHKeyByFileSegue", sender: self)
})
optionMenu.addAction(
UIAlertAction(title: SSHKeyUrlImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setGitSSHKeyByURLSegue", sender: self)
}
)
optionMenu.addAction(
UIAlertAction(title: SSHKeyArmorImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setGitSSHKeyByArmorSegue", sender: self)
}
)
optionMenu.addAction(
UIAlertAction(title: SSHKeyFileImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setGitSSHKeyByFileSegue", sender: self)
}
)
if isReadyToUse() {
optionMenu.addAction(UIAlertAction(title: "\(Self.menuLabel) (\("Import".localize()))", style: .default) { _ in
self.importSSHKey(using: self)
})
optionMenu.addAction(
UIAlertAction(title: "\(Self.menuLabel) (\("Import".localize()))", style: .default) { _ in
self.importSSHKey(using: self)
}
)
} else {
optionMenu.addAction(UIAlertAction(title: "\(Self.menuLabel) (\("Tips".localize()))", style: .default) { _ in
let title = "Tips".localize()
let message = "SshCopyPrivateKeyToPass.".localize()
Utils.alert(title: title, message: message, controller: self)
})
optionMenu.addAction(
UIAlertAction(title: "\(Self.menuLabel) (\("Tips".localize()))", style: .default) { _ in
let title = "Tips".localize()
let message = "SshCopyPrivateKeyToPass.".localize()
Utils.alert(title: title, message: message, controller: self)
}
)
}
if Defaults.gitSSHKeySource != nil {
optionMenu.addAction(UIAlertAction(title: "RemoveSShKeys".localize(), style: .destructive) { _ in
self.passwordStore.removeGitSSHKeys()
Defaults.gitSSHKeySource = nil
self.sshLabel?.isEnabled = false
self.gitAuthenticationMethod = .password
})
optionMenu.addAction(
UIAlertAction(title: "RemoveSShKeys".localize(), style: .destructive) { _ in
self.passwordStore.removeGitSSHKeys()
Defaults.gitSSHKeySource = nil
self.sshLabel?.isEnabled = false
self.gitAuthenticationMethod = .password
}
)
}
optionMenu.addAction(UIAlertAction.cancel())
optionMenu.popoverPresentationController?.sourceView = authSSHKeyCell

View file

@ -41,14 +41,16 @@ class OpenSourceComponentsTableViewController: BasicStaticTableViewController {
super.viewDidLoad()
tableData.append([])
for item in Self.openSourceComponents {
tableData[0].append([
.title: item[0],
.action: "link",
.link: item[1],
.accessoryType: UITableViewCell.AccessoryType.detailDisclosureButton,
.detailDisclosureAction: #selector(actOnDetailDisclosureButton(_:)),
.detailDisclosureData: item[2],
])
tableData[0].append(
[
.title: item[0],
.action: "link",
.link: item[1],
.accessoryType: UITableViewCell.AccessoryType.detailDisclosureButton,
.detailDisclosureAction: #selector(actOnDetailDisclosureButton(_:)),
.detailDisclosureData: item[2],
]
)
}
}

View file

@ -88,9 +88,9 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
@objc
private func decryptThenShowPassword(keyID: String? = nil) {
guard let passwordEntity = passwordEntity else {
Utils.alert(title: "CannotShowPassword".localize(), message: "PasswordDoesNotExist".localize(), controller: self, handler: { (_) -> Void in
Utils.alert(title: "CannotShowPassword".localize(), message: "PasswordDoesNotExist".localize(), controller: self) {
self.navigationController!.popViewController(animated: true)
})
}
return
}
DispatchQueue.global(qos: .userInitiated).async {
@ -116,9 +116,11 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
// alert: cancel or try again
let alert = UIAlertController(title: "CannotShowPassword".localize(), message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction.cancelAndPopView(controller: self))
alert.addAction(UIAlertAction(title: "TryAgain".localize(), style: .default) { _ in
self.decryptThenShowPassword()
})
alert.addAction(
UIAlertAction(title: "TryAgain".localize(), style: .default) { _ in
self.decryptThenShowPassword()
}
)
self.present(alert, animated: true, completion: nil)
}
}
@ -288,10 +290,12 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
var newUrlString = urlString
if urlString.lowercased().hasPrefix("http://") {
// try to replace http url to https url
newUrlString = urlString.replacingOccurrences(of: "http://",
with: "https://",
options: .caseInsensitive,
range: urlString.range(of: "http://"))
newUrlString = urlString.replacingOccurrences(
of: "http://",
with: "https://",
options: .caseInsensitive,
range: urlString.range(of: "http://")
)
} else if urlString.lowercased().hasPrefix("https://") {
// do nothing here
} else {

View file

@ -246,9 +246,11 @@ class PasswordEditorTableViewController: UITableViewController {
if selectedCell == deletePasswordCell {
let alert = UIAlertController(title: "DeletePassword?".localize(), message: nil, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "Delete".localize(), style: UIAlertAction.Style.destructive, handler: { [unowned self] (_) -> Void in
self.performSegue(withIdentifier: "deletePasswordSegue", sender: self)
}))
alert.addAction(
UIAlertAction(title: "Delete".localize(), style: UIAlertAction.Style.destructive) { [unowned self] (_) -> Void in
self.performSegue(withIdentifier: "deletePasswordSegue", sender: self)
}
)
alert.addAction(UIAlertAction.cancel())
present(alert, animated: true, completion: nil)
} else if selectedCell == scanQRCodeCell {
@ -388,9 +390,11 @@ extension PasswordEditorTableViewController: FillPasswordTableViewCellDelegate {
func generateAndCopyPassword() {
if let currentPassword = fillPasswordCell?.getContent(), Constants.isOtpRelated(line: currentPassword) {
let alert = UIAlertController(title: "Overwrite?".localize(), message: "OverwriteOtpConfiguration?".localize(), preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "Yes".localize(), style: UIAlertAction.Style.destructive, handler: { _ in
self.generateAndCopyPasswordNoOtpCheck()
}))
alert.addAction(
UIAlertAction(title: "Yes".localize(), style: UIAlertAction.Style.destructive) { _ in
self.generateAndCopyPasswordNoOtpCheck()
}
)
alert.addAction(UIAlertAction.cancel())
present(alert, animated: true, completion: nil)
} else {
@ -436,12 +440,14 @@ extension PasswordEditorTableViewController: SFSafariViewControllerDelegate {
let message = NSMutableAttributedString(string: "\("SeemsLikeYouHaveCopiedSomething.".localize()) \("FirstStringIs:".localize())\n")
message.append(Utils.attributedPassword(plainPassword: generatedPassword))
alert.setValue(message, forKey: "attributedMessage")
alert.addAction(UIAlertAction(title: "Yes", style: UIAlertAction.Style.default, handler: { [unowned self] (_) -> Void in
// update tableData so to make sure reloadData() works correctly
self.tableData[self.passwordSection][0][PasswordEditorCellKey.content] = generatedPassword
// update cell manually, no need to call reloadData()
self.fillPasswordCell?.setContent(content: generatedPassword)
}))
alert.addAction(
UIAlertAction(title: "Yes", style: UIAlertAction.Style.default) { [unowned self] (_) -> Void in
// update tableData so to make sure reloadData() works correctly
self.tableData[self.passwordSection][0][PasswordEditorCellKey.content] = generatedPassword
// update cell manually, no need to call reloadData()
self.fillPasswordCell?.setContent(content: generatedPassword)
}
)
alert.addAction(UIAlertAction.cancel())
present(alert, animated: true, completion: nil)
}

View file

@ -192,17 +192,17 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
do {
try self.passwordStore.pullRepository(credential: self.gitCredential, requestCredentialPassword: self.requestCredentialPassword, progressBlock: { git_transfer_progress, _ in
try self.passwordStore.pullRepository(credential: self.gitCredential, requestCredentialPassword: self.requestCredentialPassword) { git_transfer_progress, _ in
DispatchQueue.main.async {
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects) / Float(git_transfer_progress.pointee.total_objects), status: "PullingFromRemoteRepository".localize())
}
})
}
if self.passwordStore.numberOfLocalCommits > 0 {
try self.passwordStore.pushRepository(credential: self.gitCredential, requestCredentialPassword: self.requestCredentialPassword, transferProgressBlock: { current, total, _, _ in
try self.passwordStore.pushRepository(credential: self.gitCredential, requestCredentialPassword: self.requestCredentialPassword) { current, total, _, _ in
DispatchQueue.main.async {
SVProgressHUD.showProgress(Float(current) / Float(total), status: "PushingToRemoteRepository".localize())
}
})
}
}
DispatchQueue.main.async {
self.reloadTableView(parent: nil)

View file

@ -129,17 +129,19 @@ class QRScannerController: UIViewController, AVCaptureMetadataOutputObjectsDeleg
}
func presentCameraSettings() {
let alertController = UIAlertController(title: "Error".localize(),
message: "CameraAccessDenied.".localize() | "WarningToggleCameraPermissionsResetsApp.".localize(),
preferredStyle: .alert)
let alertController = UIAlertController(
title: "Error".localize(),
message: "CameraAccessDenied.".localize() | "WarningToggleCameraPermissionsResetsApp.".localize(),
preferredStyle: .alert
)
alertController.addAction(UIAlertAction(title: "Cancel".localize(), style: .default))
alertController.addAction(UIAlertAction(title: "Settings".localize(), style: .cancel) { _ in
if let url = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(url, options: [:], completionHandler: { _ in
// Handle
})
alertController.addAction(
UIAlertAction(title: "Settings".localize(), style: .cancel) { _ in
if let url = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(url, options: [:]) { _ in }
}
}
})
)
present(alertController, animated: true)
}

View file

@ -30,9 +30,11 @@ class SSHKeyUrlImportTableViewController: AutoCellHeightUITableViewController {
if privateKeyURL.scheme?.lowercased() == "http" {
let savePassphraseAlert = UIAlertController(title: "HttpNotSecure".localize(), message: "ReallyUseHttp?".localize(), preferredStyle: .alert)
savePassphraseAlert.addAction(UIAlertAction(title: "No".localize(), style: .default) { _ in })
savePassphraseAlert.addAction(UIAlertAction(title: "Yes".localize(), style: .destructive) { _ in
self.performSegue(withIdentifier: "importSSHKeySegue", sender: self)
})
savePassphraseAlert.addAction(
UIAlertAction(title: "Yes".localize(), style: .destructive) { _ in
self.performSegue(withIdentifier: "importSSHKeySegue", sender: self)
}
)
return present(savePassphraseAlert, animated: true)
}
sshPrivateKeyURL = privateKeyURL

View file

@ -142,36 +142,48 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
func showPGPKeyActionSheet() {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
optionMenu.addAction(UIAlertAction(title: PGPKeyUrlImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setPGPKeyByURLSegue", sender: self)
})
optionMenu.addAction(UIAlertAction(title: PGPKeyArmorImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setPGPKeyByASCIISegue", sender: self)
})
optionMenu.addAction(UIAlertAction(title: PGPKeyFileImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setPGPKeyByFileSegue", sender: self)
})
optionMenu.addAction(
UIAlertAction(title: PGPKeyUrlImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setPGPKeyByURLSegue", sender: self)
}
)
optionMenu.addAction(
UIAlertAction(title: PGPKeyArmorImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setPGPKeyByASCIISegue", sender: self)
}
)
optionMenu.addAction(
UIAlertAction(title: PGPKeyFileImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setPGPKeyByFileSegue", sender: self)
}
)
if isReadyToUse() {
optionMenu.addAction(UIAlertAction(title: "\(Self.menuLabel) (\("Import".localize()))", style: .default) { _ in
self.saveImportedKeys()
})
optionMenu.addAction(
UIAlertAction(title: "\(Self.menuLabel) (\("Import".localize()))", style: .default) { _ in
self.saveImportedKeys()
}
)
} else {
optionMenu.addAction(UIAlertAction(title: "\(Self.menuLabel) (\("Tips".localize()))", style: .default) { _ in
let title = "Tips".localize()
let message = "PgpCopyPublicAndPrivateKeyToPass.".localize()
Utils.alert(title: title, message: message, controller: self)
})
optionMenu.addAction(
UIAlertAction(title: "\(Self.menuLabel) (\("Tips".localize()))", style: .default) { _ in
let title = "Tips".localize()
let message = "PgpCopyPublicAndPrivateKeyToPass.".localize()
Utils.alert(title: title, message: message, controller: self)
}
)
}
if Defaults.pgpKeySource != nil {
optionMenu.addAction(UIAlertAction(title: "RemovePgpKeys".localize(), style: .destructive) { _ in
self.keychain.removeContent(for: PgpKey.PUBLIC.getKeychainKey())
self.keychain.removeContent(for: PgpKey.PRIVATE.getKeychainKey())
PGPAgent.shared.uninitKeys()
self.pgpKeyTableViewCell.detailTextLabel?.text = "NotSet".localize()
Defaults.pgpKeySource = nil
})
optionMenu.addAction(
UIAlertAction(title: "RemovePgpKeys".localize(), style: .destructive) { _ in
self.keychain.removeContent(for: PgpKey.PUBLIC.getKeychainKey())
self.keychain.removeContent(for: PgpKey.PRIVATE.getKeychainKey())
PGPAgent.shared.uninitKeys()
self.pgpKeyTableViewCell.detailTextLabel?.text = "NotSet".localize()
Defaults.pgpKeySource = nil
}
)
}
optionMenu.addAction(UIAlertAction.cancel())
optionMenu.popoverPresentationController?.sourceView = pgpKeyTableViewCell
@ -221,16 +233,16 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
func setPasscodeLock() {
// prepare the alert for setting the passcode
setPasscodeLockAlert = UIAlertController(title: "SetPasscode".localize(), message: "FillInAppPasscode.".localize(), preferredStyle: .alert)
setPasscodeLockAlert?.addTextField(configurationHandler: { (_ textField: UITextField) -> Void in
setPasscodeLockAlert?.addTextField { textField -> Void in
textField.placeholder = "Passcode".localize()
textField.isSecureTextEntry = true
textField.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
})
setPasscodeLockAlert?.addTextField(configurationHandler: { (_ textField: UITextField) -> Void in
}
setPasscodeLockAlert?.addTextField { textField -> Void in
textField.placeholder = "PasswordConfirmation".localize()
textField.isSecureTextEntry = true
textField.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged)
})
}
// save action
let saveAction = UIAlertAction(title: "Save".localize(), style: .default) { (_: UIAlertAction) -> Void in