Skip to content

Commit 267b83a

Browse files
authored
Update swiftformat (#151)
* Update to swiftformat 0.52.10 This is the latest version of swiftformat. The .swiftformat config is modified to target Swift 5.7, which is the oldest Swift currently supported by mqtt-nio. The validate.sh script is updated to resolve some shellcheck issues. Signed-off-by: Peter Grayson <[email protected]> * Formatting fixes for swiftformat 0.52.10 Signed-off-by: Peter Grayson <[email protected]> --------- Signed-off-by: Peter Grayson <[email protected]>
1 parent a370d9e commit 267b83a

File tree

13 files changed

+38
-37
lines changed

13 files changed

+38
-37
lines changed

.github/workflows/validate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
- name: Install Dependencies
1515
run: |
1616
brew install mint
17-
mint install nicklockwood/swiftformat@0.48.17 --no-link
17+
mint install nicklockwood/swiftformat@0.52.10 --no-link
1818
- name: run script
1919
run: ./scripts/validate.sh

.swiftformat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Minimum swiftformat version
2-
--minversion 0.47.4
2+
--minversion 0.52.0
33

44
# Swift version
5-
--swiftversion 5.1
5+
--swiftversion 5.7
66

77
# file options
88
--exclude .build

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ docker-compose run test
3535

3636
### Formatting
3737

38-
We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.48.17.
38+
We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.52.10.

Sources/MQTTNIO/AsyncAwaitSupport/MQTTClient+async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension MQTTClient {
2828
public func shutdown(queue: DispatchQueue = .global()) async throws {
2929
return try await withUnsafeThrowingContinuation { cont in
3030
self.shutdown(queue: queue) { error in
31-
if let error = error {
31+
if let error {
3232
cont.resume(throwing: error)
3333
} else {
3434
cont.resume()

Sources/MQTTNIO/ChannelHandlers/WebSocketHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ final class WebSocketHandler: ChannelDuplexHandler {
107107

108108
/// Send ping and setup task to check for pong and send new ping
109109
private func sendPingAndWait(context: ChannelHandlerContext) {
110-
guard context.channel.isActive, let pingInterval = pingInterval else {
110+
guard context.channel.isActive, let pingInterval else {
111111
return
112112
}
113113
if self.waitingOnPong {

Sources/MQTTNIO/MQTTClient.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public final class MQTTClient {
7474
return self.host
7575
}
7676

77-
internal let globalPacketId = ManagedAtomic<UInt16>(1)
77+
let globalPacketId = ManagedAtomic<UInt16>(1)
7878
/// default logger that logs nothing
7979
private static let loggingDisabled = Logger(label: "MQTT-do-not-log", factory: { _ in SwiftLogNoOpLogHandler() })
8080
/// inflight messages
@@ -101,7 +101,7 @@ public final class MQTTClient {
101101
configuration: Configuration = Configuration()
102102
) {
103103
self.host = host
104-
if let port = port {
104+
if let port {
105105
self.port = port
106106
} else {
107107
switch (configuration.useSSL, configuration.useWebSockets) {
@@ -190,7 +190,7 @@ public final class MQTTClient {
190190
var errorStorage: Error?
191191
let continuation = DispatchWorkItem {}
192192
self.shutdown(queue: DispatchQueue(label: "mqtt-client.shutdown")) { error in
193-
if let error = error {
193+
if let error {
194194
errorStorageLock.withLock {
195195
errorStorage = error
196196
}
@@ -334,7 +334,7 @@ public final class MQTTClient {
334334
will: publish
335335
)
336336

337-
return self.connect(packet: packet).map { $0.sessionPresent }
337+
return self.connect(packet: packet).map(\.sessionPresent)
338338
}
339339

340340
/// Publish message to topic
@@ -441,7 +441,7 @@ public final class MQTTClient {
441441
self.shutdownListeners.removeListener(named: name)
442442
}
443443

444-
internal func updatePacketId() -> UInt16 {
444+
func updatePacketId() -> UInt16 {
445445
let id = self.globalPacketId.wrappingIncrementThenLoad(by: 1, ordering: .relaxed)
446446

447447
// packet id must be non-zero
@@ -468,7 +468,7 @@ public final class MQTTClient {
468468
private var lock = NIOLock()
469469
}
470470

471-
internal extension MQTTClient {
471+
extension MQTTClient {
472472
/// connect to broker
473473
func connect(
474474
packet: MQTTConnectPacket,
@@ -513,7 +513,7 @@ internal extension MQTTClient {
513513
}
514514
case let auth as MQTTAuthPacket:
515515
// auth messages require an auth workflow closure
516-
guard let authWorkflow = authWorkflow else { return eventLoop.makeFailedFuture(MQTTError.authWorkflowRequired) }
516+
guard let authWorkflow else { return eventLoop.makeFailedFuture(MQTTError.authWorkflowRequired) }
517517
return self.processAuth(auth, authWorkflow: authWorkflow, on: eventLoop)
518518
.flatMapThrowing { result -> MQTTConnAckPacket in
519519
// once auth workflow is finished we should receive a connack

Sources/MQTTNIO/MQTTClientV5.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ extension MQTTClient {
187187
if auth.reason == .success {
188188
return eventLoop.makeSucceededFuture(auth)
189189
}
190-
guard let authWorkflow = authWorkflow else { return eventLoop.makeFailedFuture(MQTTError.authWorkflowRequired) }
190+
guard let authWorkflow else { return eventLoop.makeFailedFuture(MQTTError.authWorkflowRequired) }
191191
return self.client.processAuth(authPacket, authWorkflow: authWorkflow, on: eventLoop)
192192
}
193193
.flatMapThrowing { response -> MQTTAuthV5 in

Sources/MQTTNIO/MQTTInflight.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ struct MQTTInflight {
2424
/// add packet
2525
mutating func add(packet: MQTTPacket) {
2626
self.lock.withLock {
27-
packets.append(packet)
27+
self.packets.append(packet)
2828
}
2929
}
3030

3131
/// remove packert
3232
mutating func remove(id: UInt16) {
3333
self.lock.withLock {
3434
guard let first = packets.firstIndex(where: { $0.packetId == id }) else { return }
35-
packets.remove(at: first)
35+
self.packets.remove(at: first)
3636
}
3737
}
3838

3939
/// remove all packets
4040
mutating func clear() {
4141
self.lock.withLock {
42-
packets = []
42+
self.packets = []
4343
}
4444
}
4545

Sources/MQTTNIO/MQTTListeners.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ final class MQTTListeners<ReturnType> {
2828

2929
func addListener(named name: String, listener: @escaping Listener) {
3030
self.lock.withLock {
31-
listeners[name] = listener
31+
self.listeners[name] = listener
3232
}
3333
}
3434

3535
func removeListener(named name: String) {
3636
self.lock.withLock {
37-
listeners[name] = nil
37+
self.listeners[name] = nil
3838
}
3939
}
4040

Sources/MQTTNIO/MQTTPacket.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import NIOCore
1515

16-
internal enum InternalError: Swift.Error {
16+
enum InternalError: Swift.Error {
1717
case incompletePacket
1818
case notImplemented
1919
}
@@ -99,7 +99,7 @@ struct MQTTConnectPacket: MQTTPacket {
9999
byteBuffer.writeInteger(version.versionByte)
100100
// connect flags
101101
var flags = self.cleanSession ? ConnectFlags.cleanSession : 0
102-
if let will = will {
102+
if let will {
103103
flags |= ConnectFlags.willFlag
104104
flags |= will.retain ? ConnectFlags.willRetain : 0
105105
flags |= will.qos.rawValue << ConnectFlags.willQoSShift
@@ -116,17 +116,17 @@ struct MQTTConnectPacket: MQTTPacket {
116116

117117
// payload
118118
try MQTTSerializer.writeString(self.clientIdentifier, to: &byteBuffer)
119-
if let will = will {
119+
if let will {
120120
if version == .v5_0 {
121121
try will.properties.write(to: &byteBuffer)
122122
}
123123
try MQTTSerializer.writeString(will.topicName, to: &byteBuffer)
124124
try MQTTSerializer.writeBuffer(will.payload, to: &byteBuffer)
125125
}
126-
if let userName = userName {
126+
if let userName {
127127
try MQTTSerializer.writeString(userName, to: &byteBuffer)
128128
}
129-
if let password = password {
129+
if let password {
130130
try MQTTSerializer.writeString(password, to: &byteBuffer)
131131
}
132132
}
@@ -149,7 +149,7 @@ struct MQTTConnectPacket: MQTTPacket {
149149
// client identifier
150150
size += self.clientIdentifier.utf8.count + 2
151151
// will publish
152-
if let will = will {
152+
if let will {
153153
// properties
154154
if version == .v5_0 {
155155
let propertiesPacketSize = will.properties.packetSize
@@ -161,11 +161,11 @@ struct MQTTConnectPacket: MQTTPacket {
161161
size += will.payload.readableBytes + 2
162162
}
163163
// user name
164-
if let userName = userName {
164+
if let userName {
165165
size += userName.utf8.count + 2
166166
}
167167
// password
168-
if let password = password {
168+
if let password {
169169
size += password.utf8.count + 2
170170
}
171171
return size
@@ -370,7 +370,7 @@ struct MQTTPubAckPacket: MQTTPacket {
370370
let reason: MQTTReasonCode
371371
let properties: MQTTProperties
372372

373-
internal init(
373+
init(
374374
type: MQTTPacketType,
375375
packetId: UInt16,
376376
reason: MQTTReasonCode = .success,

0 commit comments

Comments
 (0)