Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix or report all current small Swiftlint warnings in xcode #5103

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ios/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ line_length:
type_name:
min_length: 4
max_length:
error: 50
warning: 50
error: 60
excluded: iPhone # excluded via string
allowed_symbols: ["_"] # these are allowed in type names
identifier_name:
Expand All @@ -47,3 +48,7 @@ identifier_name:
- URL
- GlobalAPIKey
reporter: "xcode"
nesting:
type_level:
warning: 2
error: 4
7 changes: 5 additions & 2 deletions ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@
7A21DACF2A30AA3700A787A9 /* UITextField+Appearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A21DACE2A30AA3700A787A9 /* UITextField+Appearance.swift */; };
7A307AD92A8CD8DA0017618B /* Duration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A307AD82A8CD8DA0017618B /* Duration.swift */; };
7A307ADB2A8F56DF0017618B /* Duration+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A307ADA2A8F56DF0017618B /* Duration+Extensions.swift */; };
7A3353972AAA0F8600F0A71C /* OperationBlockObserverSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3353962AAA0F8600F0A71C /* OperationBlockObserverSupport.swift */; };
7A42DEC92A05164100B209BE /* SettingsInputCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A42DEC82A05164100B209BE /* SettingsInputCell.swift */; };
7A42DECD2A09064C00B209BE /* SelectableSettingsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A42DECC2A09064C00B209BE /* SelectableSettingsCell.swift */; };
7A7AD28D29DC677800480EF1 /* FirstTimeLaunch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A7AD28C29DC677800480EF1 /* FirstTimeLaunch.swift */; };
Expand Down Expand Up @@ -1311,6 +1312,7 @@
7A21DACE2A30AA3700A787A9 /* UITextField+Appearance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITextField+Appearance.swift"; sourceTree = "<group>"; };
7A307AD82A8CD8DA0017618B /* Duration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Duration.swift; sourceTree = "<group>"; };
7A307ADA2A8F56DF0017618B /* Duration+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Duration+Extensions.swift"; sourceTree = "<group>"; };
7A3353962AAA0F8600F0A71C /* OperationBlockObserverSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationBlockObserverSupport.swift; sourceTree = "<group>"; };
7A42DEC82A05164100B209BE /* SettingsInputCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsInputCell.swift; sourceTree = "<group>"; };
7A42DECC2A09064C00B209BE /* SelectableSettingsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectableSettingsCell.swift; sourceTree = "<group>"; };
7A7AD28C29DC677800480EF1 /* FirstTimeLaunch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstTimeLaunch.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2456,8 +2458,9 @@
581813A628E09DF2002817DE /* MutuallyExclusive.swift */,
581813A028E09DBB002817DE /* NoCancelledDependenciesCondition.swift */,
581813A228E09DCD002817DE /* NoFailedDependenciesCondition.swift */,
5840BE34279EDB16002836BA /* OperationError.swift */,
7A3353962AAA0F8600F0A71C /* OperationBlockObserverSupport.swift */,
589D28772846250500F9A7B3 /* OperationCondition.swift */,
5840BE34279EDB16002836BA /* OperationError.swift */,
589D28792846250500F9A7B3 /* OperationObserver.swift */,
58059DDD28468158002B1049 /* OutputOperation.swift */,
5842102D282D3FC200F24E46 /* ResultBlockOperation.swift */,
Expand Down Expand Up @@ -4010,6 +4013,7 @@
58D223BB294C8A630029F5F8 /* NoCancelledDependenciesCondition.swift in Sources */,
58D223B3294C8A630029F5F8 /* OperationObserver.swift in Sources */,
58D223B7294C8A630029F5F8 /* MutuallyExclusive.swift in Sources */,
7A3353972AAA0F8600F0A71C /* OperationBlockObserverSupport.swift in Sources */,
58D223B2294C8A630029F5F8 /* OperationError.swift in Sources */,
58D223AF294C8A630029F5F8 /* NoFailedDependenciesCondition.swift in Sources */,
58D223B9294C8A630029F5F8 /* AsyncOperationQueue.swift in Sources */,
Expand Down Expand Up @@ -4077,7 +4081,6 @@
58B465702A98C53300467203 /* RequestExecutorTests.swift in Sources */,
A917352129FAAA5200D5DCFD /* TransportStrategyTests.swift in Sources */,
58FBFBE9291622580020E046 /* ExponentialBackoffTests.swift in Sources */,
58FBFBF1291630700020E046 /* DurationTests.swift in Sources */,
58BDEB9D2A98F69E00F578F2 /* MemoryCache.swift in Sources */,
58BDEB9B2A98F58600F578F2 /* TimeServerProxy.swift in Sources */,
58BDEB992A98F4ED00F578F2 /* AnyTransport.swift in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion ios/MullvadVPN/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

let initTunnelManagerOperation = AsyncBlockOperation(dispatchQueue: .main) { finish in
self.tunnelManager.loadConfiguration { error in
// TODO: avoid throwing fatal error and show the problem report UI instead.
if let error {
fatalError(error.localizedDescription)
}
Expand Down Expand Up @@ -492,4 +491,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
) {
completionHandler([.list, .banner, .sound])
}

// swiftlint:disable:next file_length
}
4 changes: 3 additions & 1 deletion ios/MullvadVPN/Classes/AutomaticKeyboardResponder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class AutomaticKeyboardResponder {
init<T: UIView>(targetView: T, handler: @escaping (T, CGFloat) -> Void) {
self.targetView = targetView
self.handler = { view, adjustment in
handler(view as! T, adjustment)
if let view = view as? T {
handler(view, adjustment)
}
}

NotificationCenter.default.addObserver(
Expand Down
1 change: 1 addition & 0 deletions ios/MullvadVPN/Classes/ConsolidatedApplicationLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class ConsolidatedApplicationLog: TextOutputStreamable {

private static func redactAccountNumber(string: String) -> String {
redact(
// swiftlint:disable:next force_try
regularExpression: try! NSRegularExpression(pattern: #"\d{16}"#),
string: string,
replacementString: kRedactedAccountPlaceholder
Expand Down
13 changes: 3 additions & 10 deletions ios/MullvadVPN/Classes/InputTextFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class InputTextFormatter: NSObject, UITextFieldDelegate, UITextPasteDelegate {

// Since removing separator alone makes no sense, this computation extends the string range
// to include the digit preceding a separator.
if replacementString.isEmpty, emptySelection,
!formattedString.isEmpty {
if replacementString.isEmpty, emptySelection, !formattedString.isEmpty {
let precedingDigitIndex = formattedString
.prefix(through: stringRange.lowerBound)
.lastIndex { isAllowed($0) } ?? formattedString.startIndex
Expand All @@ -85,19 +84,13 @@ class InputTextFormatter: NSObject, UITextFieldDelegate, UITextPasteDelegate {
}

// Replace the given range within a formatted string
let newString = formattedString.replacingCharacters(
in: stringRange,
with: replacementString
)
let newString = formattedString.replacingCharacters(in: stringRange, with: replacementString)

// Number of digits within a string
var numDigits = 0

// Insertion location within the input string
let insertionLocation = formattedString.distance(
from: formattedString.startIndex,
to: stringRange.lowerBound
)
let insertionLocation = formattedString.distance(from: formattedString.startIndex, to: stringRange.lowerBound)

// Original caret location based on insertion location + number of characters added
let originalCaretPosition = insertionLocation + replacementString.count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,4 +840,6 @@ extension RootContainerViewController {
presentationContainerAccountButton?.isHidden = !configuration.showsAccountButton
headerBarView.update(configuration: configuration)
}

// swiftlint:disable:next file_length
}
2 changes: 2 additions & 0 deletions ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -979,4 +979,6 @@ fileprivate extension AppPreferencesDataSource {
mutating func markChangeLogSeen() {
self.lastSeenChangeLogVersion = Bundle.main.shortVersion
}

// swiftlint:disable:next file_length
}
2 changes: 1 addition & 1 deletion ios/MullvadVPN/Coordinators/WelcomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extension WelcomeCoordinator: WelcomeViewControllerDelegate {
"""
let alertController = CustomAlertViewController(
message: NSLocalizedString(
"WELCOME_DEVICE_CONCEPET_TEXT_DIALOG",
"WELCOME_DEVICE_CONCEPT_TEXT_DIALOG",
tableName: "Welcome",
value: message,
comment: ""
Expand Down
2 changes: 2 additions & 0 deletions ios/MullvadVPN/Extensions/NSRegularExpression+IPAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extension NSRegularExpression {
return try! NSRegularExpression(pattern: pattern, options: [.allowCommentsAndWhitespace])
}

// swiftlint:disable line_length
static var ipv6RegularExpression: NSRegularExpression {
// Regular expression obtained from:
// https://stackoverflow.com/a/17871737
Expand Down Expand Up @@ -49,4 +50,5 @@ extension NSRegularExpression {
// swiftlint:disable:next force_try
return try! NSRegularExpression(pattern: pattern, options: [.allowCommentsAndWhitespace])
}
// swiftlint:enable line_length
}
5 changes: 4 additions & 1 deletion ios/MullvadVPN/Notifications/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ final class NotificationManager: NotificationProviderDelegate {
}
}

// Invalidate in-app notification
invalidateInAppNotification(notificationProvider)
}

private func invalidateInAppNotification(_ notificationProvider: NotificationProvider) {
if let notificationProvider = notificationProvider as? InAppNotificationProvider {
var newNotificationDescriptors = inAppNotificationDescriptors

Expand Down
1 change: 1 addition & 0 deletions ios/MullvadVPN/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, SettingsMigrationUIHand
private var tunnelObserver: TunnelObserver?

private var appDelegate: AppDelegate {
// swiftlint:disable:next force_cast
UIApplication.shared.delegate as! AppDelegate
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,5 @@ final class SimulatorTunnelProviderManager: NSObject, VPNTunnelProviderManagerPr
}
}

// swiftlint:disable:next file_length
#endif
16 changes: 3 additions & 13 deletions ios/MullvadVPN/TunnelManager/SetAccountOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,7 @@ class SetAccountOperation: ResultOperation<StoredAccountData?> {
let result = result.inspectError { error in
guard !error.isOperationCancellationError else { return }

logger.error(
error: error,
message: "Failed to create new account."
)
logger.error(error: error, message: "Failed to create new account.")
}.map { newAccountData -> StoredAccountData in
logger.debug("Created new account.")

Expand Down Expand Up @@ -322,10 +319,7 @@ class SetAccountOperation: ResultOperation<StoredAccountData?> {
dispatchQueue.async { [self] in
// Ignore error but log it.
if let error {
logger.error(
error: error,
message: "Failed to remove VPN configuration."
)
logger.error(error: error, message: "Failed to remove VPN configuration.")
}

interactor.setTunnel(nil, shouldRefreshTunnelState: false)
Expand All @@ -338,11 +332,7 @@ class SetAccountOperation: ResultOperation<StoredAccountData?> {
/// Create new private key and create new device via API.
private func createDevice(accountNumber: String, completion: @escaping (Result<NewDevice, Error>) -> Void) {
let privateKey = PrivateKey()

let request = REST.CreateDeviceRequest(
publicKey: privateKey.publicKey,
hijackDNS: false
)
let request = REST.CreateDeviceRequest(publicKey: privateKey.publicKey, hijackDNS: false)

logger.debug("Create device...")

Expand Down
4 changes: 2 additions & 2 deletions ios/MullvadVPN/TunnelManager/Tunnel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ final class Tunnel: Equatable {
}

func sendProviderMessage(_ messageData: Data, responseHandler: ((Data?) -> Void)?) throws {
let session = tunnelProvider.connection as! VPNTunnelProviderSessionProtocol
let session = tunnelProvider.connection as? VPNTunnelProviderSessionProtocol

try session.sendProviderMessage(messageData, responseHandler: responseHandler)
try session?.sendProviderMessage(messageData, responseHandler: responseHandler)
}

func setConfiguration(_ configuration: TunnelConfiguration) {
Expand Down
1 change: 0 additions & 1 deletion ios/MullvadVPN/TunnelManager/TunnelManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@ final class TunnelManager: StorePaymentObserver {
}

case .invalid:
// TODO: handle invalid account in some way?
break
}
}
Expand Down
23 changes: 14 additions & 9 deletions ios/MullvadVPN/UI appearance/UIMetrics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ enum UIMetrics {
static let textFieldContentInsets = UIEdgeInsets(top: 8, left: 24, bottom: 8, right: 24)
static let textFieldNonEditingContentInsetLeft: CGFloat = 40
}

/// Group of constants related to in-app notifications banner.
enum InAppBannerNotification {
/// Layout margins for contents presented within the banner.
static let layoutMargins = NSDirectionalEdgeInsets(top: 16, leading: 24, bottom: 16, trailing: 24)

/// Size of little round severity indicator.
static let indicatorSize = CGSize(width: 12, height: 12)
}

enum DisconnectSplitButton {
static let secondaryButtonPhone = CGSize(width: 42, height: 42)
static let secondaryButtonPad = CGSize(width: 52, height: 52)
}
}

extension UIMetrics {
Expand Down Expand Up @@ -83,15 +97,6 @@ extension UIMetrics {
/// Common cell indentation width
static let cellIndentationWidth: CGFloat = 16

/// Group of constants related to in-app notifications banner.
enum InAppBannerNotification {
/// Layout margins for contents presented within the banner.
static let layoutMargins = NSDirectionalEdgeInsets(top: 16, leading: 24, bottom: 16, trailing: 24)

/// Size of little round severity indicator.
static let indicatorSize = CGSize(width: 12, height: 12)
}

/// Spacing used in stack views of buttons
static let interButtonSpacing: CGFloat = 16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,6 @@ private class AccountInputBorderLayer: CAShapeLayer {
}
return super.defaultAction(forKey: event)
}

// swiftlint:disable:next file_length
}
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,6 @@ private extension LoginState {
return .hidden
}
}

// swiftlint:disable:next file_length
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ class OutOfTimeViewController: UIViewController, RootContainment {
NSLocalizedString(
"OUT_OF_TIME_BODY_CONNECTED",
tableName: "OutOfTime",
value: "You have no more VPN time left on this account. To add more, you will need to disconnect and access the Internet with an unsecure connection.",
value: """
You have no more VPN time left on this account. To add more, you will need to \
disconnect and access the Internet with an unsecure connection.
""",
comment: ""
)
)
Expand All @@ -165,7 +168,10 @@ class OutOfTimeViewController: UIViewController, RootContainment {
NSLocalizedString(
"OUT_OF_TIME_BODY_DISCONNECTED",
tableName: "OutOfTime",
value: "You have no more VPN time left on this account. Either buy credit on our website or make an in-app purchase via the **Add 30 days time** button below.",
value: """
You have no more VPN time left on this account. Either buy credit on our website \
or make an in-app purchase via the **Add 30 days time** button below.
""",
comment: ""
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class PreferencesViewController: UITableViewController, PreferencesDataSourceDel
interactor.setDNSSettings(dnsSettings)
}

// swiftlint:disable:next function_body_length
func preferencesDataSource(
_ dataSource: PreferencesDataSource,
showInfo item: PreferencesDataSource.InfoButtonItem?
Expand All @@ -128,15 +129,22 @@ class PreferencesViewController: UITableViewController, PreferencesDataSourceDel
message = NSLocalizedString(
"PREFERENCES_CONTENT_BLOCKERS_GENERAL",
tableName: "ContentBlockers",
value: "When this feature is enabled it stops the device from contacting certain domains or websites known for distributing ads, malware, trackers and more. This might cause issues on certain websites, services, and programs.",
value: """
When this feature is enabled it stops the device from contacting certain \
domains or websites known for distributing ads, malware, trackers and more. \
This might cause issues on certain websites, services, and programs.
""",
comment: ""
)

case .blockMalware:
message = NSLocalizedString(
"PREFERENCES_CONTENT_BLOCKERS_MALWARE",
tableName: "ContentBlockers",
value: "Warning: The malware blocker is not an anti-virus and should not be treated as such, this is just an extra layer of protection.",
value: """
Warning: The malware blocker is not an anti-virus and should not \
be treated as such, this is just an extra layer of protection.
""",
comment: ""
)

Expand All @@ -163,12 +171,15 @@ class PreferencesViewController: UITableViewController, PreferencesDataSourceDel
)

#if DEBUG

case .wireGuardObfuscation:
message = NSLocalizedString(
"PREFERENCES_WIRE_GUARD_OBFUSCATION_GENERAL",
tableName: "WireGuardObfuscation",
value: "Obfuscation hides the WireGuard traffic inside another protocol. It can be used to help circumvent censorship and other types of filtering, where a plain WireGuard connect would be blocked.",
value: """
Obfuscation hides the WireGuard traffic inside another protocol. \
It can be used to help circumvent censorship and other types of filtering, \
where a plain WireGuard connect would be blocked.
""",
comment: ""
)

Expand All @@ -180,6 +191,7 @@ class PreferencesViewController: UITableViewController, PreferencesDataSourceDel
comment: ""
)
#endif

default:
assertionFailure("No matching InfoButtonItem")
}
Expand Down
Loading
Loading