Skip to content

Commit 3efc563

Browse files
committed
Don't render just spaces in a line
Motivation: If a blank line is render, the text based renderer will include the current indentation level resulting in lines with just spaces. Modifications: - Don't include indentation if the line to render is otherwise empty Result: Less trailing whitespace.
1 parent c3f09df commit 3efc563

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: Sources/GRPCCodeGen/Internal/Renderer/TextBasedRenderer.swift

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ final class StringCodeWriter {
7070
if nextWriteAppendsToLastLine && !lines.isEmpty {
7171
let existingLine = lines.removeLast()
7272
newLine = existingLine + line
73+
} else if line.isEmpty {
74+
// Skip indentation to avoid trailing whitespace on blank lines.
75+
newLine = line
7376
} else {
7477
let indentation = Array(repeating: " ", count: self.indentation * level).joined()
7578
newLine = indentation + line

Diff for: Tests/GRPCCodeGenTests/Internal/Translator/ServerCodeTranslatorSnippetBasedTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ final class ServerCodeTranslatorSnippetBasedTests: XCTestCase {
408408
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
409409
context: GRPCCore.ServerContext
410410
) async throws -> GRPCCore.StreamingServerResponse<NamespaceA_ServiceAResponse>
411-
411+
412412
/// Documentation for outputStreamingMethod
413413
func outputStreaming(
414414
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
@@ -452,7 +452,7 @@ final class ServerCodeTranslatorSnippetBasedTests: XCTestCase {
452452
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
453453
context: GRPCCore.ServerContext
454454
) async throws -> GRPCCore.ServerResponse<NamespaceA_ServiceAResponse>
455-
455+
456456
/// Documentation for outputStreamingMethod
457457
func outputStreaming(
458458
request: GRPCCore.ServerRequest<NamespaceA_ServiceARequest>,
@@ -472,7 +472,7 @@ final class ServerCodeTranslatorSnippetBasedTests: XCTestCase {
472472
)
473473
return GRPCCore.StreamingServerResponse(single: response)
474474
}
475-
475+
476476
internal func outputStreaming(
477477
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
478478
context: GRPCCore.ServerContext

0 commit comments

Comments
 (0)