Skip to content

Commit 2894c47

Browse files
committed
Add SwiftLint and fix warrnings/errors
1 parent 2ca58a0 commit 2894c47

22 files changed

Lines changed: 332 additions & 291 deletions

.swiftlint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
line_length:
2+
warning: 150
3+
ignores_comments: true
4+
5+
disabled_rules:
6+
identifier_name

Example/Sources/ConversationViewController.swift

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,39 @@ import UIKit
2626
import MessageKit
2727

2828
class ConversationViewController: MessagesViewController, MessagesDataSource, MessagesDisplayDataSource {
29-
29+
3030
var messages: [MessageType] = []
31-
31+
3232
override func viewDidLoad() {
3333
super.viewDidLoad()
34-
34+
3535
addSampleData()
36-
36+
3737
messagesCollectionView.messagesDataSource = self
3838
messagesCollectionView.messagesDisplayDataSource = self
3939
messageInputBar.delegate = self
40-
40+
4141
tabBarController?.tabBar.isHidden = true
4242
}
43-
43+
4444
func addSampleData() {
45-
45+
4646
let sender1 = Sender(id: "123456", displayName: "Bobby")
4747
let sender2 = Sender(id: "654321", displayName: "Steven")
4848
let sender3 = Sender(id: "777999", displayName: "Omar")
49-
49+
5050
let msg1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." +
5151
"Pellentesque venenatis, ante et hendrerit rutrum" +
5252
"Quam erat vehicula metus, et condimentum ante tellus augue."
53-
53+
5454
let msg2 = "Cras efficitur bibendum mauris sed ultrices." +
5555
"Phasellus tellus nisl, ullamcorper quis erat."
56-
56+
5757
let msg3 = "Maecenas."
58-
58+
5959
let msg4 = "Pellentesque venenatis, ante et hendrerit rutrum" +
6060
"Quam erat vehicula metus, et condimentum ante tellus augue."
61-
61+
6262
let msg5 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." +
6363
"Pellentesque venenatis, ante et hendrerit rutrum" +
6464
"Quam erat vehicula metus, et condimentum ante tellus augue."
@@ -84,38 +84,36 @@ class ConversationViewController: MessagesViewController, MessagesDataSource, Me
8484
messages.append(MockMessage(text: msg1, sender: currentSender(), id: NSUUID().uuidString))
8585
messages.append(MockMessage(text: msg3, sender: sender1, id: NSUUID().uuidString))
8686
}
87-
87+
8888
func currentSender() -> Sender {
8989
return Sender(id: "123", displayName: "Steven")
9090
}
91-
91+
9292
func numberOfMessages(in collectionView: UICollectionView) -> Int {
9393
return messages.count
9494
}
95-
95+
9696
func messageForItem(at indexPath: IndexPath, in collectionView: UICollectionView) -> MessageType {
9797
return messages[indexPath.section]
9898
}
99-
99+
100100
func avatarForMessage(_ message: MessageType, at indexPath: IndexPath, in collectionView: UICollectionView) -> Avatar {
101101
let image = isFromCurrentSender(message: message) ? #imageLiteral(resourceName: "Steve-Jobs") : #imageLiteral(resourceName: "Tim-Cook")
102102
return Avatar(placeholderImage: image)
103103
}
104-
104+
105105
}
106106

107107
extension ConversationViewController: MessageInputBarDelegate {
108-
108+
109109
func sendButtonPressed(sender: UIButton, textView: UITextView) {
110110

111111
guard let message = textView.text else { return }
112112

113113
messages.append(MockMessage(text: message, sender: currentSender(), id: NSUUID().uuidString))
114-
114+
115115
messagesCollectionView.reloadData()
116-
116+
117117
}
118118

119119
}
120-
121-

Example/Sources/InboxViewController.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,20 @@
2525
import UIKit
2626
import MessageKit
2727

28-
2928
final class InboxViewController: UITableViewController {
3029

3130
override func viewDidLoad() {
3231
super.viewDidLoad()
3332
}
34-
33+
3534
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
3635
return 1
3736
}
38-
37+
3938
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
4039
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") ?? UITableViewCell()
4140
cell.textLabel?.text = "Test"
4241
return cell
4342
}
4443

4544
}
46-

Example/Sources/MockMessage.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,17 @@ import Foundation
2626
import MessageKit
2727

2828
struct MockMessage: MessageType {
29-
29+
3030
var messageId: String
3131
var sender: Sender
3232
var sentDate: Date
3333
var data: MessageData
34-
35-
init(text: String, sender: Sender, id: String) {
34+
35+
init(text: String, sender: Sender, messageId: String) {
3636
data = .text(text)
3737
self.sender = sender
3838
self.messageId = id
3939
self.sentDate = Date()
4040
}
41-
42-
41+
4342
}

Example/Sources/SettingsViewController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
import UIKit
2626
import MessageKit
2727

28-
2928
final class SettingsViewController: UITableViewController {
3029

3130
override func viewDidLoad() {
3231
super.viewDidLoad()
3332
}
34-
}
3533

34+
}

Example/Tests/ChatExampleTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ import XCTest
2020
@testable import ChatExample
2121

2222
final class ChatExampleTests: XCTestCase {
23-
23+
2424
override func setUp() {
2525
super.setUp()
2626
}
27-
27+
2828
override func tearDown() {
2929
super.tearDown()
3030
}
31-
31+
3232
func testExample() {
3333
// This is an example of a functional test case.
3434
// Use XCTAssert and related functions to verify your tests produce the correct results.
3535
}
36+
3637
}

Example/UITests/ChatExampleUITests.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,32 @@ import XCTest
2020
@testable import ChatExample
2121

2222
final class ChatExampleUITests: XCTestCase {
23-
23+
2424
override func setUp() {
2525
super.setUp()
2626

2727
// In UI tests it is usually best to stop immediately when a failure occurs.
2828
continueAfterFailure = false
29-
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
29+
// UI tests must launch the application that they test.
30+
// Doing this in setup will make sure it happens for each test method.
3031
if #available(iOS 9.0, *) {
3132
XCUIApplication().launch()
3233
} else {
3334
// Fallback on earlier versions
3435
}
3536

36-
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run.
37+
// In UI tests it’s important to set the initial state
38+
// - such as interface orientation - required for your tests before they run.
3739
// The setUp method is a good place to do this.
3840
}
39-
41+
4042
override func tearDown() {
4143
super.tearDown()
4244
}
43-
45+
4446
func testExample() {
4547
// Use recording to get started writing UI tests.
4648
// Use XCTAssert and related functions to verify your tests produce the correct results.
4749
}
50+
4851
}

MessageKit.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
88916B1E1CF0DF2F00469F91 /* Frameworks */,
213213
88916B1F1CF0DF2F00469F91 /* Headers */,
214214
88916B201CF0DF2F00469F91 /* Resources */,
215+
B03FF9A51F30398900754FE5 /* ShellScript */,
215216
);
216217
buildRules = (
217218
);
@@ -294,6 +295,22 @@
294295
};
295296
/* End PBXResourcesBuildPhase section */
296297

298+
/* Begin PBXShellScriptBuildPhase section */
299+
B03FF9A51F30398900754FE5 /* ShellScript */ = {
300+
isa = PBXShellScriptBuildPhase;
301+
buildActionMask = 2147483647;
302+
files = (
303+
);
304+
inputPaths = (
305+
);
306+
outputPaths = (
307+
);
308+
runOnlyForDeploymentPostprocessing = 0;
309+
shellPath = /bin/sh;
310+
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
311+
};
312+
/* End PBXShellScriptBuildPhase section */
313+
297314
/* Begin PBXSourcesBuildPhase section */
298315
88916B1D1CF0DF2F00469F91 /* Sources */ = {
299316
isa = PBXSourcesBuildPhase;

Sources/Avatar.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@
2525
import Foundation
2626

2727
public struct Avatar {
28-
28+
2929
public let image: UIImage?
30-
30+
3131
public let highlightedImage: UIImage?
32-
32+
3333
public let placeholderImage: UIImage
34-
34+
3535
public init(image: UIImage? = nil, highlightedImage: UIImage? = nil, placeholderImage: UIImage) {
3636
self.image = image
3737
self.highlightedImage = highlightedImage
3838
self.placeholderImage = placeholderImage
3939
}
40-
40+
4141
public func image(highlighted: Bool) -> UIImage {
42-
42+
4343
switch highlighted {
4444
case true:
4545
return highlightedImage ?? image ?? placeholderImage

0 commit comments

Comments
 (0)