Skip to content

Commit

Permalink
Don't render just spaces in a line
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
glbrntt committed Nov 13, 2024
1 parent c3f09df commit 3efc563
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Sources/GRPCCodeGen/Internal/Renderer/TextBasedRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ final class StringCodeWriter {
if nextWriteAppendsToLastLine && !lines.isEmpty {
let existingLine = lines.removeLast()
newLine = existingLine + line
} else if line.isEmpty {
// Skip indentation to avoid trailing whitespace on blank lines.
newLine = line
} else {
let indentation = Array(repeating: " ", count: self.indentation * level).joined()
newLine = indentation + line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ final class ServerCodeTranslatorSnippetBasedTests: XCTestCase {
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.StreamingServerResponse<NamespaceA_ServiceAResponse>
/// Documentation for outputStreamingMethod
func outputStreaming(
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
Expand Down Expand Up @@ -452,7 +452,7 @@ final class ServerCodeTranslatorSnippetBasedTests: XCTestCase {
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse<NamespaceA_ServiceAResponse>
/// Documentation for outputStreamingMethod
func outputStreaming(
request: GRPCCore.ServerRequest<NamespaceA_ServiceARequest>,
Expand All @@ -472,7 +472,7 @@ final class ServerCodeTranslatorSnippetBasedTests: XCTestCase {
)
return GRPCCore.StreamingServerResponse(single: response)
}
internal func outputStreaming(
request: GRPCCore.StreamingServerRequest<NamespaceA_ServiceARequest>,
context: GRPCCore.ServerContext
Expand Down

0 comments on commit 3efc563

Please sign in to comment.