Browse Source

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.
George Barnett 3 years ago
parent
commit
a1fd0026e3

+ 12 - 12
Sources/protoc-gen-grpc-swift/Generator-Client.swift

@@ -341,7 +341,7 @@ extension Generator {
 }
 
 extension Generator {
-  fileprivate func printFakeResponseStreams() {
+  private func printFakeResponseStreams() {
     for method in self.service.methods {
       self.println()
 
@@ -356,7 +356,7 @@ extension Generator {
     }
   }
 
-  fileprivate func printUnaryResponse() {
+  private func printUnaryResponse() {
     self.printResponseStream(isUnary: true)
     self.println()
     self.printEnqueueUnaryResponse(isUnary: true)
@@ -364,7 +364,7 @@ extension Generator {
     self.printHasResponseStreamEnqueued()
   }
 
-  fileprivate func printStreamingResponse() {
+  private func printStreamingResponse() {
     self.printResponseStream(isUnary: false)
     self.println()
     self.printEnqueueUnaryResponse(isUnary: false)
@@ -443,7 +443,7 @@ extension Generator {
     self.println("}")
   }
 
-  fileprivate func printTestClient() {
+  private func printTestClient() {
     self
       .println(
         "\(self.access) final class \(self.testClientClassName): \(self.clientProtocolName) {"
@@ -482,14 +482,14 @@ extension Generator {
   }
 }
 
-private extension Generator {
-  var streamType: StreamingType {
+extension Generator {
+  private var streamType: StreamingType {
     return streamingType(self.method)
   }
 }
 
 extension Generator {
-  fileprivate var methodArguments: [String] {
+  private var methodArguments: [String] {
     switch self.streamType {
     case .unary:
       return [
@@ -514,7 +514,7 @@ extension Generator {
     }
   }
 
-  fileprivate var methodArgumentsWithoutDefaults: [String] {
+  private var methodArgumentsWithoutDefaults: [String] {
     return self.methodArguments.map { arg in
       // Remove default arg from call options.
       if arg == "callOptions: CallOptions? = nil" {
@@ -525,13 +525,13 @@ extension Generator {
     }
   }
 
-  fileprivate var methodArgumentsWithoutCallOptions: [String] {
+  private var methodArgumentsWithoutCallOptions: [String] {
     return self.methodArguments.filter {
       !$0.hasPrefix("callOptions: ")
     }
   }
 
-  fileprivate var methodReturnType: String {
+  private var methodReturnType: String {
     switch self.streamType {
     case .unary:
       return "UnaryCall<\(self.methodInputName), \(self.methodOutputName)>"
@@ -548,8 +548,8 @@ extension Generator {
   }
 }
 
-private extension StreamingType {
-  var name: String {
+extension StreamingType {
+  fileprivate var name: String {
     switch self {
     case .unary:
       return "Unary"

+ 9 - 5
Sources/protoc-gen-grpc-swift/Generator-Names.swift

@@ -17,8 +17,10 @@ import Foundation
 import SwiftProtobuf
 import SwiftProtobufPluginLibrary
 
-internal func nameForPackageService(_ file: FileDescriptor,
-                                    _ service: ServiceDescriptor) -> String {
+internal func nameForPackageService(
+  _ file: FileDescriptor,
+  _ service: ServiceDescriptor
+) -> String {
   if !file.package.isEmpty {
     return SwiftProtobufNamer().typePrefix(forFile: file) + service.name
   } else {
@@ -26,9 +28,11 @@ internal func nameForPackageService(_ file: FileDescriptor,
   }
 }
 
-internal func nameForPackageServiceMethod(_ file: FileDescriptor,
-                                          _ service: ServiceDescriptor,
-                                          _ method: MethodDescriptor) -> String {
+internal func nameForPackageServiceMethod(
+  _ file: FileDescriptor,
+  _ service: ServiceDescriptor,
+  _ method: MethodDescriptor
+) -> String {
   return nameForPackageService(file, service) + method.name
 }
 

+ 5 - 2
Sources/protoc-gen-grpc-swift/main.swift

@@ -61,8 +61,11 @@ enum FileNaming: String {
   case DropPath
 }
 
-func outputFileName(component: String, fileDescriptor: FileDescriptor,
-                    fileNamingOption: FileNaming) -> String {
+func outputFileName(
+  component: String,
+  fileDescriptor: FileDescriptor,
+  fileNamingOption: FileNaming
+) -> String {
   let ext = "." + component + ".swift"
   let pathParts = splitPath(pathname: fileDescriptor.name)
   switch fileNamingOption {

+ 2 - 2
scripts/format.sh

@@ -21,8 +21,8 @@ REPO="$HERE/.."
 SWIFTFORMAT_DIR="$HERE/.swiftformat-source"
 
 # Important: if this is changed then make sure to update the version
-# in .travis-install.sh as well!
-SWIFTFORMAT_VERSION=0.46.3
+# in the .github/workflows/ci.yaml as well!
+SWIFTFORMAT_VERSION=0.49.4
 
 # Clone SwiftFormat if we don't already have it.
 if [ ! -d "$SWIFTFORMAT_DIR" ]; then