Skip to content

Commit 8929bb1

Browse files
authored
Swift format (#165)
* swift-format * checkout v4 * Add dependabot * Update validate.sh * Fix generic parameter 'T' could not be inferred
1 parent 8886459 commit 8929bb1

20 files changed

+189
-119
lines changed

.github/dependabot.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
ignore:
8+
- dependency-name: "codecov/codecov-action"
9+
update-types: ["version-update:semver-major"]
10+
groups:
11+
dependencies:
12+
patterns:
13+
- "*"
14+
- package-ecosystem: "swift"
15+
directory: "/"
16+
schedule:
17+
interval: "daily"
18+
open-pull-requests-limit: 5
19+
allow:
20+
- dependency-type: all
21+
groups:
22+
all-dependencies:
23+
patterns:
24+
- "*"

.github/workflows/ci.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ jobs:
3131
-instr-profile=.build/debug/codecov/default.profdata > info.lcov
3232
- name: Upload to codecov.io
3333
uses: codecov/codecov-action@v4
34-
env:
35-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3634
with:
37-
file: info.lcov
35+
files: info.lcov
36+
token: ${{ secrets.CODECOV_TOKEN }}
3837

3938
ios:
4039
runs-on: macOS-latest
@@ -94,7 +93,6 @@ jobs:
9493
-instr-profile .build/debug/codecov/default.profdata > info.lcov
9594
- name: Upload to codecov.io
9695
uses: codecov/codecov-action@v4
97-
env:
98-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
9996
with:
100-
file: info.lcov
97+
files: info.lcov
98+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/validate.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ name: Validity Check
22

33
on:
44
pull_request:
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.ref }}-validate
7+
cancel-in-progress: true
58

69
jobs:
710
validate:
8-
runs-on: macOS-latest
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 15
913
steps:
1014
- name: Checkout
11-
uses: actions/checkout@v1
15+
uses: actions/checkout@v4
1216
with:
1317
fetch-depth: 1
14-
- name: Install Dependencies
15-
run: |
16-
brew install mint
17-
mint install nicklockwood/[email protected] --no-link
1818
- name: run script
1919
run: ./scripts/validate.sh

.swift-format

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"version" : 1,
3+
"indentation" : {
4+
"spaces" : 4
5+
},
6+
"tabWidth" : 4,
7+
"fileScopedDeclarationPrivacy" : {
8+
"accessLevel" : "private"
9+
},
10+
"spacesAroundRangeFormationOperators" : false,
11+
"indentConditionalCompilationBlocks" : false,
12+
"indentSwitchCaseLabels" : false,
13+
"lineBreakAroundMultilineExpressionChainComponents" : false,
14+
"lineBreakBeforeControlFlowKeywords" : false,
15+
"lineBreakBeforeEachArgument" : true,
16+
"lineBreakBeforeEachGenericRequirement" : true,
17+
"lineLength" : 150,
18+
"maximumBlankLines" : 1,
19+
"respectsExistingLineBreaks" : true,
20+
"prioritizeKeepingFunctionOutputTogether" : true,
21+
"multiElementCollectionTrailingCommas" : true,
22+
"rules" : {
23+
"AllPublicDeclarationsHaveDocumentation" : false,
24+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
25+
"AlwaysUseLowerCamelCase" : false,
26+
"AmbiguousTrailingClosureOverload" : true,
27+
"BeginDocumentationCommentWithOneLineSummary" : false,
28+
"DoNotUseSemicolons" : true,
29+
"DontRepeatTypeInStaticProperties" : true,
30+
"FileScopedDeclarationPrivacy" : true,
31+
"FullyIndirectEnum" : true,
32+
"GroupNumericLiterals" : true,
33+
"IdentifiersMustBeASCII" : true,
34+
"NeverForceUnwrap" : false,
35+
"NeverUseForceTry" : false,
36+
"NeverUseImplicitlyUnwrappedOptionals" : false,
37+
"NoAccessLevelOnExtensionDeclaration" : true,
38+
"NoAssignmentInExpressions" : true,
39+
"NoBlockComments" : true,
40+
"NoCasesWithOnlyFallthrough" : true,
41+
"NoEmptyTrailingClosureParentheses" : true,
42+
"NoLabelsInCasePatterns" : true,
43+
"NoLeadingUnderscores" : false,
44+
"NoParensAroundConditions" : true,
45+
"NoVoidReturnOnFunctionSignature" : true,
46+
"OmitExplicitReturns" : true,
47+
"OneCasePerLine" : true,
48+
"OneVariableDeclarationPerLine" : true,
49+
"OnlyOneTrailingClosureArgument" : true,
50+
"OrderedImports" : true,
51+
"ReplaceForEachWithForLoop" : true,
52+
"ReturnVoidInsteadOfEmptyTuple" : true,
53+
"UseEarlyExits" : false,
54+
"UseExplicitNilCheckInConditions" : false,
55+
"UseLetInEveryBoundCaseVariable" : false,
56+
"UseShorthandTypeNames" : true,
57+
"UseSingleLinePropertyGetter" : false,
58+
"UseSynthesizedInitializer" : false,
59+
"UseTripleSlashForDocumentationComments" : true,
60+
"UseWhereClausesInForLoops" : false,
61+
"ValidateDocumentationComments" : false
62+
}
63+
}

.swiftformat

Lines changed: 0 additions & 26 deletions
This file was deleted.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let package = Package(
66
name: "mqtt-nio",
77
platforms: [.macOS(.v10_14), .iOS(.v12), .tvOS(.v12), .watchOS(.v6)],
88
products: [
9-
.library(name: "MQTTNIO", targets: ["MQTTNIO"]),
9+
.library(name: "MQTTNIO", targets: ["MQTTNIO"])
1010
],
1111
dependencies: [
1212
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.0"),

Sources/MQTTNIO/AsyncAwaitSupport/MQTTClient+async.swift

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
import NIOCore
15+
1416
#if canImport(FoundationEssentials)
1517
import Dispatch
1618
import FoundationEssentials
1719
#else
1820
import Foundation
1921
#endif
20-
import NIOCore
2122

2223
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
2324
extension MQTTClient {
@@ -31,7 +32,7 @@ extension MQTTClient {
3132
/// - Parameters:
3233
/// - queue: Dispatch Queue to run shutdown on
3334
public func shutdown(queue: DispatchQueue = .global()) async throws {
34-
return try await withUnsafeThrowingContinuation { cont in
35+
try await withUnsafeThrowingContinuation { (cont: UnsafeContinuation<Void, Error>) in
3536
self.shutdown(queue: queue) { error in
3637
if let error {
3738
cont.resume(throwing: error)
@@ -59,7 +60,7 @@ extension MQTTClient {
5960
cleanSession: Bool = true,
6061
will: (topicName: String, payload: ByteBuffer, qos: MQTTQoS, retain: Bool)? = nil
6162
) async throws -> Bool {
62-
return try await self.connect(cleanSession: cleanSession, will: will).get()
63+
try await self.connect(cleanSession: cleanSession, will: will).get()
6364
}
6465

6566
/// Connect to MQTT server
@@ -80,10 +81,11 @@ extension MQTTClient {
8081
will: (topicName: String, payload: ByteBuffer, qos: MQTTQoS, retain: Bool)? = nil,
8182
connectConfiguration: ConnectConfiguration
8283
) async throws -> Bool {
83-
return try await self.connect(
84+
try await self.connect(
8485
cleanSession: cleanSession,
85-
will: will, connectConfiguration:
86-
connectConfiguration
86+
will: will,
87+
connectConfiguration:
88+
connectConfiguration
8789
).get()
8890
}
8991

@@ -101,23 +103,23 @@ extension MQTTClient {
101103
/// - qos: Quality of Service for message.
102104
/// - retain: Whether this is a retained message.
103105
public func publish(to topicName: String, payload: ByteBuffer, qos: MQTTQoS, retain: Bool = false) async throws {
104-
return try await self.publish(to: topicName, payload: payload, qos: qos, retain: retain).get()
106+
try await self.publish(to: topicName, payload: payload, qos: qos, retain: retain).get()
105107
}
106108

107109
/// Subscribe to topic
108110
///
109111
/// Completes when SUBACK is received
110112
/// - Parameter subscriptions: Subscription infos
111113
public func subscribe(to subscriptions: [MQTTSubscribeInfo]) async throws -> MQTTSuback {
112-
return try await self.subscribe(to: subscriptions).get()
114+
try await self.subscribe(to: subscriptions).get()
113115
}
114116

115117
/// Unsubscribe from topic
116118
///
117119
/// Completes when UNSUBACK is received
118120
/// - Parameter subscriptions: List of subscriptions to unsubscribe from
119121
public func unsubscribe(from subscriptions: [String]) async throws {
120-
return try await self.unsubscribe(from: subscriptions).get()
122+
try await self.unsubscribe(from: subscriptions).get()
121123
}
122124

123125
/// Ping the server to test if it is still alive and to tell it you are alive.
@@ -128,12 +130,12 @@ extension MQTTClient {
128130
/// the connection is still live. If you initialize the client with the configuration `disablePingReq: true` then these
129131
/// are disabled and it is up to you to send the PINGREQ messages yourself
130132
public func ping() async throws {
131-
return try await self.ping().get()
133+
try await self.ping().get()
132134
}
133135

134136
/// Disconnect from server
135137
public func disconnect() async throws {
136-
return try await self.disconnect().get()
138+
try await self.disconnect().get()
137139
}
138140

139141
/// Create a publish listener AsyncSequence that yields a result whenever a PUBLISH message is received from the server
@@ -153,7 +155,7 @@ extension MQTTClient {
153155
/// }
154156
/// ```
155157
public func createPublishListener() -> MQTTPublishListener {
156-
return .init(self)
158+
.init(self)
157159
}
158160
}
159161

@@ -187,6 +189,6 @@ public class MQTTPublishListener: AsyncSequence {
187189
}
188190

189191
public __consuming func makeAsyncIterator() -> AsyncStream<Element>.AsyncIterator {
190-
return self.stream.makeAsyncIterator()
192+
self.stream.makeAsyncIterator()
191193
}
192194
}

Sources/MQTTNIO/AsyncAwaitSupport/MQTTClientV5+async.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
import NIOCore
15+
1416
#if canImport(FoundationEssentials)
1517
import FoundationEssentials
1618
#else
1719
import Foundation
1820
#endif
19-
import NIOCore
2021

2122
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
2223
extension MQTTClient.V5 {
@@ -42,7 +43,7 @@ extension MQTTClient.V5 {
4243
will: (topicName: String, payload: ByteBuffer, qos: MQTTQoS, retain: Bool, properties: MQTTProperties)? = nil,
4344
authWorkflow: ((MQTTAuthV5, EventLoop) -> EventLoopFuture<MQTTAuthV5>)? = nil
4445
) async throws -> MQTTConnackV5 {
45-
return try await self.connect(cleanStart: cleanStart, properties: properties, will: will, authWorkflow: authWorkflow).get()
46+
try await self.connect(cleanStart: cleanStart, properties: properties, will: will, authWorkflow: authWorkflow).get()
4647
}
4748

4849
/// Connect to MQTT server
@@ -69,7 +70,7 @@ extension MQTTClient.V5 {
6970
authWorkflow: ((MQTTAuthV5, EventLoop) -> EventLoopFuture<MQTTAuthV5>)? = nil,
7071
connectConfiguration: MQTTClient.ConnectConfiguration
7172
) async throws -> MQTTConnackV5 {
72-
return try await self.connect(
73+
try await self.connect(
7374
cleanStart: cleanStart,
7475
properties: properties,
7576
will: will,
@@ -95,7 +96,7 @@ extension MQTTClient.V5 {
9596
retain: Bool = false,
9697
properties: MQTTProperties = .init()
9798
) async throws -> MQTTAckV5? {
98-
return try await self.publish(to: topicName, payload: payload, qos: qos, retain: retain, properties: properties).get()
99+
try await self.publish(to: topicName, payload: payload, qos: qos, retain: retain, properties: properties).get()
99100
}
100101

101102
/// Subscribe to topic
@@ -108,7 +109,7 @@ extension MQTTClient.V5 {
108109
to subscriptions: [MQTTSubscribeInfoV5],
109110
properties: MQTTProperties = .init()
110111
) async throws -> MQTTSubackV5 {
111-
return try await self.subscribe(to: subscriptions, properties: properties).get()
112+
try await self.subscribe(to: subscriptions, properties: properties).get()
112113
}
113114

114115
/// Unsubscribe from topic
@@ -121,14 +122,14 @@ extension MQTTClient.V5 {
121122
from subscriptions: [String],
122123
properties: MQTTProperties = .init()
123124
) async throws -> MQTTSubackV5 {
124-
return try await self.unsubscribe(from: subscriptions, properties: properties).get()
125+
try await self.unsubscribe(from: subscriptions, properties: properties).get()
125126
}
126127

127128
/// Disconnect from server
128129
/// - Parameter properties: properties to attach to disconnect packet
129130
/// - Returns: Future waiting on disconnect message to be sent
130131
public func disconnect(properties: MQTTProperties = .init()) async throws {
131-
return try await self.disconnect(properties: properties).get()
132+
try await self.disconnect(properties: properties).get()
132133
}
133134

134135
/// Re-authenticate with server
@@ -141,13 +142,13 @@ extension MQTTClient.V5 {
141142
properties: MQTTProperties,
142143
authWorkflow: ((MQTTAuthV5, EventLoop) -> EventLoopFuture<MQTTAuthV5>)? = nil
143144
) async throws -> MQTTAuthV5 {
144-
return try await self.auth(properties: properties, authWorkflow: authWorkflow).get()
145+
try await self.auth(properties: properties, authWorkflow: authWorkflow).get()
145146
}
146147

147148
/// Create a publish listener AsyncSequence that yields a value whenever a PUBLISH message is received from the server
148149
/// with the specified subscription id
149150
public func createPublishListener(subscriptionId: UInt) -> MQTTPublishIdListener {
150-
return .init(self, subscriptionId: subscriptionId)
151+
.init(self, subscriptionId: subscriptionId)
151152
}
152153
}
153154

@@ -181,6 +182,6 @@ public class MQTTPublishIdListener: AsyncSequence {
181182
}
182183

183184
public __consuming func makeAsyncIterator() -> AsyncStream<Element>.AsyncIterator {
184-
return self.stream.makeAsyncIterator()
185+
self.stream.makeAsyncIterator()
185186
}
186187
}

0 commit comments

Comments
 (0)