Update SwiftLint and SwiftFormat (#613)
* Update Swift version used by SwiftFormat * Update SwiftLint version * Rely on new virtual 'all' rule in SwiftLint * Enable SwiftLint rule 'direct_return' rule and fix all violations * Enable SwiftLint rule 'shorthand_optional_binding' rule and fix all violations * Enable SwiftLint rule 'blanket_disable_command' rule and fix all violations
This commit is contained in:
parent
a22e872a8c
commit
d9bd0f3014
24 changed files with 90 additions and 272 deletions
|
|
@ -129,7 +129,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
|
||||
override open func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
if let biometryAuthButton = biometryAuthButton {
|
||||
if let biometryAuthButton {
|
||||
bioButtonPressedAction(biometryAuthButton)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
|
||||
func decrypt(encryptedData: Data, keyID: String?, passphrase: String) throws -> Data? {
|
||||
let key: CryptoKey? = {
|
||||
if let keyID = keyID {
|
||||
if let keyID {
|
||||
return privateKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) })?.value
|
||||
}
|
||||
return privateKeys.first?.value
|
||||
|
|
@ -109,7 +109,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
|
||||
func encrypt(plainData: Data, keyID: String?) throws -> Data {
|
||||
let key: CryptoKey? = {
|
||||
if let keyID = keyID {
|
||||
if let keyID {
|
||||
return publicKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) })?.value
|
||||
}
|
||||
return publicKeys.first?.value
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class PGPAgent {
|
|||
public func decrypt(encryptedData: Data, keyID: String, requestPGPKeyPassphrase: @escaping (String) -> String) throws -> Data? {
|
||||
// Init keys.
|
||||
try checkAndInit()
|
||||
guard let pgpInterface = pgpInterface else {
|
||||
guard let pgpInterface else {
|
||||
throw AppError.decryption
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ public class PGPAgent {
|
|||
|
||||
public func encrypt(plainData: Data, keyID: String) throws -> Data {
|
||||
try checkAndInit()
|
||||
guard let pgpInterface = pgpInterface else {
|
||||
guard let pgpInterface else {
|
||||
throw AppError.encryption
|
||||
}
|
||||
var keyID = keyID
|
||||
|
|
@ -120,7 +120,7 @@ public class PGPAgent {
|
|||
|
||||
public func encrypt(plainData: Data) throws -> Data {
|
||||
try checkAndInit()
|
||||
guard let pgpInterface = pgpInterface else {
|
||||
guard let pgpInterface else {
|
||||
throw AppError.encryption
|
||||
}
|
||||
return try pgpInterface.encrypt(plainData: plainData, keyID: nil)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public extension FileManager {
|
|||
}
|
||||
|
||||
// We have to enumerate all directory contents, including subdirectories.
|
||||
let enumerator = self.enumerator(
|
||||
let enumerator = enumerator(
|
||||
at: directoryURL,
|
||||
includingPropertiesForKeys: prefetchedProperties,
|
||||
options: Self.DirectoryEnumerationOptions(),
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ import YubiKit
|
|||
|
||||
public enum YubiKeyAPDU {
|
||||
public static func selectOpenPGPApplication() -> YKFSelectApplicationAPDU {
|
||||
let selectOpenPGPAPDU = YKFSelectApplicationAPDU(data: Data([0xD2, 0x76, 0x00, 0x01, 0x24, 0x01]))!
|
||||
return selectOpenPGPAPDU
|
||||
YKFSelectApplicationAPDU(data: Data([0xD2, 0x76, 0x00, 0x01, 0x24, 0x01]))!
|
||||
}
|
||||
|
||||
public static func verify(password: String) -> YKFAPDU {
|
||||
|
|
@ -22,8 +21,7 @@ public enum YubiKeyAPDU {
|
|||
apdu += [0x82] // P2: PW1
|
||||
apdu += withUnsafeBytes(of: UInt8(pw1.count).bigEndian, Array.init)
|
||||
apdu += pw1
|
||||
let verifyApdu = YKFAPDU(data: Data(apdu))!
|
||||
return verifyApdu
|
||||
return YKFAPDU(data: Data(apdu))!
|
||||
}
|
||||
|
||||
public static func decipherExtended(data: Data) -> [YKFAPDU] {
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public class Password {
|
|||
|
||||
private func checkPasswordForOtpToken() {
|
||||
let (key, value) = Parser.getKeyValuePair(from: password)
|
||||
if let key = key, Constants.isOtpKeyword(key) {
|
||||
if let key, Constants.isOtpKeyword(key) {
|
||||
firstLineIsOTPField = true
|
||||
additions.append(key => value)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import SwiftyUserDefaults
|
|||
|
||||
public extension PasswordEntity {
|
||||
var nameWithCategory: String {
|
||||
if let path = path {
|
||||
if let path {
|
||||
if path.hasSuffix(".gpg") {
|
||||
return String(path.prefix(upTo: path.index(path.endIndex, offsetBy: -4)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ public class PasswordStore {
|
|||
}
|
||||
|
||||
private func checkoutAndChangeBranch(withName localBranchName: String, progressBlock: @escaping (String, UInt, UInt) -> Void) throws {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
throw AppError.repositoryNotSet
|
||||
}
|
||||
let remoteBranchName = "origin/\(localBranchName)"
|
||||
|
|
@ -218,7 +218,7 @@ public class PasswordStore {
|
|||
options: [String: Any],
|
||||
progressBlock: @escaping (UnsafePointer<git_transfer_progress>, UnsafeMutablePointer<ObjCBool>) -> Void = { _, _ in }
|
||||
) throws {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
throw AppError.repositoryNotSet
|
||||
}
|
||||
let remote = try GTRemote(name: "origin", in: storeRepository)
|
||||
|
|
@ -284,7 +284,7 @@ public class PasswordStore {
|
|||
}
|
||||
|
||||
public func getRecentCommits(count: Int) throws -> [GTCommit] {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
return []
|
||||
}
|
||||
var commits = [GTCommit]()
|
||||
|
|
@ -328,8 +328,7 @@ public class PasswordStore {
|
|||
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||
passwordEntityFetchRequest.predicate = NSPredicate(format: "synced = %i", 0)
|
||||
do {
|
||||
let passwordEntities = try context.fetch(passwordEntityFetchRequest) as! [PasswordEntity]
|
||||
return passwordEntities
|
||||
return try context.fetch(passwordEntityFetchRequest) as! [PasswordEntity]
|
||||
} catch {
|
||||
fatalError("FailedToFetchPasswords".localize(error))
|
||||
}
|
||||
|
|
@ -357,7 +356,7 @@ public class PasswordStore {
|
|||
}
|
||||
|
||||
public func getLatestUpdateInfo(filename: String) -> String {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
return "Unknown".localize()
|
||||
}
|
||||
guard let blameHunks = try? storeRepository.blame(withFile: filename, options: nil).hunks else {
|
||||
|
|
@ -374,7 +373,7 @@ public class PasswordStore {
|
|||
}
|
||||
|
||||
private func gitAdd(path: String) throws {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
throw AppError.repositoryNotSet
|
||||
}
|
||||
try storeRepository.index().addFile(path)
|
||||
|
|
@ -382,7 +381,7 @@ public class PasswordStore {
|
|||
}
|
||||
|
||||
private func gitRm(path: String) throws {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
throw AppError.repositoryNotSet
|
||||
}
|
||||
let url = storeURL.appendingPathComponent(path)
|
||||
|
|
@ -417,7 +416,7 @@ public class PasswordStore {
|
|||
}
|
||||
|
||||
private func gitCommit(message: String) throws -> GTCommit? {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
throw AppError.repositoryNotSet
|
||||
}
|
||||
let newTree = try storeRepository.index().writeTree()
|
||||
|
|
@ -428,12 +427,11 @@ public class PasswordStore {
|
|||
guard let signature = gitSignatureForNow else {
|
||||
throw AppError.gitCreateSignature
|
||||
}
|
||||
let commit = try storeRepository.createCommit(with: newTree, message: message, author: signature, committer: signature, parents: [parent], updatingReferenceNamed: headReference.name)
|
||||
return commit
|
||||
return try storeRepository.createCommit(with: newTree, message: message, author: signature, committer: signature, parents: [parent], updatingReferenceNamed: headReference.name)
|
||||
}
|
||||
|
||||
private func getLocalBranch(withName branchName: String) throws -> GTBranch? {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
throw AppError.repositoryNotSet
|
||||
}
|
||||
let reference = GTBranch.localNamePrefix().appending(branchName)
|
||||
|
|
@ -445,7 +443,7 @@ public class PasswordStore {
|
|||
options: [String: Any],
|
||||
transferProgressBlock: @escaping (UInt32, UInt32, Int, UnsafeMutablePointer<ObjCBool>) -> Void = { _, _, _, _ in }
|
||||
) throws {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
throw AppError.repositoryNotSet
|
||||
}
|
||||
if let branch = try getLocalBranch(withName: Defaults.gitBranchName) {
|
||||
|
|
@ -588,7 +586,7 @@ public class PasswordStore {
|
|||
}
|
||||
|
||||
public func updateImage(passwordEntity: PasswordEntity, image: Data?) {
|
||||
guard let image = image else {
|
||||
guard let image else {
|
||||
return
|
||||
}
|
||||
let privateMOC = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
|
||||
|
|
@ -638,7 +636,7 @@ public class PasswordStore {
|
|||
|
||||
// return the number of discarded commits
|
||||
public func reset() throws -> Int {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
throw AppError.repositoryNotSet
|
||||
}
|
||||
// get a list of local commits
|
||||
|
|
@ -662,7 +660,7 @@ public class PasswordStore {
|
|||
}
|
||||
|
||||
private func getLocalCommits() throws -> [GTCommit] {
|
||||
guard let storeRepository = storeRepository else {
|
||||
guard let storeRepository else {
|
||||
throw AppError.repositoryNotSet
|
||||
}
|
||||
// get the remote branch
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public extension AlertPresenting where Self: UIViewController {
|
|||
)
|
||||
}
|
||||
|
||||
// swiftlint:disable function_default_parameter_at_end
|
||||
// swiftlint:disable:next function_default_parameter_at_end
|
||||
func presentFailureAlert(title: String? = nil, message: String, action: AlertAction? = nil) {
|
||||
let title = title ?? "Error"
|
||||
presentAlert(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue