From a89ad959016c394c3b30b30598bf9ebff2ad1911 Mon Sep 17 00:00:00 2001 From: Eric Kuck Date: Thu, 20 Dec 2018 11:22:37 -0600 Subject: [PATCH] Enabled more swiftlint rules Signed-off-by: Eric Kuck --- WireGuard/.swiftlint.yml | 10 ++++++++++ WireGuard/Shared/Logging/Logger.swift | 1 + .../WireGuard/ConfigFile/WgQuickConfigFileParser.swift | 2 +- WireGuard/WireGuard/Tunnel/TunnelErrors.swift | 1 + WireGuard/WireGuard/UI/TunnelViewModel.swift | 2 +- WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift | 2 +- .../UI/iOS/ViewController/QRScanViewController.swift | 10 +++------- .../TunnelsListTableViewController.swift | 2 +- WireGuard/WireGuard/WireGuardAppError.swift | 1 + WireGuard/WireGuardNetworkExtension/DNSResolver.swift | 2 +- .../PacketTunnelSettingsGenerator.swift | 2 +- 11 files changed, 22 insertions(+), 13 deletions(-) diff --git a/WireGuard/.swiftlint.yml b/WireGuard/.swiftlint.yml index f0a450f..93c7ab3 100644 --- a/WireGuard/.swiftlint.yml +++ b/WireGuard/.swiftlint.yml @@ -3,7 +3,17 @@ disabled_rules: - trailing_whitespace - todo opt_in_rules: + - empty_count + - empty_string + - implicitly_unwrapped_optional + - legacy_random + - let_var_whitespace + - literal_expression_end_indentation + - override_in_extension + - redundant_type_annotation + - toggle_bool - unneeded_parentheses_in_closure_argument + - unused_import # - trailing_closure file_length: warning: 500 diff --git a/WireGuard/Shared/Logging/Logger.swift b/WireGuard/Shared/Logging/Logger.swift index 10b90d8..026ec09 100644 --- a/WireGuard/Shared/Logging/Logger.swift +++ b/WireGuard/Shared/Logging/Logger.swift @@ -8,6 +8,7 @@ public class Logger { enum LoggerError: Error { case openFailure } + static var global: Logger? var log: OpaquePointer diff --git a/WireGuard/WireGuard/ConfigFile/WgQuickConfigFileParser.swift b/WireGuard/WireGuard/ConfigFile/WgQuickConfigFileParser.swift index b3c0acd..f4c52c2 100644 --- a/WireGuard/WireGuard/ConfigFile/WgQuickConfigFileParser.swift +++ b/WireGuard/WireGuard/ConfigFile/WgQuickConfigFileParser.swift @@ -42,7 +42,7 @@ class WgQuickConfigFileParser { trimmedLine = trimmedLine.trimmingCharacters(in: .whitespaces) - guard trimmedLine.count > 0 else { continue } + guard !trimmedLine.isEmpty else { continue } let lowercasedLine = line.lowercased() if let equalsIndex = line.firstIndex(of: "=") { diff --git a/WireGuard/WireGuard/Tunnel/TunnelErrors.swift b/WireGuard/WireGuard/Tunnel/TunnelErrors.swift index 16c8072..45c20f6 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelErrors.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelErrors.swift @@ -52,6 +52,7 @@ enum TunnelsManagerActivationAttemptError: WireGuardAppError { enum TunnelsManagerActivationError: WireGuardAppError { case activationFailed case activationFailedWithExtensionError(title: String, message: String) + var alertText: AlertText { switch self { case .activationFailed: diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift index 1a88da2..71cb18e 100644 --- a/WireGuard/WireGuard/UI/TunnelViewModel.swift +++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift @@ -361,7 +361,7 @@ class TunnelViewModel { var peersData: [PeerData] init(tunnelConfiguration: TunnelConfiguration?) { - let interfaceData: InterfaceData = InterfaceData() + let interfaceData = InterfaceData() var peersData = [PeerData]() if let tunnelConfiguration = tunnelConfiguration { interfaceData.validatedConfiguration = tunnelConfiguration.interface diff --git a/WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift b/WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift index 4702993..aff17ee 100644 --- a/WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift +++ b/WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift @@ -33,7 +33,7 @@ class ButtonCell: UITableViewCell { button.topAnchor.constraint(equalTo: contentView.layoutMarginsGuide.topAnchor), contentView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: button.bottomAnchor), button.centerXAnchor.constraint(equalTo: contentView.centerXAnchor) - ]) + ]) button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) } diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift index 1e231ec..e4b6287 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift @@ -76,15 +76,11 @@ class QRScanViewController: UIViewController { super.viewDidLayoutSubviews() if let connection = previewLayer?.connection { - - let currentDevice: UIDevice = UIDevice.current - - let orientation: UIDeviceOrientation = currentDevice.orientation - - let previewLayerConnection: AVCaptureConnection = connection + let currentDevice = UIDevice.current + let orientation = currentDevice.orientation + let previewLayerConnection = connection if previewLayerConnection.isVideoOrientationSupported { - switch orientation { case .portrait: previewLayerConnection.videoOrientation = .portrait diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift index c07657f..9dea8b0 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift @@ -127,7 +127,7 @@ class TunnelsListTableViewController: UIViewController { present(alert, animated: true, completion: nil) } - @objc func settingsButtonTapped(sender: UIBarButtonItem!) { + @objc func settingsButtonTapped(sender: UIBarButtonItem) { guard tunnelsManager != nil else { return } let settingsVC = SettingsTableViewController(tunnelsManager: tunnelsManager) diff --git a/WireGuard/WireGuard/WireGuardAppError.swift b/WireGuard/WireGuard/WireGuardAppError.swift index aa2f909..8b725d7 100644 --- a/WireGuard/WireGuard/WireGuardAppError.swift +++ b/WireGuard/WireGuard/WireGuardAppError.swift @@ -3,5 +3,6 @@ protocol WireGuardAppError: Error { typealias AlertText = (title: String, message: String) + var alertText: AlertText { get } } diff --git a/WireGuard/WireGuardNetworkExtension/DNSResolver.swift b/WireGuard/WireGuardNetworkExtension/DNSResolver.swift index a30b512..32cbf78 100644 --- a/WireGuard/WireGuardNetworkExtension/DNSResolver.swift +++ b/WireGuard/WireGuardNetworkExtension/DNSResolver.swift @@ -21,7 +21,7 @@ class DNSResolver { } static func resolveSync(endpoints: [Endpoint?]) throws -> [Endpoint?] { - let dispatchGroup: DispatchGroup = DispatchGroup() + let dispatchGroup = DispatchGroup() if isAllEndpointsAlreadyResolved(endpoints: endpoints) { return endpoints diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift index 3aab8a4..7ee0acc 100644 --- a/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift +++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift @@ -36,7 +36,7 @@ class PacketTunnelSettingsGenerator { if let listenPort = tunnelConfiguration.interface.listenPort { wgSettings.append("listen_port=\(listenPort)\n") } - if tunnelConfiguration.peers.count > 0 { + if !tunnelConfiguration.peers.isEmpty { wgSettings.append("replace_peers=true\n") } assert(tunnelConfiguration.peers.count == resolvedEndpoints.count)