Skip to content

Commit c2e1e12

Browse files
authored
Reformat async code (#1383)
* Update formatter Motivation: We need to use a newer version of SwiftFormat on the async/await code. First we should update main so that merging changes into the async branch is cleaner. Modifications: - Update SwiftFormat - Reformat Result: Our version of SwiftFormat is new enough to correctly handle async/await code. (cherry picked from commit 80055e5) * Reformat async code Motivation: On 'main' we updated SwiftFormat to a version which knows about language features introduced in 5.5 and formatted the code accordingly. We need to do the same on the async branch. Modifications: - Remove rules to temporarily disable SwiftFormat (in place for compatibility reasons) - Rerun the formatter Result: Formatter is happy.
1 parent b341dbb commit c2e1e12

File tree

55 files changed

+214
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+214
-164
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- name: "Formatting and License Headers check"
1616
run: |
17-
SWIFTFORMAT_VERSION=0.46.3
17+
SWIFTFORMAT_VERSION=0.49.4
1818
git clone --depth 1 --branch "$SWIFTFORMAT_VERSION" "https://github.com/nicklockwood/SwiftFormat" "$HOME/SwiftFormat"
1919
swift build --package-path "$HOME/SwiftFormat" --product swiftformat
2020
export PATH=$PATH:"$(swift build --package-path "$HOME/SwiftFormat" --show-bin-path)"

.swiftformat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@
3737

3838
# Don't prefer using key paths for trivial closures.
3939
--disable preferKeyPath
40+
41+
# Put ACLs on declarations within an extension rather than the extension itself.
42+
--extensionacl on-declarations

Examples/Google/NaturalLanguage/Sources/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func getAuthToken(
5656
do {
5757
try provider.withToken { token, error in
5858
if let token = token,
59-
let accessToken = token.AccessToken {
59+
let accessToken = token.AccessToken {
6060
promise.succeed(accessToken)
6161
} else if let error = error {
6262
promise.fail(error)

Examples/Google/SpeechToText/Sources/Launch/SceneDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
3535
self.navController?.navigationBar.prefersLargeTitles = false
3636

3737
let viewController: UIViewController = ViewController()
38-
navController?.pushViewController(viewController, animated: false)
38+
self.navController?.pushViewController(viewController, animated: false)
3939

4040
self.window = UIWindow(windowScene: windowScene)
4141
self.window!.rootViewController = self.navController

Examples/Google/SpeechToText/Sources/SpeechService.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ final class SpeechService {
6666
)
6767
}
6868

69-
func stream(_ data: Data,
70-
completion: ((Google_Cloud_Speech_V1_StreamingRecognizeResponse) -> Void)? = nil) {
69+
func stream(
70+
_ data: Data,
71+
completion: ((Google_Cloud_Speech_V1_StreamingRecognizeResponse) -> Void)? = nil
72+
) {
7173
switch self.state {
7274
case .idle:
7375
// Initialize the bidirectional stream

Examples/Google/SpeechToText/Sources/ViewController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ final class ViewController: UIViewController {
5656
private let speechService: SpeechService
5757
private let audioStreamManager: AudioStreamManager
5858

59-
init(speechService: SpeechService,
60-
audioStreamManager: AudioStreamManager) {
59+
init(
60+
speechService: SpeechService,
61+
audioStreamManager: AudioStreamManager
62+
) {
6163
self.speechService = speechService
6264
self.audioStreamManager = audioStreamManager
6365

Performance/QPSBenchmark/Sources/QPSBenchmark/Runtime/AsyncPingPongRequestMaker.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ final class AsyncPingPongRequestMaker: RequestMaker {
3939
/// - requestMessage: Pre-made request message to use possibly repeatedly.
4040
/// - logger: Where to log useful diagnostics.
4141
/// - stats: Where to record statistics on latency.
42-
init(config: Grpc_Testing_ClientConfig,
43-
client: Grpc_Testing_BenchmarkServiceClient,
44-
requestMessage: Grpc_Testing_SimpleRequest,
45-
logger: Logger,
46-
stats: StatsWithLock) {
42+
init(
43+
config: Grpc_Testing_ClientConfig,
44+
client: Grpc_Testing_BenchmarkServiceClient,
45+
requestMessage: Grpc_Testing_SimpleRequest,
46+
logger: Logger,
47+
stats: StatsWithLock
48+
) {
4749
self.client = client
4850
self.requestMessage = requestMessage
4951
self.logger = logger
@@ -70,7 +72,7 @@ final class AsyncPingPongRequestMaker: RequestMaker {
7072
let endTime = grpcTimeNow()
7173
self.stats.add(latency: endTime - startTime)
7274
if !self.stopRequested,
73-
self.messagesPerStream == 0 || messagesSent < self.messagesPerStream {
75+
self.messagesPerStream == 0 || messagesSent < self.messagesPerStream {
7476
messagesSent += 1
7577
startTime = endTime // Use end of previous request as the start of the next.
7678
streamingCall!.sendMessage(self.requestMessage, promise: nil)

Performance/QPSBenchmark/Sources/QPSBenchmark/Runtime/AsyncUnaryRequestMaker.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ final class AsyncUnaryRequestMaker: RequestMaker {
3232
/// - requestMessage: Pre-made request message to use possibly repeatedly.
3333
/// - logger: Where to log useful diagnostics.
3434
/// - stats: Where to record statistics on latency.
35-
init(config: Grpc_Testing_ClientConfig,
36-
client: Grpc_Testing_BenchmarkServiceClient,
37-
requestMessage: Grpc_Testing_SimpleRequest,
38-
logger: Logger,
39-
stats: StatsWithLock) {
35+
init(
36+
config: Grpc_Testing_ClientConfig,
37+
client: Grpc_Testing_BenchmarkServiceClient,
38+
requestMessage: Grpc_Testing_SimpleRequest,
39+
logger: Logger,
40+
stats: StatsWithLock
41+
) {
4042
self.client = client
4143
self.requestMessage = requestMessage
4244
self.logger = logger

Performance/QPSBenchmark/Sources/QPSBenchmark/Runtime/BenchmarkServiceImpl.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ final class AsyncQPSServerImpl: Grpc_Testing_BenchmarkServiceProvider {
2424

2525
/// One request followed by one response.
2626
/// The server returns the client payload as-is.
27-
func unaryCall(request: Grpc_Testing_SimpleRequest,
28-
context: StatusOnlyCallContext) -> EventLoopFuture<Grpc_Testing_SimpleResponse> {
27+
func unaryCall(
28+
request: Grpc_Testing_SimpleRequest,
29+
context: StatusOnlyCallContext
30+
) -> EventLoopFuture<Grpc_Testing_SimpleResponse> {
2931
do {
3032
return context.eventLoop
3133
.makeSucceededFuture(try AsyncQPSServerImpl.processSimpleRPC(request: request))
@@ -93,8 +95,10 @@ final class AsyncQPSServerImpl: Grpc_Testing_BenchmarkServiceProvider {
9395
}
9496

9597
/// Make a payload for sending back to the client.
96-
private static func makePayload(type: Grpc_Testing_PayloadType,
97-
size: Int) throws -> Grpc_Testing_Payload {
98+
private static func makePayload(
99+
type: Grpc_Testing_PayloadType,
100+
size: Int
101+
) throws -> Grpc_Testing_Payload {
98102
if type != .compressable {
99103
// Making a payload which is not compressable is hard - and not implemented in
100104
// other implementations too.

Performance/QPSBenchmark/Sources/QPSBenchmark/Runtime/RequestMaker.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ protocol RequestMaker {
2727
/// - requestMessage: Pre-made request message to use possibly repeatedly.
2828
/// - logger: Where to log useful diagnostics.
2929
/// - stats: Where to record statistics on latency.
30-
init(config: Grpc_Testing_ClientConfig,
31-
client: Grpc_Testing_BenchmarkServiceClient,
32-
requestMessage: Grpc_Testing_SimpleRequest,
33-
logger: Logger,
34-
stats: StatsWithLock)
30+
init(
31+
config: Grpc_Testing_ClientConfig,
32+
client: Grpc_Testing_BenchmarkServiceClient,
33+
requestMessage: Grpc_Testing_SimpleRequest,
34+
logger: Logger,
35+
stats: StatsWithLock
36+
)
3537

3638
/// Initiate a request sequence to the server.
3739
/// - returns: A future which completes when the request-response sequence is complete.

0 commit comments

Comments
 (0)