From 0e2556544e617088d830dfb6d5ca53164a0d4c7c Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 8 Feb 2019 17:05:58 +0100 Subject: Global: fix swiftlint issues Signed-off-by: Jason A. Donenfeld --- .../WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift | 2 -- WireGuard/WireGuard/Tunnel/TunnelsManager.swift | 2 +- WireGuard/WireGuard/UI/TunnelViewModel.swift | 4 +--- .../iOS/ViewController/TunnelDetailTableViewController.swift | 8 +++++++- .../UI/iOS/ViewController/TunnelEditTableViewController.swift | 11 ++++++----- WireGuard/WireGuard/UI/macOS/StatusMenu.swift | 1 - 6 files changed, 15 insertions(+), 13 deletions(-) (limited to 'WireGuard/WireGuard') diff --git a/WireGuard/WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift b/WireGuard/WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift index b72223d..38f1e6f 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelConfiguration+UapiConfig.swift @@ -4,7 +4,6 @@ import Foundation extension TunnelConfiguration { - //swiftlint:disable:next function_body_length cyclomatic_complexity convenience init(fromUapiConfig uapiConfig: String, basedOn base: TunnelConfiguration? = nil) throws { var interfaceConfiguration: InterfaceConfiguration? var peerConfigurations = [PeerConfiguration]() @@ -103,7 +102,6 @@ extension TunnelConfiguration { return interface } - //swiftlint:disable:next cyclomatic_complexity private static func collate(peerAttributes attributes: [String: String]) throws -> PeerConfiguration { guard let publicKeyString = attributes["public_key"] else { throw ParseError.peerHasNoPublicKey diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift index a7909ff..8718ccf 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift @@ -446,7 +446,6 @@ class TunnelContainer: NSObject { isActivateOnDemandEnabled = tunnelProvider.isOnDemandEnabled } - //swiftlint:disable:next function_body_length fileprivate func startActivation(recursionCount: UInt = 0, lastError: Error? = nil, activationDelegate: TunnelsManagerActivationDelegate?) { if recursionCount >= 8 { wg_log(.error, message: "startActivation: Failed after 8 attempts. Giving up with \(lastError!)") @@ -532,6 +531,7 @@ extension NETunnelProviderManager { } return config } + func setTunnelConfiguration(_ tunnelConfiguration: TunnelConfiguration) { protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, previouslyFrom: protocolConfiguration) localizedDescription = tunnelConfiguration.name diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift index 35dd98b..efca5c0 100644 --- a/WireGuard/WireGuard/UI/TunnelViewModel.swift +++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift @@ -3,7 +3,6 @@ import Foundation -//swiftlint:disable:next type_body_length class TunnelViewModel { enum InterfaceField: CaseIterable { @@ -74,6 +73,7 @@ class TunnelViewModel { case removed case modified } + var interfaceChanged: ([InterfaceField: FieldChange]) -> Void var peerChangedAt: (Int, [PeerField: FieldChange]) -> Void var peersRemovedAt: ([Int]) -> Void @@ -141,7 +141,6 @@ class TunnelViewModel { return scratchpad } - //swiftlint:disable:next cyclomatic_complexity function_body_length func save() -> SaveResult<(String, InterfaceConfiguration)> { if let config = validatedConfiguration, let name = validatedName { return .saved((name, config)) @@ -327,7 +326,6 @@ class TunnelViewModel { return scratchpad } - //swiftlint:disable:next cyclomatic_complexity func save() -> SaveResult { if let validatedConfiguration = validatedConfiguration { return .saved(validatedConfiguration) diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift index 7ed019b..1eb6461 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift @@ -147,7 +147,13 @@ class TunnelDetailTableViewController: UITableViewController { // Incorporates changes from tunnelConfiguation. Ignores any changes in peer ordering. guard let tableView = self.tableView else { return } let sections = self.sections - let interfaceSectionIndex = sections.firstIndex(where: { if case .interface = $0 { return true } else { return false }})! + let interfaceSectionIndex = sections.firstIndex { + if case .interface = $0 { + return true + } else { + return false + } + }! let firstPeerSectionIndex = interfaceSectionIndex + 1 var interfaceFieldIsVisible = self.interfaceFieldIsVisible var peerFieldIsVisible = self.peerFieldIsVisible diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift index 01fed49..0b0be6d 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift @@ -302,6 +302,8 @@ extension TunnelEditTableViewController { guard let self = self else { return } let removedSectionIndices = self.deletePeer(peer: peerData) let shouldShowExcludePrivateIPs = (self.tunnelViewModel.peersData.count == 1 && self.tunnelViewModel.peersData[0].shouldAllowExcludePrivateIPsControl) + + //swiftlint:disable:next trailing_closure tableView.performBatchUpdates({ self.tableView.deleteSections(removedSectionIndices, with: .fade) if shouldShowExcludePrivateIPs { @@ -309,7 +311,6 @@ extension TunnelEditTableViewController { let rowIndexPath = IndexPath(row: row, section: self.interfaceFieldsBySection.count /* First peer section */) self.tableView.insertRows(at: [rowIndexPath], with: .fade) } - } }) } @@ -359,9 +360,9 @@ extension TunnelEditTableViewController { cell.value = peerData[field] if field == .allowedIPs { - let firstInterfaceSection = sections.firstIndex(where: { $0 == .interface })! - let interfaceSubSection = interfaceFieldsBySection.firstIndex(where: { $0.contains(.dns) })! - let dnsRow = interfaceFieldsBySection[interfaceSubSection].firstIndex(where: { $0 == .dns })! + let firstInterfaceSection = sections.firstIndex { $0 == .interface }! + let interfaceSubSection = interfaceFieldsBySection.firstIndex { $0.contains(.dns) }! + let dnsRow = interfaceFieldsBySection[interfaceSubSection].firstIndex { $0 == .dns }! cell.onValueBeingEdited = { [weak self, weak peerData] value in guard let self = self, let peerData = peerData else { return } @@ -419,7 +420,7 @@ extension TunnelEditTableViewController { self.activateOnDemandSetting.isActivateOnDemandEnabled = isOn self.loadSections() - let section = self.sections.firstIndex(where: { $0 == .onDemand })! + let section = self.sections.firstIndex { $0 == .onDemand }! let indexPaths = (1 ..< 4).map { IndexPath(row: $0, section: section) } if isOn { if self.activateOnDemandSetting.activateOnDemandOption == .none { diff --git a/WireGuard/WireGuard/UI/macOS/StatusMenu.swift b/WireGuard/WireGuard/UI/macOS/StatusMenu.swift index 376a57a..70d536b 100644 --- a/WireGuard/WireGuard/UI/macOS/StatusMenu.swift +++ b/WireGuard/WireGuard/UI/macOS/StatusMenu.swift @@ -57,7 +57,6 @@ class StatusMenu: NSMenu { self.networksMenuItem = networksMenuItem } - //swiftlint:disable:next cyclomatic_complexity func updateStatusMenuItems(with tunnel: TunnelContainer?) { guard let statusMenuItem = statusMenuItem, let networksMenuItem = networksMenuItem else { return } guard let tunnel = tunnel else { -- cgit v1.2.3-59-g8ed1b