Skip to content

Commit eb9f072

Browse files
committed
add swiftlint and code rules refactoring
1 parent c52cda4 commit eb9f072

File tree

331 files changed

+1084
-1404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+1084
-1404
lines changed

.swiftlint.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
warning_threshold: 200
2+
3+
excluded:
4+
- Pods
5+
6+
disabled_rules:
7+
- variable_name
8+
- cyclomatic_complexity
9+
- large_tuple
10+
- trailing_whitespace
11+
- force_try
12+
- force_cast
13+
- function_body_length
14+
- line_length
15+
- type_body_length
16+
- multiple_closures_with_trailing_closure
17+
- redundant_string_enum_value
18+
- inert_defer
19+
- nesting
20+
- type_name
21+
- file_length
22+
23+
line_length:
24+
warning: 250
25+
error: 500
26+
27+
function_parameter_count:
28+
warning: 8
29+
error: 15
30+
31+
file_length:
32+
warning: 500
33+
34+
type_body_length:
35+
warning: 400
36+
error: 450

Commun.xcodeproj/project.pbxproj

+27-8
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
57FB179D224BFBD700563BF7 /* PillPageControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57FB179A224BFBD700563BF7 /* PillPageControl.swift */; };
164164
7472E4613CDA904305E42A4F /* Pods_Commun.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F0772CC6D820AD11B1FF48A /* Pods_Commun.framework */; };
165165
AC0F9C2F237C307300A5002C /* CyberSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AC759B97237C15C20069D169 /* CyberSwift.framework */; };
166-
AC0F9C30237C307300A5002C /* CyberSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = AC759B97237C15C20069D169 /* CyberSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
166+
AC0F9C30237C307300A5002C /* CyberSwift.framework in CyberSwift */ = {isa = PBXBuildFile; fileRef = AC759B97237C15C20069D169 /* CyberSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
167167
AC3386A12371D1B6009DB3BB /* EmbedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC3386A02371D1B6009DB3BB /* EmbedView.swift */; };
168168
AC3386A62371DDEA009DB3BB /* EmbedView.xib in Resources */ = {isa = PBXBuildFile; fileRef = AC3386A52371DDEA009DB3BB /* EmbedView.xib */; };
169169
AC5D7D8B2385A1C400EEC5ED /* Formatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC5D7D8A2385A1C400EEC5ED /* Formatter.swift */; };
@@ -429,15 +429,15 @@
429429
/* End PBXContainerItemProxy section */
430430

431431
/* Begin PBXCopyFilesBuildPhase section */
432-
AC0F9C31237C307300A5002C /* Embed Frameworks */ = {
432+
AC0F9C31237C307300A5002C /* CyberSwift */ = {
433433
isa = PBXCopyFilesBuildPhase;
434434
buildActionMask = 2147483647;
435435
dstPath = "";
436436
dstSubfolderSpec = 10;
437437
files = (
438-
AC0F9C30237C307300A5002C /* CyberSwift.framework in Embed Frameworks */,
438+
AC0F9C30237C307300A5002C /* CyberSwift.framework in CyberSwift */,
439439
);
440-
name = "Embed Frameworks";
440+
name = CyberSwift;
441441
runOnlyForDeploymentPostprocessing = 0;
442442
};
443443
/* End PBXCopyFilesBuildPhase section */
@@ -2330,8 +2330,9 @@
23302330
571B14ED223A935C00630C8F /* Frameworks */,
23312331
571B14EE223A935C00630C8F /* Resources */,
23322332
A763FF25490FA583CA98714C /* [CP] Embed Pods Frameworks */,
2333-
B1A93CB922BB714F000D6A9C /* ShellScript */,
2334-
AC0F9C31237C307300A5002C /* Embed Frameworks */,
2333+
B1A93CB922BB714F000D6A9C /* Fabric */,
2334+
AC0F9C31237C307300A5002C /* CyberSwift */,
2335+
AC899CC323A7DAE10089F246 /* ShellScript */,
23352336
);
23362337
buildRules = (
23372338
);
@@ -2350,7 +2351,7 @@
23502351
attributes = {
23512352
LastSwiftUpdateCheck = 1020;
23522353
LastUpgradeCheck = 1130;
2353-
ORGANIZATIONNAME = "Maxim Prigozhenkov";
2354+
ORGANIZATIONNAME = "Commun Limited";
23542355
TargetAttributes = {
23552356
3BEA224022B3DA9C00FF42DA = {
23562357
CreatedOnToolsVersion = 10.2.1;
@@ -2555,7 +2556,24 @@
25552556
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Commun/Pods-Commun-frameworks.sh\"\n";
25562557
showEnvVarsInLog = 0;
25572558
};
2558-
B1A93CB922BB714F000D6A9C /* ShellScript */ = {
2559+
AC899CC323A7DAE10089F246 /* ShellScript */ = {
2560+
isa = PBXShellScriptBuildPhase;
2561+
buildActionMask = 2147483647;
2562+
files = (
2563+
);
2564+
inputFileListPaths = (
2565+
);
2566+
inputPaths = (
2567+
);
2568+
outputFileListPaths = (
2569+
);
2570+
outputPaths = (
2571+
);
2572+
runOnlyForDeploymentPostprocessing = 0;
2573+
shellPath = /bin/sh;
2574+
shellScript = "if which ${PODS_ROOT}/SwiftLint/swiftlint >/dev/null; then\n${PODS_ROOT}/SwiftLint/swiftlint\nelse\necho \"error: SwiftLint does not exist, download it from https://github.com/realm/SwiftLint\"\nexit 1\nfi\n";
2575+
};
2576+
B1A93CB922BB714F000D6A9C /* Fabric */ = {
25592577
isa = PBXShellScriptBuildPhase;
25602578
buildActionMask = 2147483647;
25612579
files = (
@@ -2565,6 +2583,7 @@
25652583
inputPaths = (
25662584
"$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)",
25672585
);
2586+
name = Fabric;
25682587
outputFileListPaths = (
25692588
);
25702589
outputPaths = (

Commun/AppDelegate.swift

+33-51
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Commun
44
//
55
// Created by Maxim Prigozhenkov on 14/03/2019.
6-
// Copyright © 2019 Maxim Prigozhenkov. All rights reserved.
6+
// Copyright © 2019 Commun Limited. All rights reserved.
77
//
88
// https://console.firebase.google.com/project/golos-5b0d5/notification/compose?campaignId=9093831260433778480&dupe=true
99
//
@@ -34,7 +34,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3434
let notificationCenter = UNUserNotificationCenter.current()
3535

3636
private var bag = DisposeBag()
37-
3837

3938
// MARK: - Class Functions
4039
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
@@ -73,7 +72,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7372
.take(1)
7473
.asSingle()
7574
.timeout(5, scheduler: MainScheduler.instance)
76-
.subscribe(onSuccess: { (connected) in
75+
.subscribe(onSuccess: { (_) in
7776
AppDelegate.reloadSubject.onNext(false)
7877
self.window?.makeKeyAndVisible()
7978
application.applicationIconBadgeNumber = 0
@@ -125,15 +124,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
125124

126125
// if all set
127126
RestAPIManager.instance.authorize()
128-
.subscribe(onSuccess: { (response) in
127+
.subscribe(onSuccess: { (_) in
129128
// Retrieve favourites
130129
FavouritesList.shared.retrieve()
131130

132131
// Turn notify on
133132
self.pushNotifyOn()
134133

135134
// show feed
136-
if (!force && (self.window?.rootViewController is TabBarVC)) {return}
135+
if !force && (self.window?.rootViewController is TabBarVC) {return}
137136
self.changeRootVC(controllerContainer.resolve(TabBarVC.self)!)
138137
}, onError: { (error) in
139138
if let error = error as? ErrorAPI {
@@ -173,9 +172,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
173172
let navigationBarAppearace = UINavigationBar.appearance()
174173
navigationBarAppearace.tintColor = #colorLiteral(red: 0.4156862745, green: 0.5019607843, blue: 0.9607843137, alpha: 1)
175174
navigationBarAppearace.largeTitleTextAttributes = [
176-
NSAttributedString.Key.foregroundColor: UIColor.black,
177-
NSAttributedString.Key.font: UIFont(name: "SFProDisplay-Bold",
178-
size: 30.0 * Config.widthRatio)!
175+
NSAttributedString.Key.foregroundColor: UIColor.black,
176+
NSAttributedString.Key.font: UIFont(name: "SFProDisplay-Bold",
177+
size: 30.0 * Config.widthRatio)!
179178
]
180179
}
181180
}
@@ -215,10 +214,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
215214
}
216215
})
217216
}
218-
219217
}
220218

221-
func getConfig(completion: @escaping ((Error?)->Void)) {
219+
func getConfig(completion: @escaping ((Error?) -> Void)) {
222220
RestAPIManager.instance.getConfig()
223221
.subscribe(onSuccess: { _ in
224222
completion(nil)
@@ -232,26 +230,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
232230
SocketManager.shared.disconnect()
233231
}
234232

235-
func applicationDidEnterBackground(_ application: UIApplication) {
236-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
237-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
238-
// NetworkService.shared.disconnect()
239-
}
240-
241233
func applicationWillEnterForeground(_ application: UIApplication) {
242-
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
243234
SocketManager.shared.connect()
244235
}
245236

246-
func applicationDidBecomeActive(_ application: UIApplication) {
247-
// NetworkService.shared.connect()
248-
}
249-
250237
func applicationWillTerminate(_ application: UIApplication) {
251238
SocketManager.shared.disconnect()
252239
self.saveContext()
253240
}
254-
255241

256242
// MARK: - Custom Functions
257243
private func configureNotifications(application: UIApplication) {
@@ -261,8 +247,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
261247
// Configure notificationCenter
262248
self.notificationCenter.delegate = self
263249

264-
self.notificationCenter.requestAuthorization(options: [.alert, .sound, .badge],
265-
completionHandler: { (granted, error) in
250+
self.notificationCenter.requestAuthorization(options: [.alert, .sound, .badge],
251+
completionHandler: { (granted, _) in
266252
Logger.log(message: "Permission granted: \(granted)", event: .debug)
267253
guard granted else { return }
268254
self.getNotificationSettings()
@@ -273,12 +259,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
273259
}
274260

275261
private func getNotificationSettings() {
276-
self.notificationCenter.getNotificationSettings(completionHandler: { (settings) in
262+
self.notificationCenter.getNotificationSettings(completionHandler: { (settings) in
277263
Logger.log(message: "Notification settings: \(settings)", event: .debug)
278264
})
279265
}
280266

281-
private func scheduleLocalNotification(userInfo: [AnyHashable : Any]) {
267+
private func scheduleLocalNotification(userInfo: [AnyHashable: Any]) {
282268
let notificationContent = UNMutableNotificationContent()
283269
let categoryIdentifier = userInfo["category"] as? String ?? "Commun"
284270

@@ -301,10 +287,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
301287
let snoozeAction = UNNotificationAction(identifier: "ActionSnooze", title: "Snooze".localized(), options: [])
302288
let deleteAction = UNNotificationAction(identifier: "ActionDelete", title: "delete".localized().uppercaseFirst, options: [.destructive])
303289

304-
let category = UNNotificationCategory(identifier: categoryIdentifier,
305-
actions: [snoozeAction, deleteAction],
306-
intentIdentifiers: [],
307-
options: [])
290+
let category = UNNotificationCategory(identifier: categoryIdentifier,
291+
actions: [snoozeAction, deleteAction],
292+
intentIdentifiers: [],
293+
options: [])
308294

309295
self.notificationCenter.setNotificationCategories([category])
310296
}
@@ -314,14 +300,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
314300
RestAPIManager.instance.pushNotifyOn()
315301
.subscribe(onCompleted: {
316302
Logger.log(message: "Successfully turn pushNotificationOn", event: .severe)
317-
}) { (error) in
303+
}) { (_) in
318304

319305
}
320306
.disposed(by: bag)
321307
}
322308
}
323309

324-
325310
// MARK: - Core Data stack
326311
lazy var persistentContainer: NSPersistentContainer = {
327312
/*
@@ -331,7 +316,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
331316
error conditions that could cause the creation of the store to fail.
332317
*/
333318
let container = NSPersistentContainer(name: "Commun")
334-
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
319+
container.loadPersistentStores(completionHandler: { (_, error) in
335320
if let error = error as NSError? {
336321
// Replace this implementation with code to handle the error appropriately.
337322
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
@@ -367,11 +352,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
367352
}
368353
}
369354

370-
371355
// MARK: - Firebase Cloud Messaging (FCM)
372356
extension AppDelegate {
373-
func application(_ application: UIApplication,
374-
didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
357+
func application(_ application: UIApplication,
358+
didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
375359
if let messageID = userInfo[gcmMessageIDKey] {
376360
Logger.log(message: "Message ID: \(messageID)", event: .severe)
377361
}
@@ -380,8 +364,8 @@ extension AppDelegate {
380364
Logger.log(message: "userInfo: \(userInfo)", event: .severe)
381365
}
382366

383-
func application(_ application: UIApplication,
384-
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
367+
func application(_ application: UIApplication,
368+
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
385369
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
386370
if let messageID = userInfo[gcmMessageIDKey] {
387371
Logger.log(message: "Message ID: \(messageID)", event: .severe)
@@ -393,27 +377,26 @@ extension AppDelegate {
393377
completionHandler(UIBackgroundFetchResult.newData)
394378
}
395379

396-
func application(_ application: UIApplication,
397-
didFailToRegisterForRemoteNotificationsWithError error: Error) {
380+
func application(_ application: UIApplication,
381+
didFailToRegisterForRemoteNotificationsWithError error: Error) {
398382
Logger.log(message: "Unable to register for remote notifications: \(error.localizedDescription)", event: .error)
399383
}
400384

401-
func application(_ application: UIApplication,
402-
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
385+
func application(_ application: UIApplication,
386+
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
403387
Logger.log(message: "APNs token retrieved: \(deviceToken)", event: .severe)
404388

405389
// With swizzling disabled you must set the APNs token here.
406390
// Messaging.messaging().apnsToken = deviceToken
407391
}
408392
}
409393

410-
411394
// MARK: - UNUserNotificationCenterDelegate
412395
@available(iOS 10, *)
413396
extension AppDelegate: UNUserNotificationCenterDelegate {
414397
// Receive push-message when App is active/in background
415-
func userNotificationCenter(_ center: UNUserNotificationCenter,
416-
willPresent notification: UNNotification,
398+
func userNotificationCenter(_ center: UNUserNotificationCenter,
399+
willPresent notification: UNNotification,
417400
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
418401
// Display Local Notification
419402
let notificationContent = notification.request.content
@@ -427,8 +410,8 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
427410
}
428411

429412
// Tap on push message
430-
func userNotificationCenter(_ center: UNUserNotificationCenter,
431-
didReceive response: UNNotificationResponse,
413+
func userNotificationCenter(_ center: UNUserNotificationCenter,
414+
didReceive response: UNNotificationResponse,
432415
withCompletionHandler completionHandler: @escaping () -> Void) {
433416
let notificationContent = response.notification.request.content
434417

@@ -443,14 +426,13 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
443426
}
444427
}
445428

446-
447429
// MARK: - MessagingDelegate
448430
extension AppDelegate: MessagingDelegate {
449-
func messaging(_ messaging: Messaging,
450-
didReceiveRegistrationToken fcmToken: String) {
431+
func messaging(_ messaging: Messaging,
432+
didReceiveRegistrationToken fcmToken: String) {
451433
Logger.log(message: "FCM registration token: \(fcmToken)", event: .severe)
452434

453-
let dataDict:[String: String] = ["token": fcmToken]
435+
let dataDict: [String: String] = ["token": fcmToken]
454436
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
455437

456438
UserDefaults.standard.set(fcmToken, forKey: "fcmToken")

Commun/Assembly/Container.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Commun
44
//
55
// Created by Maxim Prigozhenkov on 19/03/2019.
6-
// Copyright © 2019 Maxim Prigozhenkov. All rights reserved.
6+
// Copyright © 2019 Commun Limited. All rights reserved.
77
//
88

99
import Foundation

0 commit comments

Comments
 (0)