Global: fix swiftlint issues
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
2ec51ba8cf
commit
0e2556544e
|
@ -2,6 +2,11 @@ disabled_rules:
|
||||||
- line_length
|
- line_length
|
||||||
- trailing_whitespace
|
- trailing_whitespace
|
||||||
- todo
|
- todo
|
||||||
|
- cyclomatic_complexity
|
||||||
|
- file_length
|
||||||
|
- type_body_length
|
||||||
|
- function_body_length
|
||||||
|
- nesting
|
||||||
opt_in_rules:
|
opt_in_rules:
|
||||||
- empty_count
|
- empty_count
|
||||||
- empty_string
|
- empty_string
|
||||||
|
@ -14,14 +19,7 @@ opt_in_rules:
|
||||||
- toggle_bool
|
- toggle_bool
|
||||||
- unneeded_parentheses_in_closure_argument
|
- unneeded_parentheses_in_closure_argument
|
||||||
- unused_import
|
- unused_import
|
||||||
# - trailing_closure
|
- trailing_closure
|
||||||
file_length:
|
|
||||||
warning: 500
|
|
||||||
cyclomatic_complexity:
|
|
||||||
warning: 10
|
|
||||||
error: 25
|
|
||||||
function_body_length:
|
|
||||||
warning: 45
|
|
||||||
variable_name:
|
variable_name:
|
||||||
min_length:
|
min_length:
|
||||||
warning: 0
|
warning: 0
|
||||||
|
|
|
@ -35,7 +35,6 @@ extension TunnelConfiguration {
|
||||||
case multipleEntriesForKey(String)
|
case multipleEntriesForKey(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next function_body_length cyclomatic_complexity
|
|
||||||
convenience init(fromWgQuickConfig wgQuickConfig: String, called name: String? = nil) throws {
|
convenience init(fromWgQuickConfig wgQuickConfig: String, called name: String? = nil) throws {
|
||||||
var interfaceConfiguration: InterfaceConfiguration?
|
var interfaceConfiguration: InterfaceConfiguration?
|
||||||
var peerConfigurations = [PeerConfiguration]()
|
var peerConfigurations = [PeerConfiguration]()
|
||||||
|
@ -167,7 +166,6 @@ extension TunnelConfiguration {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next cyclomatic_complexity
|
|
||||||
private static func collate(interfaceAttributes attributes: [String: String]) throws -> InterfaceConfiguration {
|
private static func collate(interfaceAttributes attributes: [String: String]) throws -> InterfaceConfiguration {
|
||||||
guard let privateKeyString = attributes["privatekey"] else {
|
guard let privateKeyString = attributes["privatekey"] else {
|
||||||
throw ParseError.interfaceHasNoPrivateKey
|
throw ParseError.interfaceHasNoPrivateKey
|
||||||
|
@ -211,7 +209,6 @@ extension TunnelConfiguration {
|
||||||
return interface
|
return interface
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next cyclomatic_complexity
|
|
||||||
private static func collate(peerAttributes attributes: [String: String]) throws -> PeerConfiguration {
|
private static func collate(peerAttributes attributes: [String: String]) throws -> PeerConfiguration {
|
||||||
guard let publicKeyString = attributes["publickey"] else {
|
guard let publicKeyString = attributes["publickey"] else {
|
||||||
throw ParseError.peerHasNoPublicKey
|
throw ParseError.peerHasNoPublicKey
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
extension TunnelConfiguration {
|
extension TunnelConfiguration {
|
||||||
//swiftlint:disable:next function_body_length cyclomatic_complexity
|
|
||||||
convenience init(fromUapiConfig uapiConfig: String, basedOn base: TunnelConfiguration? = nil) throws {
|
convenience init(fromUapiConfig uapiConfig: String, basedOn base: TunnelConfiguration? = nil) throws {
|
||||||
var interfaceConfiguration: InterfaceConfiguration?
|
var interfaceConfiguration: InterfaceConfiguration?
|
||||||
var peerConfigurations = [PeerConfiguration]()
|
var peerConfigurations = [PeerConfiguration]()
|
||||||
|
@ -103,7 +102,6 @@ extension TunnelConfiguration {
|
||||||
return interface
|
return interface
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next cyclomatic_complexity
|
|
||||||
private static func collate(peerAttributes attributes: [String: String]) throws -> PeerConfiguration {
|
private static func collate(peerAttributes attributes: [String: String]) throws -> PeerConfiguration {
|
||||||
guard let publicKeyString = attributes["public_key"] else {
|
guard let publicKeyString = attributes["public_key"] else {
|
||||||
throw ParseError.peerHasNoPublicKey
|
throw ParseError.peerHasNoPublicKey
|
||||||
|
|
|
@ -446,7 +446,6 @@ class TunnelContainer: NSObject {
|
||||||
isActivateOnDemandEnabled = tunnelProvider.isOnDemandEnabled
|
isActivateOnDemandEnabled = tunnelProvider.isOnDemandEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next function_body_length
|
|
||||||
fileprivate func startActivation(recursionCount: UInt = 0, lastError: Error? = nil, activationDelegate: TunnelsManagerActivationDelegate?) {
|
fileprivate func startActivation(recursionCount: UInt = 0, lastError: Error? = nil, activationDelegate: TunnelsManagerActivationDelegate?) {
|
||||||
if recursionCount >= 8 {
|
if recursionCount >= 8 {
|
||||||
wg_log(.error, message: "startActivation: Failed after 8 attempts. Giving up with \(lastError!)")
|
wg_log(.error, message: "startActivation: Failed after 8 attempts. Giving up with \(lastError!)")
|
||||||
|
@ -532,6 +531,7 @@ extension NETunnelProviderManager {
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func setTunnelConfiguration(_ tunnelConfiguration: TunnelConfiguration) {
|
func setTunnelConfiguration(_ tunnelConfiguration: TunnelConfiguration) {
|
||||||
protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, previouslyFrom: protocolConfiguration)
|
protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, previouslyFrom: protocolConfiguration)
|
||||||
localizedDescription = tunnelConfiguration.name
|
localizedDescription = tunnelConfiguration.name
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
//swiftlint:disable:next type_body_length
|
|
||||||
class TunnelViewModel {
|
class TunnelViewModel {
|
||||||
|
|
||||||
enum InterfaceField: CaseIterable {
|
enum InterfaceField: CaseIterable {
|
||||||
|
@ -74,6 +73,7 @@ class TunnelViewModel {
|
||||||
case removed
|
case removed
|
||||||
case modified
|
case modified
|
||||||
}
|
}
|
||||||
|
|
||||||
var interfaceChanged: ([InterfaceField: FieldChange]) -> Void
|
var interfaceChanged: ([InterfaceField: FieldChange]) -> Void
|
||||||
var peerChangedAt: (Int, [PeerField: FieldChange]) -> Void
|
var peerChangedAt: (Int, [PeerField: FieldChange]) -> Void
|
||||||
var peersRemovedAt: ([Int]) -> Void
|
var peersRemovedAt: ([Int]) -> Void
|
||||||
|
@ -141,7 +141,6 @@ class TunnelViewModel {
|
||||||
return scratchpad
|
return scratchpad
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next cyclomatic_complexity function_body_length
|
|
||||||
func save() -> SaveResult<(String, InterfaceConfiguration)> {
|
func save() -> SaveResult<(String, InterfaceConfiguration)> {
|
||||||
if let config = validatedConfiguration, let name = validatedName {
|
if let config = validatedConfiguration, let name = validatedName {
|
||||||
return .saved((name, config))
|
return .saved((name, config))
|
||||||
|
@ -327,7 +326,6 @@ class TunnelViewModel {
|
||||||
return scratchpad
|
return scratchpad
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next cyclomatic_complexity
|
|
||||||
func save() -> SaveResult<PeerConfiguration> {
|
func save() -> SaveResult<PeerConfiguration> {
|
||||||
if let validatedConfiguration = validatedConfiguration {
|
if let validatedConfiguration = validatedConfiguration {
|
||||||
return .saved(validatedConfiguration)
|
return .saved(validatedConfiguration)
|
||||||
|
|
|
@ -147,7 +147,13 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||||
// Incorporates changes from tunnelConfiguation. Ignores any changes in peer ordering.
|
// Incorporates changes from tunnelConfiguation. Ignores any changes in peer ordering.
|
||||||
guard let tableView = self.tableView else { return }
|
guard let tableView = self.tableView else { return }
|
||||||
let sections = self.sections
|
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
|
let firstPeerSectionIndex = interfaceSectionIndex + 1
|
||||||
var interfaceFieldIsVisible = self.interfaceFieldIsVisible
|
var interfaceFieldIsVisible = self.interfaceFieldIsVisible
|
||||||
var peerFieldIsVisible = self.peerFieldIsVisible
|
var peerFieldIsVisible = self.peerFieldIsVisible
|
||||||
|
|
|
@ -302,6 +302,8 @@ extension TunnelEditTableViewController {
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
let removedSectionIndices = self.deletePeer(peer: peerData)
|
let removedSectionIndices = self.deletePeer(peer: peerData)
|
||||||
let shouldShowExcludePrivateIPs = (self.tunnelViewModel.peersData.count == 1 && self.tunnelViewModel.peersData[0].shouldAllowExcludePrivateIPsControl)
|
let shouldShowExcludePrivateIPs = (self.tunnelViewModel.peersData.count == 1 && self.tunnelViewModel.peersData[0].shouldAllowExcludePrivateIPsControl)
|
||||||
|
|
||||||
|
//swiftlint:disable:next trailing_closure
|
||||||
tableView.performBatchUpdates({
|
tableView.performBatchUpdates({
|
||||||
self.tableView.deleteSections(removedSectionIndices, with: .fade)
|
self.tableView.deleteSections(removedSectionIndices, with: .fade)
|
||||||
if shouldShowExcludePrivateIPs {
|
if shouldShowExcludePrivateIPs {
|
||||||
|
@ -309,7 +311,6 @@ extension TunnelEditTableViewController {
|
||||||
let rowIndexPath = IndexPath(row: row, section: self.interfaceFieldsBySection.count /* First peer section */)
|
let rowIndexPath = IndexPath(row: row, section: self.interfaceFieldsBySection.count /* First peer section */)
|
||||||
self.tableView.insertRows(at: [rowIndexPath], with: .fade)
|
self.tableView.insertRows(at: [rowIndexPath], with: .fade)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -359,9 +360,9 @@ extension TunnelEditTableViewController {
|
||||||
cell.value = peerData[field]
|
cell.value = peerData[field]
|
||||||
|
|
||||||
if field == .allowedIPs {
|
if field == .allowedIPs {
|
||||||
let firstInterfaceSection = sections.firstIndex(where: { $0 == .interface })!
|
let firstInterfaceSection = sections.firstIndex { $0 == .interface }!
|
||||||
let interfaceSubSection = interfaceFieldsBySection.firstIndex(where: { $0.contains(.dns) })!
|
let interfaceSubSection = interfaceFieldsBySection.firstIndex { $0.contains(.dns) }!
|
||||||
let dnsRow = interfaceFieldsBySection[interfaceSubSection].firstIndex(where: { $0 == .dns })!
|
let dnsRow = interfaceFieldsBySection[interfaceSubSection].firstIndex { $0 == .dns }!
|
||||||
|
|
||||||
cell.onValueBeingEdited = { [weak self, weak peerData] value in
|
cell.onValueBeingEdited = { [weak self, weak peerData] value in
|
||||||
guard let self = self, let peerData = peerData else { return }
|
guard let self = self, let peerData = peerData else { return }
|
||||||
|
@ -419,7 +420,7 @@ extension TunnelEditTableViewController {
|
||||||
self.activateOnDemandSetting.isActivateOnDemandEnabled = isOn
|
self.activateOnDemandSetting.isActivateOnDemandEnabled = isOn
|
||||||
self.loadSections()
|
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) }
|
let indexPaths = (1 ..< 4).map { IndexPath(row: $0, section: section) }
|
||||||
if isOn {
|
if isOn {
|
||||||
if self.activateOnDemandSetting.activateOnDemandOption == .none {
|
if self.activateOnDemandSetting.activateOnDemandOption == .none {
|
||||||
|
|
|
@ -57,7 +57,6 @@ class StatusMenu: NSMenu {
|
||||||
self.networksMenuItem = networksMenuItem
|
self.networksMenuItem = networksMenuItem
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next cyclomatic_complexity
|
|
||||||
func updateStatusMenuItems(with tunnel: TunnelContainer?) {
|
func updateStatusMenuItems(with tunnel: TunnelContainer?) {
|
||||||
guard let statusMenuItem = statusMenuItem, let networksMenuItem = networksMenuItem else { return }
|
guard let statusMenuItem = statusMenuItem, let networksMenuItem = networksMenuItem else { return }
|
||||||
guard let tunnel = tunnel else {
|
guard let tunnel = tunnel else {
|
||||||
|
|
|
@ -17,7 +17,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
networkMonitor?.cancel()
|
networkMonitor?.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next function_body_length
|
|
||||||
override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
|
override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
|
||||||
let activationAttemptId = options?["activationAttemptId"] as? String
|
let activationAttemptId = options?["activationAttemptId"] as? String
|
||||||
let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId)
|
let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId)
|
||||||
|
|
Loading…
Reference in New Issue