Skip to content

Commit 55dabfd

Browse files
committed
Add Linting to Build Phase + Fix Linting Errors
Also added swiftlint.yml to IOSExample project root in order to pick up rule modifications.
1 parent 5f9628b commit 55dabfd

31 files changed

+117
-53
lines changed

.swiftlint.yml

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ disabled_rules: # rule identifiers turned on by default to exclude from running
1111
- nesting
1212
- type_body_length
1313
- file_length
14+
- todo
15+
- control_statement
16+
- switch_case_alignment
17+
- empty_enum_arguments
18+
- for_where
19+
- private_over_fileprivate
20+
- redundant_string_enum_value
21+
- redundant_optional_initialization
22+
- operator_whitespace
23+
- comma
1424

1525
opt_in_rules:
1626
- force_unwrapping

Sources/XMTPTestHelpers/TestHelpers.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public class FakeApiClient: ApiClient {
197197
}
198198
}
199199
}
200-
200+
201201
if let direction = pagination?.direction {
202202
switch direction {
203203
case .ascending:
@@ -244,7 +244,6 @@ public class FakeApiClient: ApiClient {
244244
var queryResponse = XMTPiOS.BatchQueryResponse()
245245
queryResponse.responses = responses
246246
return queryResponse
247-
248247
}
249248

250249
public func query(request: XMTPiOS.QueryRequest) async throws -> XMTPiOS.QueryResponse {
@@ -254,7 +253,6 @@ public class FakeApiClient: ApiClient {
254253
public func publish(request: XMTPiOS.PublishRequest) async throws {
255254
abort() // Not supported on Fake
256255
}
257-
258256
}
259257

260258
@available(iOS 15, *)

Sources/XMTPiOS/Codecs/AttachmentCodec.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ public struct AttachmentCodec: ContentCodec {
5555

5656
return attachment
5757
}
58-
58+
5959
public func fallback(content: Attachment) throws -> String? {
6060
return "Can’t display “\(content.filename)”. This app doesn’t support attachments."
6161
}
62-
62+
6363
public func shouldPush(content: Attachment) throws -> Bool {
6464
return true
6565
}

Sources/XMTPiOS/Codecs/Composite.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ struct CompositeCodec: ContentCodec {
4141
let decodedComposite = fromComposite(composite: composite)
4242
return decodedComposite
4343
}
44-
44+
4545
public func fallback(content: DecodedComposite) throws -> String? {
4646
return nil
4747
}
48-
48+
4949
public func shouldPush(content: DecodedComposite) throws -> Bool {
5050
return false
5151
}

Sources/XMTPiOS/Codecs/GroupMembershipChanged.swift

-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ public struct GroupMembershipChangedCodec: ContentCodec {
4040
false
4141
}
4242
}
43-

Sources/XMTPiOS/Codecs/ReactionCodec.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77

88
import Foundation
99

10-
1110
public let ContentTypeReaction = ContentTypeID(authorityID: "xmtp.org", typeID: "reaction", versionMajor: 1, versionMinor: 0)
1211

1312
public struct Reaction: Codable {
1413
public var reference: String
1514
public var action: ReactionAction
1615
public var content: String
1716
public var schema: ReactionSchema
18-
17+
1918
public init(reference: String, action: ReactionAction, content: String, schema: ReactionSchema) {
2019
self.reference = reference
2120
self.action = action
@@ -26,7 +25,7 @@ public struct Reaction: Codable {
2625

2726
public enum ReactionAction: String, Codable {
2827
case added, removed, unknown
29-
28+
3029
public init(rawValue: String) {
3130
switch rawValue {
3231
case "added":
@@ -41,7 +40,7 @@ public enum ReactionAction: String, Codable {
4140

4241
public enum ReactionSchema: String, Codable {
4342
case unicode, shortcode, custom, unknown
44-
43+
4544
public init(rawValue: String) {
4645
switch rawValue {
4746
case "unicode":
@@ -85,8 +84,9 @@ public struct ReactionCodec: ContentCodec {
8584
content: String(data: content.content, encoding: .utf8) ?? "",
8685
schema: ReactionSchema(rawValue: content.parameters["schema"] ?? "")
8786
)
87+
// swiftlint:enable no_optional_try
8888
}
89-
89+
9090
public func fallback(content: Reaction) throws -> String? {
9191
switch content.action {
9292
case .added:
@@ -97,7 +97,7 @@ public struct ReactionCodec: ContentCodec {
9797
return nil
9898
}
9999
}
100-
100+
101101
public func shouldPush(content: Reaction) throws -> Bool {
102102
switch content.action {
103103
case .added:

Sources/XMTPiOS/Codecs/ReadReceiptCodec.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public struct ReadReceiptCodec: ContentCodec {
3232
public func decode(content: EncodedContent, client _: Client) throws -> ReadReceipt {
3333
return ReadReceipt()
3434
}
35-
35+
3636
public func fallback(content: ReadReceipt) throws -> String? {
3737
return nil
3838
}
39-
39+
4040
public func shouldPush(content: ReadReceipt) throws -> Bool {
4141
return false
4242
}

Sources/XMTPiOS/Codecs/RemoteAttachmentCodec.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public struct RemoteAttachment {
149149
}
150150

151151
public struct RemoteAttachmentCodec: ContentCodec {
152-
152+
153153
public typealias T = RemoteAttachment
154154

155155
public init() {}
@@ -207,7 +207,7 @@ public struct RemoteAttachmentCodec: ContentCodec {
207207

208208
return attachment
209209
}
210-
210+
211211
public func fallback(content: RemoteAttachment) throws -> String? {
212212
return "Can’t display “\(String(describing: content.filename))”. This app doesn’t support attachments."
213213
}
@@ -223,7 +223,7 @@ public struct RemoteAttachmentCodec: ContentCodec {
223223

224224
return Data(parameterData)
225225
}
226-
226+
227227
public func shouldPush(content: RemoteAttachment) throws -> Bool {
228228
return true
229229
}

Sources/XMTPiOS/Codecs/ReplyCodec.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public struct ReplyCodec: ContentCodec {
6262
throw CodecError.invalidContent
6363
}
6464
}
65-
65+
6666
public func fallback(content: Reply) throws -> String? {
6767
return "Replied with “\(content.content)” to an earlier message"
6868
}
69-
69+
7070
public func shouldPush(content: Reply) throws -> Bool {
7171
return true
7272
}

Sources/XMTPiOS/Codecs/TextCodec.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum TextCodecError: Error {
1414
}
1515

1616
public struct TextCodec: ContentCodec {
17-
17+
1818
public typealias T = String
1919

2020
public init() { }
@@ -42,11 +42,11 @@ public struct TextCodec: ContentCodec {
4242
throw TextCodecError.unknownDecodingError
4343
}
4444
}
45-
45+
4646
public func fallback(content: String) throws -> String? {
4747
return nil
4848
}
49-
49+
5050
public func shouldPush(content: String) throws -> Bool {
5151
return true
5252
}

Sources/XMTPiOS/Conversation.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum Conversation: Sendable {
8989
return group.peerAddresses.joined(separator: ",")
9090
}
9191
}
92-
92+
9393
public var peerAddresses: [String] {
9494
switch self {
9595
case let .v1(conversationV1):
@@ -100,7 +100,7 @@ public enum Conversation: Sendable {
100100
return group.peerAddresses
101101
}
102102
}
103-
103+
104104
public var keyMaterial: Data? {
105105
switch self {
106106
case let .v1(conversationV1):
@@ -182,7 +182,7 @@ public enum Conversation: Sendable {
182182
throw GroupError.notSupportedByGroups
183183
}
184184
}
185-
185+
186186
public func prepareMessage(encodedContent: EncodedContent, options: SendOptions? = nil) async throws -> PreparedMessage {
187187
switch self {
188188
case let .v1(conversationV1):

Sources/XMTPiOS/ConversationV2.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@ public struct ConversationV2 {
107107
}
108108

109109
var encoded = try encode(codec: codec, content: content)
110-
110+
111111
func fallback<Codec: ContentCodec>(codec: Codec, content: Any) throws -> String? {
112112
if let content = content as? Codec.T {
113113
return try codec.fallback(content: content)
114114
} else {
115115
throw CodecError.invalidContent
116116
}
117117
}
118-
118+
119119
if let fallback = try fallback(codec: codec, content: content) {
120120
encoded.fallback = fallback
121121
}
122-
122+
123123
if let compression = options?.compression {
124124
encoded = try encoded.compress(compression)
125125
}

Sources/XMTPiOS/Messages/Invitation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension InvitationV1 {
1616
let context = context ?? InvitationV1.Context()
1717
let myAddress = try sender.toV1().walletAddress
1818
let theirAddress = try recipient.walletAddress
19-
19+
2020
let secret = try sender.sharedSecret(
2121
peer: recipient,
2222
myPreKey: sender.preKeys[0].publicKey,

Sources/XMTPiOS/Messages/MessageV2.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ extension MessageV2 {
9898
let signedBytes = try signedContent.serializedData()
9999

100100
let ciphertext = try Crypto.encrypt(keyMaterial, signedBytes, additionalData: headerBytes)
101-
101+
102102
let thirtyDayPeriodsSinceEpoch = Int(date.timeIntervalSince1970 / 60 / 60 / 24 / 30)
103103
let info = "\(thirtyDayPeriodsSinceEpoch)-\(client.address)"
104104
guard let infoEncoded = info.data(using: .utf8) else {
105105
throw MessageV2Error.invalidData
106106
}
107107

108108
let senderHmac = try Crypto.generateHmacSignature(secret: keyMaterial, info: infoEncoded, message: headerBytes)
109-
109+
110110
let decoded = try codec.decode(content: encodedContent, client: client)
111111
let calculatedShouldPush = try codec.shouldPush(content: decoded)
112112

Sources/XMTPiOS/Messages/PagingInfo.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct Pagination {
1616
public var before: Date?
1717
public var after: Date?
1818
public var direction: PagingInfoSortDirection?
19-
19+
2020
public init(limit: Int? = nil, before: Date? = nil, after: Date? = nil, direction: PagingInfoSortDirection? = .descending) {
2121
self.limit = limit
2222
self.before = before

Sources/XMTPiOS/Messages/PrivateKeyBundle.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Foundation
99

10-
1110
public typealias PrivateKeyBundle = Xmtp_MessageContents_PrivateKeyBundle
1211

1312
enum PrivateKeyBundleError: Error {
@@ -23,9 +22,9 @@ extension PrivateKeyBundle {
2322
func encrypted(with key: SigningKey, preEnableIdentityCallback: PreEventCallback? = nil) async throws -> EncryptedPrivateKeyBundle {
2423
let bundleBytes = try serializedData()
2524
let walletPreKey = try Crypto.secureRandomBytes(count: 32)
26-
25+
2726
try await preEnableIdentityCallback?()
28-
27+
2928
let signature = try await key.sign(message: Signature.enableIdentityText(key: walletPreKey))
3029
let cipherText = try Crypto.encrypt(signature.rawDataWithNormalizedRecovery, bundleBytes)
3130

Sources/XMTPiOS/Messages/PrivateKeyBundleV1.swift

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import CryptoKit
99
import Foundation
1010
import LibXMTP
1111

12-
1312
public typealias PrivateKeyBundleV1 = Xmtp_MessageContents_PrivateKeyBundleV1
1413

1514
extension PrivateKeyBundleV1 {

Sources/XMTPiOS/Messages/PublicKeyBundle.swift

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Created by Pat Nakajima on 11/23/22.
66
//
77

8-
9-
108
typealias PublicKeyBundle = Xmtp_MessageContents_PublicKeyBundle
119

1210
extension PublicKeyBundle {

Sources/XMTPiOS/Messages/SealedInvitationV1.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Foundation
99

10-
1110
typealias SealedInvitationV1 = Xmtp_MessageContents_SealedInvitationV1
1211

1312
extension SealedInvitationV1 {

Sources/XMTPiOS/Messages/SignedContent.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Foundation
99

10-
1110
typealias SignedContent = Xmtp_MessageContents_SignedContent
1211

1312
extension SignedContent {

Sources/XMTPiOS/Messages/SignedPrivateKey.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Foundation
99

10-
1110
public typealias SignedPrivateKey = Xmtp_MessageContents_SignedPrivateKey
1211

1312
extension SignedPrivateKey {

Sources/XMTPiOS/Messages/SignedPublicKeyBundle.swift

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Created by Pat Nakajima on 11/23/22.
66
//
77

8-
9-
108
public typealias SignedPublicKeyBundle = Xmtp_MessageContents_SignedPublicKeyBundle
119

1210
extension SignedPublicKeyBundle {

Sources/XMTPiOS/Messages/Token.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77

88
import Foundation
99

10-
1110
typealias Token = Xmtp_MessageApi_V1_Token

Sources/XMTPiOS/Messages/Topic.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Created by Pat Nakajima on 11/17/22.
66
//
77

8-
9-
108
public enum Topic {
119
case userPrivateStoreKeyBundle(String),
1210
contact(String),
@@ -39,7 +37,7 @@ public enum Topic {
3937
private func wrap(_ value: String) -> String {
4038
"/xmtp/0/\(value)/proto"
4139
}
42-
40+
4341
static func isValidTopic(topic: String) -> Bool {
4442
return topic.allSatisfy(\.isASCII)
4543
}

Sources/XMTPiOS/Messages/UnsignedPublicKey.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Foundation
99

10-
1110
typealias UnsignedPublicKey = Xmtp_MessageContents_UnsignedPublicKey
1211

1312
extension UnsignedPublicKey {

0 commit comments

Comments
 (0)