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 swiftlint warnings in xcode #5100

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4077,7 +4077,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
105 changes: 62 additions & 43 deletions ios/MullvadVPN/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
configureLogging()

logger = Logger(label: "AppDelegate")

let containerURL = ApplicationConfiguration.containerURL

configureLogging()

addressCache = REST.AddressCache(canWriteToCache: true, cacheDirectory: containerURL)
addressCache.loadFromFile()

proxyFactory = REST.ProxyFactory.makeProxyFactory(
transportProvider: REST.AnyTransportProvider { [weak self] in
return self?.transportMonitor.makeTransport()
},
addressCache: addressCache
)

apiProxy = proxyFactory.createAPIProxy()
accountsProxy = proxyFactory.createAccountsProxy()
devicesProxy = proxyFactory.createDevicesProxy()
setUpProxies(containerURL: containerURL)

let relayCache = RelayCache(cacheDirectory: containerURL)
relayCacheTracker = RelayCacheTracker(relayCache: relayCache, application: application, apiProxy: apiProxy)
Expand All @@ -93,6 +82,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
relayConstraintsObserver = TunnelBlockObserver(didUpdateTunnelSettings: { _, settings in
constraintsUpdater.onNewConstraints?(settings.relayConstraints)
})
tunnelManager.addObserver(relayConstraintsObserver)

storePaymentManager = StorePaymentManager(
application: application,
Expand All @@ -110,15 +100,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
shadowsocksCache: shadowsocksCache,
constraintsUpdater: constraintsUpdater
)
setUpTransportMonitor(transportProvider: transportProvider)
setUpSimulatorHost(transportProvider: transportProvider)

tunnelManager.addObserver(relayConstraintsObserver)
registerBackgroundTasks()
setupPaymentHandler()
setupNotifications()
addApplicationNotifications(application: application)

startInitialization(application: application)

return true
}

private func setUpProxies(containerURL: URL) {
proxyFactory = REST.ProxyFactory.makeProxyFactory(
transportProvider: REST.AnyTransportProvider { [weak self] in
return self?.transportMonitor.makeTransport()
},
addressCache: addressCache
)

apiProxy = proxyFactory.createAPIProxy()
accountsProxy = proxyFactory.createAccountsProxy()
devicesProxy = proxyFactory.createDevicesProxy()
}

private func setUpTransportMonitor(transportProvider: TransportProvider) {
transportMonitor = TransportMonitor(
tunnelManager: tunnelManager,
tunnelStore: tunnelStore,
transportProvider: transportProvider
)
}

private func setUpSimulatorHost(transportProvider: TransportProvider) {
#if targetEnvironment(simulator)
// Configure mock tunnel provider on simulator
simulatorTunnelProviderHost = SimulatorTunnelProviderHost(
Expand All @@ -127,15 +143,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
)
SimulatorTunnelProvider.shared.delegate = simulatorTunnelProviderHost
#endif

registerBackgroundTasks()
setupPaymentHandler()
setupNotifications()
addApplicationNotifications(application: application)

startInitialization(application: application)

return true
}

// MARK: - UISceneSession lifecycle
Expand Down Expand Up @@ -318,6 +325,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
loggerBuilder.addOSLogOutput(subsystem: ApplicationTarget.mainApp.bundleIdentifier)
#endif
loggerBuilder.install()

logger = Logger(label: "AppDelegate")
}

private func addApplicationNotifications(application: UIApplication) {
Expand Down Expand Up @@ -360,8 +369,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

private func startInitialization(application: UIApplication) {
let wipeSettingsOperation = getWipeSettingsOperation()
let loadTunnelStoreOperation = getLoadTunnelStoreOperation()
let migrateSettingsOperation = getMigrateSettingsOperation(application: application)
let initTunnelManagerOperation = getInitTunnelManagerOperation()

migrateSettingsOperation.addDependencies([wipeSettingsOperation, loadTunnelStoreOperation])
initTunnelManagerOperation.addDependency(migrateSettingsOperation)

operationQueue.addOperations(
[
wipeSettingsOperation,
loadTunnelStoreOperation,
migrateSettingsOperation,
initTunnelManagerOperation,
],
waitUntilFinished: false
)
}

let loadTunnelStoreOperation = AsyncBlockOperation(dispatchQueue: .main) { [self] finish in
private func getLoadTunnelStoreOperation() -> AsyncBlockOperation {
AsyncBlockOperation(dispatchQueue: .main) { [self] finish in
tunnelStore.loadPersistentTunnels { [self] error in
if let error {
logger.error(
Expand All @@ -372,8 +399,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
finish(nil)
}
}
}

let migrateSettingsOperation = AsyncBlockOperation(dispatchQueue: .main) { [self] finish in
private func getMigrateSettingsOperation(application: UIApplication) -> AsyncBlockOperation {
AsyncBlockOperation(dispatchQueue: .main) { [self] finish in
migrationManager
.migrateSettings(store: SettingsManager.store, proxyFactory: proxyFactory) { [self] migrationResult in
switch migrationResult {
Expand All @@ -387,8 +416,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
finish(nil)

case let .failure(error):
let migrationUIHandler = application.connectedScenes.first { $0 is SettingsMigrationUIHandler }
as? SettingsMigrationUIHandler
let migrationUIHandler = application.connectedScenes
.first { $0 is SettingsMigrationUIHandler } as? SettingsMigrationUIHandler

if let migrationUIHandler {
migrationUIHandler.showMigrationError(error) {
Expand All @@ -400,12 +429,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
}
}
}

migrateSettingsOperation.addDependencies([wipeSettingsOperation, loadTunnelStoreOperation])

let initTunnelManagerOperation = AsyncBlockOperation(dispatchQueue: .main) { finish in
private func getInitTunnelManagerOperation() -> AsyncBlockOperation {
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 All @@ -418,17 +446,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
finish(nil)
}
}
initTunnelManagerOperation.addDependency(migrateSettingsOperation)

operationQueue.addOperations(
[
wipeSettingsOperation,
loadTunnelStoreOperation,
migrateSettingsOperation,
initTunnelManagerOperation,
],
waitUntilFinished: false
)
}

/// Returns an operation that acts on two conditions:
Expand Down Expand Up @@ -492,4 +509,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
) {
completionHandler([.list, .banner, .sound])
}

// swiftlint:disable:next file_length
}
6 changes: 4 additions & 2 deletions 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 Expand Up @@ -112,7 +114,7 @@ class AutomaticKeyboardResponder {
\.frame,
options: [.new],
changeHandler: { [weak self] _, _ in
guard let self,
guard let self = self,
let keyboardFrameValue = lastKeyboardRect else { return }

adjustContentInsets(convertedKeyboardFrameEnd: keyboardFrameValue)
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
Loading
Loading