From a194b31498db75a6af6845b48b6bd8245bc1a2d9 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Tue, 7 Jan 2025 11:18:09 +0000 Subject: [PATCH] Use a nil Descriptor list for empty proto files Motivation: If a proto file contains no services we include a comment indicating this is expected. At the moment this has two empty lines above it. Modifications: Store `nil` instead of an empty array of `Descriptor`s into the `FileDescription`. Result: Only one empty line above the comment. --- .../Internal/Translator/IDLToStructuredSwiftTranslator.swift | 4 ++-- .../IDLToStructuredSwiftTranslatorSnippetBasedTests.swift | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift index 612768cdd..eccc65ba3 100644 --- a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift +++ b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift @@ -74,9 +74,9 @@ package struct IDLToStructuredSwiftTranslator: Translator { } } - let imports: [ImportDescription] + let imports: [ImportDescription]? if codeGenerationRequest.services.isEmpty { - imports = [] + imports = nil codeBlocks.append( CodeBlock(comment: .inline("This file contained no services.")) ) diff --git a/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift b/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift index d30fe8954..8f4509b50 100644 --- a/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift +++ b/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift @@ -145,7 +145,6 @@ final class IDLToStructuredSwiftTranslatorSnippetBasedTests: XCTestCase { """ /// Some really exciting license header 2023. - // This file contained no services. """ try self.assertIDLToStructuredSwiftTranslation(