Use SwiftFormat version 0.49.x and enable some new rules (#527)

This commit is contained in:
Danny Moesch 2021-12-28 02:57:11 +01:00 committed by GitHub
parent b62c5fa2e5
commit cdedff0d4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 139 additions and 126 deletions

View file

@ -49,7 +49,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
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) { [unowned self] _ -> Void in
UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in
SVProgressHUD.show(withStatus: "Erasing...".localize())
self.passwordStore.erase()
self.navigationController!.popViewController(animated: true)
@ -62,7 +62,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
} 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) { [unowned self] _ -> Void in
UIAlertAction(title: "DiscardAllLocalChanges".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in
SVProgressHUD.show(withStatus: "Resetting...".localize())
do {
let numberDiscarded = try self.passwordStore.reset()

View file

@ -41,7 +41,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
}
}
private var gitUrl: URL {
private var gitURL: URL {
get { Defaults.gitURL }
set { Defaults.gitURL = newValue }
}
@ -60,7 +60,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
override func viewDidLoad() {
super.viewDidLoad()
gitURLTextField.text = gitUrl.absoluteString
gitURLTextField.text = gitURL.absoluteString
usernameTextField.text = gitUsername
branchNameTextField.text = gitBranchName
sshLabel = authSSHKeyCell.subviews[0].subviews[0] as? UILabel
@ -70,7 +70,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Grey out ssh option if ssh_key is not present.
sshLabel?.isEnabled = keychain.contains(key: SshKey.PRIVATE.getKeychainKey())
sshLabel?.isEnabled = keychain.contains(key: SSHKey.PRIVATE.getKeychainKey())
updateAuthenticationMethodCheckView(for: gitAuthenticationMethod)
}
@ -95,7 +95,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
if cell == authPasswordCell {
gitAuthenticationMethod = .password
} else if cell == authSSHKeyCell {
if !keychain.contains(key: SshKey.PRIVATE.getKeychainKey()) {
if !keychain.contains(key: SSHKey.PRIVATE.getKeychainKey()) {
Utils.alert(title: "CannotSelectSshKey".localize(), message: "PleaseSetupSshKeyFirst.".localize(), controller: self)
gitAuthenticationMethod = .password
} else {
@ -146,7 +146,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
}
}
gitUrl = gitURL
self.gitURL = gitURL
gitBranchName = branchName.trimmed
gitUsername = (gitURL.user ?? usernameTextField.text ?? "git").trimmed
@ -186,7 +186,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
let options = self.gitCredential.getCredentialOptions(passwordProvider: self.present)
try self.passwordStore.cloneRepository(
remoteRepoURL: self.gitUrl,
remoteRepoURL: self.gitURL,
branchName: self.gitBranchName,
options: options,
transferProgressBlock: transferProgressBlock,
@ -278,7 +278,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
private func showSSHKeyActionSheet() {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
optionMenu.addAction(
UIAlertAction(title: SSHKeyUrlImportTableViewController.menuLabel, style: .default) { _ in
UIAlertAction(title: SSHKeyURLImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setGitSSHKeyByURLSegue", sender: self)
}
)
@ -354,10 +354,10 @@ extension GitRepositorySettingsTableViewController: KeyImporter {
static let label = "ITunesFileSharing".localize()
func isReadyToUse() -> Bool {
KeyFileManager.PrivateSsh.doesKeyFileExist()
KeyFileManager.PrivateSSH.doesKeyFileExist()
}
func importKeys() throws {
try KeyFileManager.PrivateSsh.importKeyFromFileSharing()
try KeyFileManager.PrivateSSH.importKeyFromFileSharing()
}
}

View file

@ -109,8 +109,8 @@ extension PGPKeyArmorImportTableViewController: PGPKeyImporter {
}
func importKeys() throws {
try KeyFileManager.PublicPgp.importKey(from: armorPublicKey ?? "")
try KeyFileManager.PrivatePgp.importKey(from: armorPrivateKey ?? "")
try KeyFileManager.PublicPGP.importKey(from: armorPublicKey ?? "")
try KeyFileManager.PrivatePGP.importKey(from: armorPrivateKey ?? "")
}
func saveImportedKeys() {

View file

@ -88,8 +88,8 @@ extension PGPKeyFileImportTableViewController: PGPKeyImporter {
guard let publicKey = publicKey, let privateKey = privateKey else {
return
}
try KeyFileManager.PublicPgp.importKey(from: publicKey)
try KeyFileManager.PrivatePgp.importKey(from: privateKey)
try KeyFileManager.PublicPGP.importKey(from: publicKey)
try KeyFileManager.PrivatePGP.importKey(from: privateKey)
}
func doAfterImport() {

View file

@ -1,5 +1,5 @@
//
// PGPKeyUrlImportTableViewController.swift
// PGPKeyURLImportTableViewController.swift
// pass
//
// Created by Mingshen Sun on 21/1/2017.
@ -9,7 +9,7 @@
import passKit
import UIKit
class PGPKeyUrlImportTableViewController: AutoCellHeightUITableViewController {
class PGPKeyURLImportTableViewController: AutoCellHeightUITableViewController {
@IBOutlet var pgpPublicKeyURLTextField: UITextField!
@IBOutlet var pgpPrivateKeyURLTextField: UITextField!
@ -40,21 +40,21 @@ class PGPKeyUrlImportTableViewController: AutoCellHeightUITableViewController {
}
}
extension PGPKeyUrlImportTableViewController: PGPKeyImporter {
extension PGPKeyURLImportTableViewController: PGPKeyImporter {
static let keySource = KeySource.url
static let label = "DownloadFromUrl".localize()
func isReadyToUse() -> Bool {
validate(pgpKeyUrl: pgpPublicKeyURLTextField.text ?? "")
&& validate(pgpKeyUrl: pgpPrivateKeyURLTextField.text ?? "")
validate(pgpKeyURL: pgpPublicKeyURLTextField.text ?? "")
&& validate(pgpKeyURL: pgpPrivateKeyURLTextField.text ?? "")
}
func importKeys() throws {
Defaults.pgpPrivateKeyURL = pgpPrivateKeyURL
Defaults.pgpPublicKeyURL = pgpPublicKeyURL
try KeyFileManager.PublicPgp.importKey(from: Defaults.pgpPublicKeyURL!)
try KeyFileManager.PrivatePgp.importKey(from: Defaults.pgpPrivateKeyURL!)
try KeyFileManager.PublicPGP.importKey(from: Defaults.pgpPublicKeyURL!)
try KeyFileManager.PrivatePGP.importKey(from: Defaults.pgpPrivateKeyURL!)
}
func doAfterImport() {
@ -65,8 +65,8 @@ extension PGPKeyUrlImportTableViewController: PGPKeyImporter {
performSegue(withIdentifier: "savePGPKeySegue", sender: self)
}
private func validate(pgpKeyUrl: String) -> Bool {
guard let url = URL(string: pgpKeyUrl) else {
private func validate(pgpKeyURL: String) -> Bool {
guard let url = URL(string: pgpKeyURL) else {
Utils.alert(title: "CannotSavePgpKey".localize(), message: "SetPgpKeyUrlsFirst.".localize(), controller: self)
return false
}

View file

@ -289,10 +289,10 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
}
private func updatePasswordImage(urlString: String) {
var newUrlString = urlString
var newURLString = urlString
if urlString.lowercased().hasPrefix("http://") {
// try to replace http url to https url
newUrlString = urlString.replacingOccurrences(
newURLString = urlString.replacingOccurrences(
of: "http://",
with: "https://",
options: .caseInsensitive,
@ -302,10 +302,10 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
// do nothing here
} else {
// if a url does not start with http or https, try to add https
newUrlString = "https://\(urlString)"
newURLString = "https://\(urlString)"
}
try? FavIcon.downloadPreferred(newUrlString) { [weak self] result in
try? FavIcon.downloadPreferred(newURLString) { [weak self] result in
if case let .success(image) = result {
let indexPath = IndexPath(row: 0, section: 0)
self?.passwordImage = image

View file

@ -247,7 +247,7 @@ 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) { [unowned self] _ -> Void in
UIAlertAction(title: "Delete".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in
self.performSegue(withIdentifier: "deletePasswordSegue", sender: self)
}
)
@ -440,7 +440,7 @@ extension PasswordEditorTableViewController: SFSafariViewControllerDelegate {
message.append(Utils.attributedPassword(plainPassword: generatedPassword))
alert.setValue(message, forKey: "attributedMessage")
alert.addAction(
UIAlertAction(title: "Yes", style: UIAlertAction.Style.default) { [unowned self] _ -> Void in
UIAlertAction(title: "Yes", style: UIAlertAction.Style.default) { [unowned self] _ 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()

View file

@ -40,9 +40,7 @@ class PasswordNavigationViewController: UIViewController {
return uiSearchController
}()
lazy var searchBar: UISearchBar = {
self.searchController.searchBar
}()
lazy var searchBar: UISearchBar = self.searchController.searchBar
lazy var refreshControl: UIRefreshControl = {
let refreshControl = UIRefreshControl()

View file

@ -92,6 +92,6 @@ extension SSHKeyArmorImportTableViewController: KeyImporter {
}
func importKeys() throws {
try KeyFileManager.PrivateSsh.importKey(from: armorPrivateKey ?? "")
try KeyFileManager.PrivateSSH.importKey(from: armorPrivateKey ?? "")
}
}

View file

@ -75,6 +75,6 @@ extension SSHKeyFileImportTableViewController: KeyImporter {
guard let privateKey = privateKey else {
return
}
try KeyFileManager.PrivateSsh.importKey(from: privateKey)
try KeyFileManager.PrivateSSH.importKey(from: privateKey)
}
}

View file

@ -1,5 +1,5 @@
//
// SSHKeyUrlImportTableViewController.swift
// SSHKeyURLImportTableViewController.swift
// pass
//
// Created by Mingshen Sun on 25/1/2017.
@ -9,7 +9,7 @@
import passKit
import SVProgressHUD
class SSHKeyUrlImportTableViewController: AutoCellHeightUITableViewController {
class SSHKeyURLImportTableViewController: AutoCellHeightUITableViewController {
@IBOutlet var privateKeyURLTextField: UITextField!
var sshPrivateKeyURL: URL?
@ -42,7 +42,7 @@ class SSHKeyUrlImportTableViewController: AutoCellHeightUITableViewController {
}
}
extension SSHKeyUrlImportTableViewController: KeyImporter {
extension SSHKeyURLImportTableViewController: KeyImporter {
static let keySource = KeySource.url
static let label = "DownloadFromUrl".localize()
@ -60,6 +60,6 @@ extension SSHKeyUrlImportTableViewController: KeyImporter {
func importKeys() throws {
Defaults.gitSSHPrivateKeyURL = sshPrivateKeyURL
try KeyFileManager.PrivateSsh.importKey(from: Defaults.gitSSHPrivateKeyURL!)
try KeyFileManager.PrivateSSH.importKey(from: Defaults.gitSSHPrivateKeyURL!)
}
}

View file

@ -150,7 +150,7 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
func showPGPKeyActionSheet() {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
optionMenu.addAction(
UIAlertAction(title: PGPKeyUrlImportTableViewController.menuLabel, style: .default) { _ in
UIAlertAction(title: PGPKeyURLImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setPGPKeyByURLSegue", sender: self)
}
)
@ -184,8 +184,8 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
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())
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
@ -240,19 +240,19 @@ 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 { textField -> Void in
setPasscodeLockAlert?.addTextField { textField in
textField.placeholder = "Passcode".localize()
textField.isSecureTextEntry = true
textField.addTarget(self, action: #selector(self.alertTextFieldDidChange), for: UIControl.Event.editingChanged)
}
setPasscodeLockAlert?.addTextField { textField -> Void in
setPasscodeLockAlert?.addTextField { textField 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
let saveAction = UIAlertAction(title: "Save".localize(), style: .default) { (_: UIAlertAction) in
let passcode: String = self.setPasscodeLockAlert!.textFields![0].text!
self.passcodeLock.save(passcode: passcode)
// refresh the passcode lock cell ("On")
@ -275,12 +275,12 @@ extension SettingsTableViewController: PGPKeyImporter {
static let label = "ITunesFileSharing".localize()
func isReadyToUse() -> Bool {
KeyFileManager.PublicPgp.doesKeyFileExist() && KeyFileManager.PrivatePgp.doesKeyFileExist()
KeyFileManager.PublicPGP.doesKeyFileExist() && KeyFileManager.PrivatePGP.doesKeyFileExist()
}
func importKeys() throws {
try KeyFileManager.PublicPgp.importKeyFromFileSharing()
try KeyFileManager.PrivatePgp.importKeyFromFileSharing()
try KeyFileManager.PublicPGP.importKeyFromFileSharing()
try KeyFileManager.PrivatePGP.importKeyFromFileSharing()
}
func saveImportedKeys() {