From ab5eb4af76d0d3d57ed0fa394024c2f42e1fb989 Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Wed, 21 Oct 2020 19:38:31 +0800 Subject: [PATCH] Fix Swiftlint warnings --- .../Coordinators/ActivitiesCoordinator.swift | 4 ++-- .../DefaultActivityCellViewModel.swift | 16 ++++++++-------- AlphaWallet/AppDelegate.swift | 2 +- .../TokenScriptClient/Models/SolidityType.swift | 2 +- .../Models/TokenScriptFilterParser.swift | 2 +- .../TokenScriptClient/Models/XMLHandler.swift | 2 -- .../Helpers/CallSmartContractFunction.swift | 3 ++- AlphaWallet/Tokens/Models/WalletFilter.swift | 4 ++-- .../TokenInstanceActionViewController.swift | 1 - .../Coordinators/TokensCardCoordinator.swift | 2 ++ .../ConfirmationTransitionController.swift | 2 +- .../Controllers/TransactionConfigurator.swift | 2 +- AlphaWallet/UI/TokenImageView.swift | 1 - .../CreateInitialWalletViewController.swift | 1 - 14 files changed, 21 insertions(+), 23 deletions(-) diff --git a/AlphaWallet/Activities/Coordinators/ActivitiesCoordinator.swift b/AlphaWallet/Activities/Coordinators/ActivitiesCoordinator.swift index 672f38f1a..3ac6c9d17 100644 --- a/AlphaWallet/Activities/Coordinators/ActivitiesCoordinator.swift +++ b/AlphaWallet/Activities/Coordinators/ActivitiesCoordinator.swift @@ -22,7 +22,7 @@ class ActivitiesCoordinator: Coordinator { private var activities: [Activity] = .init() private var transactions: [Transaction] = .init() private var tokensAndTokenHolders: [AlphaWallet.Address: (tokenObject: TokenObject, tokenHolders: [TokenHolder])] = .init() - weak private var activityViewController: ActivityViewController? + weak private var activityViewController: ActivityViewController? private var rateLimitedUpdater: RateLimiter? private var rateLimitedViewControllerReloader: RateLimiter? private var hasLoadedActivitiesTheFirstTime = false @@ -121,7 +121,7 @@ class ActivitiesCoordinator: Coordinator { let eachServer = each.server let xmlHandler = XMLHandler(token: each, assetDefinitionStore: assetDefinitionStore) guard xmlHandler.hasAssetDefinition else { return nil } - guard (xmlHandler.server?.matches(server: eachServer) ?? false) else { return nil } + guard xmlHandler.server?.matches(server: eachServer) ?? false else { return nil } return (contract: eachContract, server: eachServer, xmlHandler: xmlHandler) } diff --git a/AlphaWallet/Activities/ViewModels/DefaultActivityCellViewModel.swift b/AlphaWallet/Activities/ViewModels/DefaultActivityCellViewModel.swift index 7546c49ff..0bf7275b4 100644 --- a/AlphaWallet/Activities/ViewModels/DefaultActivityCellViewModel.swift +++ b/AlphaWallet/Activities/ViewModels/DefaultActivityCellViewModel.swift @@ -31,23 +31,23 @@ struct DefaultActivityCellViewModel { switch activity.nativeViewType { case .erc20Sent, .erc721Sent, .nativeCryptoSent: let string = NSMutableAttributedString(string: "\(R.string.localizable.transactionCellSentTitle()) \(symbol)") - string.addAttribute(.font, value: Fonts.regular(size: 17)! , range: NSRange(location: 0, length: string.length)) - string.addAttribute(.font, value: Fonts.semibold(size: 17)! , range: NSRange(location: string.length - symbol.count, length: symbol.count)) + string.addAttribute(.font, value: Fonts.regular(size: 17)!, range: NSRange(location: 0, length: string.length)) + string.addAttribute(.font, value: Fonts.semibold(size: 17)!, range: NSRange(location: string.length - symbol.count, length: symbol.count)) return string case .erc20Received, .erc721Received, .nativeCryptoReceived: let string = NSMutableAttributedString(string: "\(R.string.localizable.transactionCellReceivedTitle()) \(symbol)") - string.addAttribute(.font, value: Fonts.regular(size: 17)! , range: NSRange(location: 0, length: string.length)) - string.addAttribute(.font, value: Fonts.semibold(size: 17)! , range: NSRange(location: string.length - symbol.count, length: symbol.count)) + string.addAttribute(.font, value: Fonts.regular(size: 17)!, range: NSRange(location: 0, length: string.length)) + string.addAttribute(.font, value: Fonts.semibold(size: 17)!, range: NSRange(location: string.length - symbol.count, length: symbol.count)) return string case .erc20OwnerApproved, .erc721OwnerApproved: let string = NSMutableAttributedString(string: R.string.localizable.activityOwnerApproved(symbol)) - string.addAttribute(.font, value: Fonts.regular(size: 17)! , range: NSRange(location: 0, length: string.length)) - string.addAttribute(.font, value: Fonts.semibold(size: 17)! , range: NSRange(location: string.length - symbol.count, length: symbol.count)) + string.addAttribute(.font, value: Fonts.regular(size: 17)!, range: NSRange(location: 0, length: string.length)) + string.addAttribute(.font, value: Fonts.semibold(size: 17)!, range: NSRange(location: string.length - symbol.count, length: symbol.count)) return string case .erc20ApprovalObtained, .erc721ApprovalObtained: let string = NSMutableAttributedString(string: R.string.localizable.activityApprovalObtained(symbol)) - string.addAttribute(.font, value: Fonts.regular(size: 17)! , range: NSRange(location: 0, length: string.length)) - string.addAttribute(.font, value: Fonts.semibold(size: 17)! , range: NSRange(location: string.length - symbol.count, length: symbol.count)) + string.addAttribute(.font, value: Fonts.regular(size: 17)!, range: NSRange(location: 0, length: string.length)) + string.addAttribute(.font, value: Fonts.semibold(size: 17)!, range: NSRange(location: string.length - symbol.count, length: symbol.count)) return string case .none: return .init() diff --git a/AlphaWallet/AppDelegate.swift b/AlphaWallet/AppDelegate.swift index 47978ce2b..52c170c3b 100644 --- a/AlphaWallet/AppDelegate.swift +++ b/AlphaWallet/AppDelegate.swift @@ -43,7 +43,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele return true } - func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> ()) { + func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { if shortcutItem.type == Constants.launchShortcutKey { appCoordinator.launchUniversalScanner() } diff --git a/AlphaWallet/TokenScriptClient/Models/SolidityType.swift b/AlphaWallet/TokenScriptClient/Models/SolidityType.swift index be4248067..40083b4bb 100644 --- a/AlphaWallet/TokenScriptClient/Models/SolidityType.swift +++ b/AlphaWallet/TokenScriptClient/Models/SolidityType.swift @@ -29,7 +29,7 @@ enum SolidityType: String { return nil case .string: return coerceAsString(originalValue) - case .int, .int8, .int16, .int24, .int32, .int40, .int48, .int56, .int64, .int72, .int80, .int88, .int96, .int104, .int112, .int120, .int128, .int136, .int144, .int152, .int160, .int168, .int176, .int184, .int192, .int200, .int208, .int216, .int224, .int232, .int240, .int248, .int256: + case .int, .int8, .int16, .int24, .int32, .int40, .int48, .int56, .int64, .int72, .int80, .int88, .int96, .int104, .int112, .int120, .int128, .int136, .int144, .int152, .int160, .int168, .int176, .int184, .int192, .int200, .int208, .int216, .int224, .int232, .int240, .int248, .int256: return coerceAsInt(originalValue) case .void: return nil diff --git a/AlphaWallet/TokenScriptClient/Models/TokenScriptFilterParser.swift b/AlphaWallet/TokenScriptClient/Models/TokenScriptFilterParser.swift index 477ae06c9..a201ff80b 100644 --- a/AlphaWallet/TokenScriptClient/Models/TokenScriptFilterParser.swift +++ b/AlphaWallet/TokenScriptClient/Models/TokenScriptFilterParser.swift @@ -194,7 +194,7 @@ struct TokenScriptFilterParser { var buffer: [Character] = [] var escapeBuffer: [Character]? = nil var wasPreviousEscapedCharacter = false - for (_, c) in expression.enumerated() { + for c in expression { let previous = buffer.last.flatMap { String($0) } if c == escape && escapeBuffer == nil { //start new escape diff --git a/AlphaWallet/TokenScriptClient/Models/XMLHandler.swift b/AlphaWallet/TokenScriptClient/Models/XMLHandler.swift index 6c1fea0c5..0dd556b68 100644 --- a/AlphaWallet/TokenScriptClient/Models/XMLHandler.swift +++ b/AlphaWallet/TokenScriptClient/Models/XMLHandler.swift @@ -1,4 +1,3 @@ -// // XMLHandler.swift // AlphaWallet // @@ -425,7 +424,6 @@ private class PrivateXMLHandler { ) } - func resolveAttributesBypassingCache(withTokenIdOrEvent tokenIdOrEvent: TokenIdOrEvent, server: RPCServer, account: Wallet) -> [AttributeId: AssetAttributeSyntaxValue] { fields.resolve(withTokenIdOrEvent: tokenIdOrEvent, userEntryValues: .init(), server: server, account: account, additionalValues: .init(), localRefs: .init()) } diff --git a/AlphaWallet/Tokens/Helpers/CallSmartContractFunction.swift b/AlphaWallet/Tokens/Helpers/CallSmartContractFunction.swift index 0ba8df8d1..27b66134b 100644 --- a/AlphaWallet/Tokens/Helpers/CallSmartContractFunction.swift +++ b/AlphaWallet/Tokens/Helpers/CallSmartContractFunction.swift @@ -7,9 +7,10 @@ import web3swift //TODO time to wrap `callSmartContract` with a class //TODO wrap callSmartContract() and cache into a type +// swiftlint:disable private_over_fileprivate fileprivate var smartContractCallsCache = [String: (promise: Promise<[String: Any]>, timestamp: Date)]() - fileprivate var web3s = [RPCServer: [TimeInterval: web3]]() +// swiftlint:enable private_over_fileprivate func getCachedWeb3(forServer server: RPCServer, timeout: TimeInterval) throws -> web3 { if let result = web3s[server]?[timeout] { diff --git a/AlphaWallet/Tokens/Models/WalletFilter.swift b/AlphaWallet/Tokens/Models/WalletFilter.swift index fbdc1f433..c6f774943 100644 --- a/AlphaWallet/Tokens/Models/WalletFilter.swift +++ b/AlphaWallet/Tokens/Models/WalletFilter.swift @@ -25,8 +25,8 @@ func == (lhs: WalletFilter, rhs: WalletFilter) -> Bool { return keyword1 == keyword2 case (.keyword, .all), (.keyword, .currencyOnly), (.keyword, .assetsOnly), (.keyword, .collectiblesOnly), (.collectiblesOnly, .all), (.collectiblesOnly, .currencyOnly), (.collectiblesOnly, .assetsOnly), (.collectiblesOnly, .keyword), (.assetsOnly, .all), (.assetsOnly, .currencyOnly), (.assetsOnly, .collectiblesOnly), (.assetsOnly, .keyword), (.currencyOnly, .all), (.currencyOnly, .assetsOnly), (.currencyOnly, .collectiblesOnly), (.currencyOnly, .keyword), (.all, .currencyOnly), (.all, .assetsOnly), (.all, .collectiblesOnly), (.all, .keyword): return false - case (.type(_), _), (_, .type(_)): + case (.type, _), (_, .type): return true - } + } } diff --git a/AlphaWallet/Tokens/ViewControllers/TokenInstanceActionViewController.swift b/AlphaWallet/Tokens/ViewControllers/TokenInstanceActionViewController.swift index 14d8ebe0f..1d20ac4d9 100644 --- a/AlphaWallet/Tokens/ViewControllers/TokenInstanceActionViewController.swift +++ b/AlphaWallet/Tokens/ViewControllers/TokenInstanceActionViewController.swift @@ -28,7 +28,6 @@ class TokenInstanceActionViewController: UIViewController, TokenVerifiableStatus return webView }() - //TODO might have to change the number of buttons? if the action type change or should we just go back since the flow may be broken if we remain in this screen private let buttonsBar = ButtonsBar(configuration: .green(buttons: 1)) private var isFungible: Bool { diff --git a/AlphaWallet/Transactions/Coordinators/TokensCardCoordinator.swift b/AlphaWallet/Transactions/Coordinators/TokensCardCoordinator.swift index f4b1e7f53..b545f30b5 100644 --- a/AlphaWallet/Transactions/Coordinators/TokensCardCoordinator.swift +++ b/AlphaWallet/Transactions/Coordinators/TokensCardCoordinator.swift @@ -17,6 +17,7 @@ protocol TokensCardCoordinatorDelegate: class, CanOpenURL { func didPostTokenScriptTransaction(_ transaction: SentTransaction, in coordinator: TokensCardCoordinator) } +// swiftlint:disable type_body_length class TokensCardCoordinator: NSObject, Coordinator { private let keystore: Keystore private let token: TokenObject @@ -427,6 +428,7 @@ class TokensCardCoordinator: NSObject, Coordinator { viewController.navigationController?.pushViewController(vc, animated: true) } } +// swiftlint:enable type_body_length extension TokensCardCoordinator: TokensCardViewControllerDelegate { func didPressRedeem(token: TokenObject, tokenHolder: TokenHolder, in viewController: TokensCardViewController) { diff --git a/AlphaWallet/Transfer/Controllers/ConfirmationTransitionController.swift b/AlphaWallet/Transfer/Controllers/ConfirmationTransitionController.swift index e18cdb5b4..210ca7f51 100644 --- a/AlphaWallet/Transfer/Controllers/ConfirmationTransitionController.swift +++ b/AlphaWallet/Transfer/Controllers/ConfirmationTransitionController.swift @@ -24,7 +24,7 @@ extension UINavigationController: UpdatablePreferredContentSizeContainer { class ConfirmationTransitionController: NSObject { //NOTE: Need to retain self until dismissal because UIKit won't. - private var selfRetainer: ConfirmationTransitionController? = nil + private var selfRetainer: ConfirmationTransitionController? private let sourceViewController: UIViewController private let destinationViewController: UIViewController private let presenter = Presenter() diff --git a/AlphaWallet/Transfer/Controllers/TransactionConfigurator.swift b/AlphaWallet/Transfer/Controllers/TransactionConfigurator.swift index 9530a06f5..6e72fd40f 100644 --- a/AlphaWallet/Transfer/Controllers/TransactionConfigurator.swift +++ b/AlphaWallet/Transfer/Controllers/TransactionConfigurator.swift @@ -87,7 +87,7 @@ class TransactionConfigurator { switch transaction.transferType { case .nativeCryptocurrency, .dapp, .ERC875TokenOrder: return transaction.value case .ERC20Token, .ERC721Token, .ERC721ForTicketToken, .ERC875Token: - return 0; + return 0 } }() let request = EstimateGasRequest( diff --git a/AlphaWallet/UI/TokenImageView.swift b/AlphaWallet/UI/TokenImageView.swift index 47d403a70..fb50f2e22 100644 --- a/AlphaWallet/UI/TokenImageView.swift +++ b/AlphaWallet/UI/TokenImageView.swift @@ -38,7 +38,6 @@ class TokenImageView: UIView { } } - override init(frame: CGRect) { super.init(frame: frame) diff --git a/AlphaWallet/Wallet/ViewControllers/CreateInitialWalletViewController.swift b/AlphaWallet/Wallet/ViewControllers/CreateInitialWalletViewController.swift index 97363dd6d..81b0209f5 100644 --- a/AlphaWallet/Wallet/ViewControllers/CreateInitialWalletViewController.swift +++ b/AlphaWallet/Wallet/ViewControllers/CreateInitialWalletViewController.swift @@ -20,7 +20,6 @@ class CreateInitialWalletViewController: UIViewController { private let haveWalletLabel = UILabel() private let buttonsBar = ButtonsBar(configuration: .white(buttons: 2)) - private var imageViewDimension: CGFloat { if ScreenChecker().isNarrowScreen { return 60