From 77216abe146e74ac4578a0abaafbdec61d600901 Mon Sep 17 00:00:00 2001 From: Danny Moesch Date: Sun, 5 Jul 2020 00:40:05 +0200 Subject: [PATCH] Enable SwiftLint rule 'nesting' and fix all violations --- .swiftlint.yml | 2 +- pass.xcodeproj/project.pbxproj | 12 +++++ ...PGPKeyArmorImportTableViewController.swift | 45 ---------------- pass/Models/ScannedPGPKey.swift | 52 +++++++++++++++++++ 4 files changed, 65 insertions(+), 46 deletions(-) create mode 100644 pass/Models/ScannedPGPKey.swift diff --git a/.swiftlint.yml b/.swiftlint.yml index 84aa5a6..9579382 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -103,7 +103,7 @@ whitelist_rules: - multiline_parameters - multiline_parameters_brackets - multiple_closures_with_trailing_closure -# - nesting + - nesting - nimble_operator # - no_extension_access_modifier - no_fallthrough_only diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index d5c4f4b..50950ac 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 116F7CC922E134FA003B3BAC /* Crypto.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 116F7CC822E134FA003B3BAC /* Crypto.framework */; }; 116F7CCA22E134FA003B3BAC /* Crypto.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 116F7CC822E134FA003B3BAC /* Crypto.framework */; }; + 3005F35424B13C3E000519B5 /* ScannedPGPKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3005F35324B13C3E000519B5 /* ScannedPGPKey.swift */; }; 300713C52219D54100F553AC /* AutoCellHeightUITableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 300713C42219D54100F553AC /* AutoCellHeightUITableViewController.swift */; }; 301F6463216162550071A4CE /* AdditionField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 301F6462216162550071A4CE /* AdditionField.swift */; }; 301F6468216165290071A4CE /* ConstantsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 301F6467216165290071A4CE /* ConstantsTest.swift */; }; @@ -260,6 +261,7 @@ 116F7CC822E134FA003B3BAC /* Crypto.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Crypto.framework; path = go/dist/Crypto.framework; sourceTree = ""; }; 134DA5B66070BA56678688CF /* Pods_passKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_passKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 14E955B67C88672AA3A40BA0 /* Pods_passExtension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_passExtension.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 3005F35324B13C3E000519B5 /* ScannedPGPKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannedPGPKey.swift; sourceTree = ""; }; 300713C42219D54100F553AC /* AutoCellHeightUITableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoCellHeightUITableViewController.swift; sourceTree = ""; }; 301F6462216162550071A4CE /* AdditionField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdditionField.swift; sourceTree = ""; }; 301F6467216165290071A4CE /* ConstantsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsTest.swift; sourceTree = ""; }; @@ -514,6 +516,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 3005F35224B13BF3000519B5 /* Models */ = { + isa = PBXGroup; + children = ( + 3005F35324B13C3E000519B5 /* ScannedPGPKey.swift */, + ); + path = Models; + sourceTree = ""; + }; 301F6464216164670071A4CE /* Helpers */ = { isa = PBXGroup; children = ( @@ -900,6 +910,7 @@ children = ( DC19400C1E4B39400077E0A3 /* Controllers */, DC19400E1E4B3A610077E0A3 /* Helpers */, + 3005F35224B13BF3000519B5 /* Models */, DC19400F1E4B3A9E0077E0A3 /* Views */, DC917BDD1E2E8231000FDF54 /* Assets.xcassets */, DC917BD61E2E8231000FDF54 /* AppDelegate.swift */, @@ -1588,6 +1599,7 @@ DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */, DC5F385B1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift in Sources */, DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */, + 3005F35424B13C3E000519B5 /* ScannedPGPKey.swift in Sources */, DCFB77A71E502DF9008DE471 /* EditPasswordTableViewController.swift in Sources */, DCA0499A1E335CC800522E8F /* GitRepositorySettingsTableViewController.swift in Sources */, DCDDEAB31E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift in Sources */, diff --git a/pass/Controllers/PGPKeyArmorImportTableViewController.swift b/pass/Controllers/PGPKeyArmorImportTableViewController.swift index 91d1699..abecf23 100644 --- a/pass/Controllers/PGPKeyArmorImportTableViewController.swift +++ b/pass/Controllers/PGPKeyArmorImportTableViewController.swift @@ -18,51 +18,6 @@ class PGPKeyArmorImportTableViewController: AutoCellHeightUITableViewController, var armorPublicKey: String? var armorPrivateKey: String? - class ScannedPGPKey { - enum KeyType { - case publicKey, privateKey - } - - var keyType = KeyType.publicKey - var segments = [String]() - var message = "" - - func reset(keytype: KeyType) { - keyType = keytype - segments.removeAll() - message = "LookingForStartingFrame.".localize() - } - - func addSegment(segment: String) -> (accept: Bool, message: String) { - let keyTypeStr = keyType == .publicKey ? "Public" : "Private" - let theOtherKeyTypeStr = keyType == .publicKey ? "Private" : "Public" - - // Skip duplicated segments. - guard segment != segments.last else { - return (accept: false, message: message) - } - - // Check whether we have found the first block. - guard !segments.isEmpty || segment.contains("-----BEGIN PGP \(keyTypeStr.uppercased()) KEY BLOCK-----") else { - // Check whether we are scanning the wrong key type. - if segment.contains("-----BEGIN PGP \(theOtherKeyTypeStr.uppercased()) KEY BLOCK-----") { - message = "Scan\(keyTypeStr)Key.".localize() - } - return (accept: false, message: message) - } - - // Update the list of scanned segment and return. - segments.append(segment) - if segment.contains("-----END PGP \(keyTypeStr.uppercased()) KEY BLOCK-----") { - message = "Done".localize() - return (accept: true, message: message) - } else { - message = "ScannedQrCodes(%d)".localize(segments.count) - return (accept: false, message: message) - } - } - } - var scanned = ScannedPGPKey() override func viewDidLoad() { diff --git a/pass/Models/ScannedPGPKey.swift b/pass/Models/ScannedPGPKey.swift new file mode 100644 index 0000000..d0d7ccf --- /dev/null +++ b/pass/Models/ScannedPGPKey.swift @@ -0,0 +1,52 @@ +// +// ScannedPGPKey.swift +// pass +// +// Created by Danny Moesch on 05.07.20. +// Copyright © 2020 Bob Sun. All rights reserved. +// + +class ScannedPGPKey { + enum KeyType { + case publicKey, privateKey + } + + var keyType = KeyType.publicKey + var segments = [String]() + var message = "" + + func reset(keytype: KeyType) { + keyType = keytype + segments.removeAll() + message = "LookingForStartingFrame.".localize() + } + + func addSegment(segment: String) -> (accept: Bool, message: String) { + let keyTypeStr = keyType == .publicKey ? "Public" : "Private" + let theOtherKeyTypeStr = keyType == .publicKey ? "Private" : "Public" + + // Skip duplicated segments. + guard segment != segments.last else { + return (accept: false, message: message) + } + + // Check whether we have found the first block. + guard !segments.isEmpty || segment.contains("-----BEGIN PGP \(keyTypeStr.uppercased()) KEY BLOCK-----") else { + // Check whether we are scanning the wrong key type. + if segment.contains("-----BEGIN PGP \(theOtherKeyTypeStr.uppercased()) KEY BLOCK-----") { + message = "Scan\(keyTypeStr)Key.".localize() + } + return (accept: false, message: message) + } + + // Update the list of scanned segment and return. + segments.append(segment) + if segment.contains("-----END PGP \(keyTypeStr.uppercased()) KEY BLOCK-----") { + message = "Done".localize() + return (accept: true, message: message) + } else { + message = "ScannedQrCodes(%d)".localize(segments.count) + return (accept: false, message: message) + } + } +}