Skip to content

Commit

Permalink
Update SwiftFormat version (#1639)
Browse files Browse the repository at this point in the history
Motivation:

Some changes cause the formatter to throw an error while formatting.
This particular bug was fixed in 0.52.0.

Modifications:

- Update the formatter version to 0.52.0
- Update the rules applied to minimise the diff from updating
- Run the formatter

Results:

- Formatter is up-to-date.
  • Loading branch information
glbrntt authored Aug 14, 2023
1 parent 735d88f commit 666e30d
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- name: "Formatting and License Headers check"
run: |
SWIFTFORMAT_VERSION=0.49.4
SWIFTFORMAT_VERSION=0.52.0
git clone --depth 1 --branch "$SWIFTFORMAT_VERSION" "https://github.com/nicklockwood/SwiftFormat" "$HOME/SwiftFormat"
swift build -c release --package-path "$HOME/SwiftFormat" --product swiftformat
export PATH=$PATH:"$(swift build -c release --package-path "$HOME/SwiftFormat" --show-bin-path)"
Expand Down
17 changes: 17 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@

# Put ACLs on declarations within an extension rather than the extension itself.
--extensionacl on-declarations

# Don't remove internal ACLs
--disable redundantInternal

# Don't remove redundant parenstheses, because no all of them are redundant.
--disable redundantParens

# Don't remove static Self
--disable redundantStaticSelf

# Hoisting try and await causes a bunch of issues (and churn) in 0.52.0. Disable
# them for the time being.
--disable hoistTry
--disable hoistAwait

# Disabled as enabling causes a lot of churn.
--disable wrapSingleLineComments
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import UIKit

@UIApplicationMain
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
Expand Down
4 changes: 2 additions & 2 deletions Examples/Google/SpeechToText/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class ViewController: UIViewController {
button.backgroundColor = .darkGray
button.layer.cornerRadius = 15
button.clipsToBounds = true
button.addTarget(self, action: #selector(recordTapped), for: .touchUpInside)
button.addTarget(self, action: #selector(self.recordTapped), for: .touchUpInside)
return button
}()

Expand Down Expand Up @@ -110,7 +110,7 @@ final class ViewController: UIViewController {
self.textView.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide.snp.topMargin)
make.left.right.equalToSuperview()
make.bottom.equalTo(recordButton.snp.top)
make.bottom.equalTo(self.recordButton.snp.top)
}

self.recordButton.snp.makeConstraints { make in
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import PackageDescription
// swiftformat puts the next import before the tools version.
// swiftformat:disable:next sortedImports
// swiftformat:disable:next sortImports
import class Foundation.ProcessInfo

let grpcPackageName = "grpc-swift"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final class AsyncPingPongRequestMaker: AsyncRequestMaker, @unchecked Sendable {
while !self.stopRequested.load(ordering: .relaxed),
self.messagesPerStream == 0 || messagesSent < self.messagesPerStream {
try await streamingCall.requestStream.send(self.requestMessage)
let _ = try await responseStream.next()
_ = try await responseStream.next()
let endTime = grpcTimeNow()
self.stats.add(latency: endTime - startTime)
messagesSent += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ internal final class _StreamingResponseCallContext<Request, Response>:
/// Concrete implementation of `StreamingResponseCallContext` used for testing.
///
/// Simply records all sent messages.
open class StreamingResponseCallContextTestStub<ResponsePayload>: StreamingResponseCallContext<ResponsePayload> {
open class StreamingResponseCallContextTestStub<ResponsePayload>: StreamingResponseCallContext<
ResponsePayload
> {
open var recordedResponses: [ResponsePayload] = []

override open func sendResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Unary: ServerProvidingBenchmark {
let upperBound = min(lowerBound + batchSize, self.requestCount)

let requests = (lowerBound ..< upperBound).map { _ in
client.get(Echo_EchoRequest.with { $0.text = self.requestText }).response
self.client.get(Echo_EchoRequest.with { $0.text = self.requestText }).response
}

messages += requests.count
Expand Down
6 changes: 3 additions & 3 deletions Tests/GRPCTests/ClientInterceptorPipelineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ClientInterceptorPipelineTests: GRPCTestCase {
assertThat(cancelled, .is(false))
cancelled = true
// We don't expect a promise: this cancellation is fired by the pipeline.
assertThat(promise, .is(.nil()))
assertThat(promise, .is(.none()))
},
onRequestPart: { _, _ in
XCTFail("Unexpected request part")
Expand Down Expand Up @@ -202,14 +202,14 @@ class ClientInterceptorPipelineTests: GRPCTestCase {
assertThat(cancellations, .is(0))
cancellations += 1
// We don't expect a promise: this cancellation is fired by the pipeline.
assertThat(promise, .is(.nil()))
assertThat(promise, .is(.none()))
},
onRequestPart: { _, _ in
XCTFail("Unexpected request part")
},
onResponsePart: { part in
// We only expect the end.
assertThat(part.end, .is(.notNil()))
assertThat(part.end, .is(.some()))
}
)

Expand Down
2 changes: 1 addition & 1 deletion Tests/GRPCTests/ConnectionPool/GRPCChannelPoolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ final class GRPCChannelPoolTests: GRPCTestCase {

// If we express no event loop preference then we should not get the loaded loop.
let indifferentLoopRPCs = (1 ... 10).map {
_ in echo.get(.with { $0.text = "" })
_ in self.echo.get(.with { $0.text = "" })
}

XCTAssert(indifferentLoopRPCs.map { $0.eventLoop }.allSatisfy { $0 !== loop })
Expand Down
4 changes: 2 additions & 2 deletions Tests/GRPCTests/GRPCAsyncClientCallTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ class GRPCAsyncClientCallTests: GRPCTestCase {
var responseStreamIterator = update.responseStream.makeAsyncIterator()
for word in ["boyle", "jeffers", "holt"] {
try await update.requestStream.send(.with { $0.text = word })
await assertThat(try await responseStreamIterator.next(), .is(.notNil()))
await assertThat(try await responseStreamIterator.next(), .is(.some()))
}

update.requestStream.finish()

await assertThat(try await responseStreamIterator.next(), .is(.nil()))
await assertThat(try await responseStreamIterator.next(), .is(.none()))

await assertThat(try await update.trailingMetadata, .is(.equalTo(Self.OKTrailingMetadata)))
await assertThat(await update.status, .hasCode(.ok))
Expand Down
2 changes: 1 addition & 1 deletion Tests/GRPCTests/GRPCPingHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ extension PingHandler.Action: Equatable {
extension GRPCPingHandlerTests {
func testSingleAckIsEmittedOnPing() throws {
let client = EmbeddedChannel()
let _ = try client.configureHTTP2Pipeline(mode: .client) { _ in
_ = try client.configureHTTP2Pipeline(mode: .client) { _ in
fatalError("Unexpected inbound stream")
}.wait()

Expand Down
20 changes: 10 additions & 10 deletions Tests/GRPCTests/GRPCWebToHTTP2ServerCodecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase {
)
assertThat(try channel.writeInbound(HTTPServerRequestPart.head(head)), .doesNotThrow())
let headersPayload = try channel.readInbound(as: HTTP2Frame.FramePayload.self)
assertThat(headersPayload, .notNil(.headers(.contains(":path", [path]))))
assertThat(headersPayload, .some(.headers(.contains(":path", [path]))))
}

private func receiveBytes(
Expand All @@ -59,22 +59,22 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase {

if let expectedBytes = expectedBytes {
let dataPayload = try channel.readInbound(as: HTTP2Frame.FramePayload.self)
assertThat(dataPayload, .notNil(.data(buffer: ByteBuffer(bytes: expectedBytes))))
assertThat(dataPayload, .some(.data(buffer: ByteBuffer(bytes: expectedBytes))))
}
}

private func receiveEnd(on channel: EmbeddedChannel) throws {
assertThat(try channel.writeInbound(HTTPServerRequestPart.end(nil)), .doesNotThrow())
let dataEndPayload = try channel.readInbound(as: HTTP2Frame.FramePayload.self)
assertThat(dataEndPayload, .notNil(.data(buffer: ByteBuffer(), endStream: true)))
assertThat(dataEndPayload, .some(.data(buffer: ByteBuffer(), endStream: true)))
}

private func sendResponseHeaders(on channel: EmbeddedChannel) throws {
let responseHeaders: HPACKHeaders = [":status": "200"]
let headerPayload: HTTP2Frame.FramePayload = .headers(.init(headers: responseHeaders))
assertThat(try channel.writeOutbound(headerPayload), .doesNotThrow())
let responseHead = try channel.readOutbound(as: HTTPServerResponsePart.self)
assertThat(responseHead, .notNil(.head(status: .ok)))
assertThat(responseHead, .some(.head(status: .ok)))
}

private func sendTrailersOnlyResponse(on channel: EmbeddedChannel) throws {
Expand All @@ -83,9 +83,9 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase {

assertThat(try channel.writeOutbound(headerPayload), .doesNotThrow())
let responseHead = try channel.readOutbound(as: HTTPServerResponsePart.self)
assertThat(responseHead, .notNil(.head(status: .ok)))
assertThat(responseHead, .some(.head(status: .ok)))
let end = try channel.readOutbound(as: HTTPServerResponsePart.self)
assertThat(end, .notNil(.end()))
assertThat(end, .some(.end()))
}

private func sendBytes(
Expand All @@ -99,9 +99,9 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase {

if let expectedBytes = expectedBytes {
let expectedBuffer = ByteBuffer(bytes: expectedBytes)
assertThat(try channel.readOutbound(), .notNil(.body(.is(expectedBuffer))))
assertThat(try channel.readOutbound(), .some(.body(.is(expectedBuffer))))
} else {
assertThat(try channel.readOutbound(as: HTTPServerResponsePart.self), .doesNotThrow(.nil()))
assertThat(try channel.readOutbound(as: HTTPServerResponsePart.self), .doesNotThrow(.none()))
}
}

Expand All @@ -115,10 +115,10 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase {
assertThat(try channel.writeOutbound(headersPayload), .doesNotThrow())

if let expectedBytes = expectedBytes {
assertThat(try channel.readOutbound(), .notNil(.body(.is(expectedBytes))))
assertThat(try channel.readOutbound(), .some(.body(.is(expectedBytes))))
}

assertThat(try channel.readOutbound(), .notNil(.end()))
assertThat(try channel.readOutbound(), .some(.end()))
}

func testWebBinaryHappyPath() throws {
Expand Down
14 changes: 7 additions & 7 deletions Tests/GRPCTests/ServerInterceptorPipelineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ServerInterceptorPipelineTests: GRPCTestCase {
onRequestPart: { requestParts.append($0) },
onResponsePart: { part, promise in
responseParts.append(part)
assertThat(promise, .is(.nil()))
assertThat(promise, .is(.none()))
}
)

Expand All @@ -80,7 +80,7 @@ class ServerInterceptorPipelineTests: GRPCTestCase {
assertThat(responseParts, .hasCount(3))
assertThat(responseParts[0].metadata, .is([:]))
assertThat(responseParts[1].message, .is("bar"))
assertThat(responseParts[2].end, .is(.notNil()))
assertThat(responseParts[2].end, .is(.some()))

// Pipelines should now be closed. We can't send or receive.
let p = self.embeddedEventLoop.makePromise(of: Void.self)
Expand Down Expand Up @@ -110,15 +110,15 @@ class ServerInterceptorPipelineTests: GRPCTestCase {

// Check the request parts are there.
assertThat(recorder.requestParts, .hasCount(3))
assertThat(recorder.requestParts[0].metadata, .is(.notNil()))
assertThat(recorder.requestParts[1].message, .is(.notNil()))
assertThat(recorder.requestParts[0].metadata, .is(.some()))
assertThat(recorder.requestParts[1].message, .is(.some()))
assertThat(recorder.requestParts[2].isEnd, .is(true))

// Check the response parts are there.
assertThat(recorder.responseParts, .hasCount(3))
assertThat(recorder.responseParts[0].metadata, .is(.notNil()))
assertThat(recorder.responseParts[1].message, .is(.notNil()))
assertThat(recorder.responseParts[2].end, .is(.notNil()))
assertThat(recorder.responseParts[0].metadata, .is(.some()))
assertThat(recorder.responseParts[1].message, .is(.some()))
assertThat(recorder.responseParts[2].end, .is(.some()))
}
}

Expand Down
20 changes: 10 additions & 10 deletions Tests/GRPCTests/ServerInterceptorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class ServerInterceptorTests: GRPCTestCase {
handler.receiveEnd()

// Expect responses.
assertThat(self.recorder.metadata, .is(.notNil()))
assertThat(self.recorder.metadata, .is(.some()))
assertThat(self.recorder.messages.count, .is(1))
assertThat(self.recorder.status, .is(.notNil()))
assertThat(self.recorder.status, .is(.some()))

// We expect 2 request parts: the provider responds before it sees end, that's fine.
assertThat(recordingInterceptor.requestParts, .hasCount(2))
Expand All @@ -123,9 +123,9 @@ class ServerInterceptorTests: GRPCTestCase {
handler.receiveEnd()

// Get the responses.
assertThat(self.recorder.metadata, .is(.notNil()))
assertThat(self.recorder.metadata, .is(.some()))
assertThat(self.recorder.messages.count, .is(1))
assertThat(self.recorder.status, .is(.notNil()))
assertThat(self.recorder.status, .is(.some()))
}

func testClientStreamingFromInterceptor() throws {
Expand All @@ -140,9 +140,9 @@ class ServerInterceptorTests: GRPCTestCase {
handler.receiveEnd()

// Get the responses.
assertThat(self.recorder.metadata, .is(.notNil()))
assertThat(self.recorder.metadata, .is(.some()))
assertThat(self.recorder.messages.count, .is(1))
assertThat(self.recorder.status, .is(.notNil()))
assertThat(self.recorder.status, .is(.some()))
}

func testServerStreamingFromInterceptor() throws {
Expand All @@ -155,9 +155,9 @@ class ServerInterceptorTests: GRPCTestCase {
handler.receiveEnd()

// Get the responses.
assertThat(self.recorder.metadata, .is(.notNil()))
assertThat(self.recorder.metadata, .is(.some()))
assertThat(self.recorder.messages.count, .is(3))
assertThat(self.recorder.status, .is(.notNil()))
assertThat(self.recorder.status, .is(.some()))
}

func testBidirectionalStreamingFromInterceptor() throws {
Expand All @@ -172,9 +172,9 @@ class ServerInterceptorTests: GRPCTestCase {
handler.receiveEnd()

// Get the responses.
assertThat(self.recorder.metadata, .is(.notNil()))
assertThat(self.recorder.metadata, .is(.some()))
assertThat(self.recorder.messages.count, .is(3))
assertThat(self.recorder.status, .is(.notNil()))
assertThat(self.recorder.status, .is(.some()))
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/GRPCTests/ServerThrowingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class ServerThrowingTests: EchoTestCaseBase {
}
}
XCTAssertThrowsError(try call.response.wait()) {
XCTAssertEqual(expectedError, $0 as? GRPCStatus)
XCTAssertEqual(self.expectedError, $0 as? GRPCStatus)
}
}

Expand All @@ -170,7 +170,7 @@ class ServerThrowingTests: EchoTestCaseBase {
// With `ErrorReturningEchoProvider` we actually _return_ a response, which means that the `response` future
// will _not_ fail, so in that case this test doesn't apply.
XCTAssertThrowsError(try call.response.wait()) {
XCTAssertEqual(expectedError, $0 as? GRPCStatus)
XCTAssertEqual(self.expectedError, $0 as? GRPCStatus)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/GRPCTests/ServerWebTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ extension ServerWebTests {
var expectedData = Data()
var index = 0
message.split(separator: " ").forEach { component in
expectedData.append(gRPCEncodedEchoRequest("Swift echo expand (\(index)): \(component)"))
expectedData.append(self.gRPCEncodedEchoRequest("Swift echo expand (\(index)): \(component)"))
index += 1
}
expectedData.append(self.gRPCWebTrailers())
Expand Down
Loading

0 comments on commit 666e30d

Please sign in to comment.