From 943ed2d899dfcaf93691e9056ec003fd0fcfc388 Mon Sep 17 00:00:00 2001 From: Changnam Hong Date: Mon, 9 Apr 2018 23:51:08 +0900 Subject: [PATCH] Fix ChatExample for SwiftLint 1. Set .swiftlint.yml for ChatExample 2. Fix Access Control for Explicit Top Level ACL Violation 3. Fix SwiftLint Warning: Colon Violation, Function Body Length 4. Fix Forced Unwrapping style --- Example/.swiftlint.yml | 20 +++++++++++++ Example/ChatExample.xcodeproj/project.pbxproj | 14 +++++++++ .../xcschemes/ChatExample.xcscheme | 8 ++--- .../xcschemes/ChatExampleUITests.xcscheme | 4 +-- Example/Podfile.lock | 4 +-- Example/Sources/AppDelegate.swift | 4 +-- .../Sources/ConversationViewController.swift | 30 ++++++++----------- Example/Sources/IMessageViewController.swift | 3 +- Example/Sources/InboxViewController.swift | 4 +-- Example/Sources/MockMessage.swift | 7 ++--- Example/Sources/SampleData.swift | 2 +- Example/Sources/SettingsViewController.swift | 24 ++++++++------- Example/Sources/TableViewCells.swift | 2 +- 13 files changed, 75 insertions(+), 51 deletions(-) create mode 100644 Example/.swiftlint.yml diff --git a/Example/.swiftlint.yml b/Example/.swiftlint.yml new file mode 100644 index 00000000..8bf8a3da --- /dev/null +++ b/Example/.swiftlint.yml @@ -0,0 +1,20 @@ + +disabled_rules: + - identifier_name + - trailing_whitespace + - line_length + - type_body_length + - file_length +custom_rules: + override_func: # rule identifier + name: "override in func" # rule name. optional. + regex: "override (open|public|private|internal|fileprivate)" # matching pattern + message: "Use like open override or public override instead" # violation message. optional. + severity: warning # violation severity. optional. +opt_in_rules: + - explicit_acl + - explicit_top_level_acl +explicit_acl: error +explicit_top_level_acl: error +included: + - Sources \ No newline at end of file diff --git a/Example/ChatExample.xcodeproj/project.pbxproj b/Example/ChatExample.xcodeproj/project.pbxproj index 56d35379..7d32b277 100644 --- a/Example/ChatExample.xcodeproj/project.pbxproj +++ b/Example/ChatExample.xcodeproj/project.pbxproj @@ -207,6 +207,7 @@ 882B5EA41CF7D8D100B6E160 /* Embed Frameworks */, 3C8DFCD3063DA0DF099EC7B6 /* [CP] Embed Pods Frameworks */, CD3F8EE3AFF2313DF2D62568 /* [CP] Copy Pods Resources */, + 7E0AFF9D207BB460004DFD4C /* ShellScript */, ); buildRules = ( ); @@ -464,6 +465,19 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ChatExampleUITests/Pods-ChatExampleUITests-resources.sh\"\n"; showEnvVarsInLog = 0; }; + 7E0AFF9D207BB460004DFD4C /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; CD3F8EE3AFF2313DF2D62568 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/Example/ChatExample.xcodeproj/xcshareddata/xcschemes/ChatExample.xcscheme b/Example/ChatExample.xcodeproj/xcshareddata/xcschemes/ChatExample.xcscheme index 56543ffd..cebf89c0 100644 --- a/Example/ChatExample.xcodeproj/xcshareddata/xcschemes/ChatExample.xcscheme +++ b/Example/ChatExample.xcodeproj/xcshareddata/xcschemes/ChatExample.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -71,7 +70,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Example/ChatExample.xcodeproj/xcshareddata/xcschemes/ChatExampleUITests.xcscheme b/Example/ChatExample.xcodeproj/xcshareddata/xcschemes/ChatExampleUITests.xcscheme index 6d3eb900..78acc96f 100644 --- a/Example/ChatExample.xcodeproj/xcshareddata/xcschemes/ChatExampleUITests.xcscheme +++ b/Example/ChatExample.xcodeproj/xcshareddata/xcschemes/ChatExampleUITests.xcscheme @@ -1,6 +1,6 @@ Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool { UIApplication.shared.statusBarStyle = .lightContent window = UIWindow(frame: UIScreen.main.bounds) diff --git a/Example/Sources/ConversationViewController.swift b/Example/Sources/ConversationViewController.swift index a74fe92f..a4820889 100644 --- a/Example/Sources/ConversationViewController.swift +++ b/Example/Sources/ConversationViewController.swift @@ -26,7 +26,7 @@ import UIKit import MessageKit import MapKit -class ConversationViewController: MessagesViewController { +internal class ConversationViewController: MessagesViewController { let refreshControl = UIRefreshControl() @@ -91,8 +91,6 @@ class ConversationViewController: MessagesViewController { label.text = "nathan.tannar is typing..." label.font = UIFont.boldSystemFont(ofSize: 16) messageInputBar.topStackView.addArrangedSubview(label) - - messageInputBar.topStackViewPadding.top = 6 messageInputBar.topStackViewPadding.left = 12 @@ -156,11 +154,9 @@ class ConversationViewController: MessagesViewController { }, makeButton(named: "ic_at").onSelected { $0.tintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1) - print("@ Selected") }, makeButton(named: "ic_hashtag").onSelected { $0.tintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1) - print("# Selected") }, .flexibleSpace, makeButton(named: "ic_library").onTextViewDidChange { button, textView in @@ -275,15 +271,13 @@ extension ConversationViewController: MessagesDataSource { } func cellBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { - - struct ConversationDateFormatter { - static let formatter: DateFormatter = { - let formatter = DateFormatter() - formatter.dateStyle = .medium - return formatter - }() - } - let formatter = ConversationDateFormatter.formatter + + let formatter: DateFormatter = { + let formatter = DateFormatter() + formatter.dateStyle = .medium + return formatter + }() + let dateString = formatter.string(from: message.sentDate) return NSAttributedString(string: dateString, attributes: [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: .caption2)]) } @@ -300,7 +294,7 @@ extension ConversationViewController: MessagesDisplayDelegate { return isFromCurrentSender(message: message) ? .white : .darkText } - func detectorAttributes(for detector: DetectorType, and message: MessageType, at indexPath: IndexPath) -> [NSAttributedStringKey : Any] { + func detectorAttributes(for detector: DetectorType, and message: MessageType, at indexPath: IndexPath) -> [NSAttributedStringKey: Any] { return MessageLabel.defaultAttributes } @@ -365,7 +359,7 @@ extension ConversationViewController: MessagesLayoutDelegate { return 16 } - func footerViewSize(for indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGSize { + private func footerViewSize(for indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> CGSize { return CGSize(width: messagesCollectionView.bounds.width, height: 10) } } @@ -396,7 +390,7 @@ extension ConversationViewController: MessageCellDelegate { extension ConversationViewController: MessageLabelDelegate { - func didSelectAddress(_ addressComponents: [String : String]) { + func didSelectAddress(_ addressComponents: [String: String]) { print("Address Selected: \(addressComponents)") } @@ -412,7 +406,7 @@ extension ConversationViewController: MessageLabelDelegate { print("URL Selected: \(url)") } - func didSelectTransitInformation(_ transitInformation: [String : String]) { + func didSelectTransitInformation(_ transitInformation: [String: String]) { print("TransitInformation Selected: \(transitInformation)") } diff --git a/Example/Sources/IMessageViewController.swift b/Example/Sources/IMessageViewController.swift index 77a8dcaa..4e29233c 100644 --- a/Example/Sources/IMessageViewController.swift +++ b/Example/Sources/IMessageViewController.swift @@ -8,8 +8,7 @@ import MessageKit -class IMessageViewController: MessagesViewController { - +internal class IMessageViewController: MessagesViewController { override func viewDidLoad() { super.viewDidLoad() diff --git a/Example/Sources/InboxViewController.swift b/Example/Sources/InboxViewController.swift index 37f478bc..559437ad 100644 --- a/Example/Sources/InboxViewController.swift +++ b/Example/Sources/InboxViewController.swift @@ -26,7 +26,7 @@ import UIKit import MessageKit import SafariServices -final class InboxViewController: UITableViewController { +final internal class InboxViewController: UITableViewController { let cells = ["Example", "Settings", "Source Code", "Contributors"] @@ -37,7 +37,7 @@ final class InboxViewController: UITableViewController { title = "MessageKit" navigationController?.navigationBar.tintColor = .white navigationController?.navigationBar.barTintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1) - navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font : UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.bold) ] + navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.bold) ] tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") tableView.tableFooterView = UIView() } diff --git a/Example/Sources/MockMessage.swift b/Example/Sources/MockMessage.swift index 99267958..f7077a82 100644 --- a/Example/Sources/MockMessage.swift +++ b/Example/Sources/MockMessage.swift @@ -26,7 +26,7 @@ import Foundation import CoreLocation import MessageKit -struct MockLocationItem: LocationItem { +private struct MockLocationItem: LocationItem { var location: CLLocation var size: CGSize @@ -38,7 +38,7 @@ struct MockLocationItem: LocationItem { } -struct MockMediaItem: MediaItem { +private struct MockMediaItem: MediaItem { var url: URL? var image: UIImage? @@ -53,7 +53,7 @@ struct MockMediaItem: MediaItem { } -struct MockMessage: MessageType { +internal struct MockMessage: MessageType { var messageId: String var sender: Sender @@ -95,4 +95,3 @@ struct MockMessage: MessageType { } } - diff --git a/Example/Sources/SampleData.swift b/Example/Sources/SampleData.swift index f33d5e8c..10619a8e 100644 --- a/Example/Sources/SampleData.swift +++ b/Example/Sources/SampleData.swift @@ -25,7 +25,7 @@ import MessageKit import CoreLocation -final class SampleData { +final internal class SampleData { static let shared = SampleData() diff --git a/Example/Sources/SettingsViewController.swift b/Example/Sources/SettingsViewController.swift index 61bb813d..dae638b2 100644 --- a/Example/Sources/SettingsViewController.swift +++ b/Example/Sources/SettingsViewController.swift @@ -25,7 +25,7 @@ import UIKit import MessageKit -final class SettingsViewController: UITableViewController { +final internal class SettingsViewController: UITableViewController { // MARK: - Properties @@ -100,16 +100,18 @@ final class SettingsViewController: UITableViewController { // MARK: - Helper private func configureTextFieldTableViewCell(at indexPath: IndexPath) -> TextFieldTableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: TextFieldTableViewCell.identifier, for: indexPath) as! TextFieldTableViewCell - cell.mainLabel.text = "Mock messages count:" - - let messagesCount = UserDefaults.standard.mockMessagesCount() - cell.textField.text = "\(messagesCount)" - - cell.textField.inputView = messagesPicker - cell.textField.inputAccessoryView = messagesToolbar - - return cell + if let cell = tableView.dequeueReusableCell(withIdentifier: TextFieldTableViewCell.identifier, for: indexPath) as? TextFieldTableViewCell { + cell.mainLabel.text = "Mock messages count:" + + let messagesCount = UserDefaults.standard.mockMessagesCount() + cell.textField.text = "\(messagesCount)" + + cell.textField.inputView = messagesPicker + cell.textField.inputAccessoryView = messagesToolbar + + return cell + } + return TextFieldTableViewCell() } } diff --git a/Example/Sources/TableViewCells.swift b/Example/Sources/TableViewCells.swift index b3e114e5..6b88a523 100644 --- a/Example/Sources/TableViewCells.swift +++ b/Example/Sources/TableViewCells.swift @@ -24,7 +24,7 @@ import UIKit -class TextFieldTableViewCell: UITableViewCell { +internal class TextFieldTableViewCell: UITableViewCell { static let identifier = "TextFieldTableViewCellIdentifier"