Document whitespace-suppression behavior on CodeBlock#4571
Document whitespace-suppression behavior on CodeBlock#4571pepone merged 1 commit intoicerpc:mainfrom
Conversation
…ddBlock
WriteLine("") and AddBlock(emptyBlock) are intentionally no-ops: it lets
callers interpolate possibly-empty values without producing stray blank
lines (e.g. WriteLine(\$\" {body.Indent()}\") with empty body). Vertical
whitespace in final output is managed by ToString, which collapses runs
of blank lines to at most one.
Adds <remarks> on both methods so the design intent is visible to
callers who might otherwise expect WriteLine("") to emit a blank line.
There was a problem hiding this comment.
Pull request overview
Clarifies ZeroC.CodeBuilder.CodeBlock whitespace-suppression semantics so callers understand when “empty” writes/blocks are ignored and how final vertical whitespace is normalized.
Changes:
- Documented
AddBlockbehavior when adding empty blocks and howToStringnormalizes vertical whitespace. - Documented
WriteLinebehavior for empty/whitespace-only input (no-op viaWrite) and referencedToStringblank-line collapsing.
| /// <remarks>Adding an empty <see cref="CodeBlock"/> has no effect — no phantom blank-line gap is | ||
| /// inserted. The vertical whitespace between non-empty blocks is normalized by <see cref="ToString"/>, | ||
| /// which collapses runs of blank lines to at most one.</remarks> |
There was a problem hiding this comment.
The remark says adding an empty CodeBlock has no effect, but AddBlock will also effectively ignore blocks that contain only whitespace because interpolation calls CodeBlock.ToString(), which trims whitespace-only lines to empty. Consider clarifying that "empty" here includes whitespace-only content (and may differ from IsEmpty).
| /// <remarks>Adding an empty <see cref="CodeBlock"/> has no effect — no phantom blank-line gap is | |
| /// inserted. The vertical whitespace between non-empty blocks is normalized by <see cref="ToString"/>, | |
| /// which collapses runs of blank lines to at most one.</remarks> | |
| /// <remarks>Adding a <see cref="CodeBlock"/> whose rendered content is empty has no effect — no | |
| /// phantom blank-line gap is inserted. This includes blocks that contain only whitespace, because | |
| /// interpolation calls <see cref="ToString"/>, which normalizes such content to empty; this may | |
| /// differ from <see cref="IsEmpty"/>. The vertical whitespace between non-empty blocks is also | |
| /// normalized by <see cref="ToString"/>, which collapses runs of blank lines to at most one.</remarks> |
| /// that may be empty without producing stray blank lines (for example | ||
| /// <c>WriteLine($" {body.Indent()}")</c> when <c>body</c> is empty). Vertical whitespace in the | ||
| /// final output is managed by <see cref="ToString"/>, which collapses runs of blank lines to at | ||
| /// most one.</remarks> |
There was a problem hiding this comment.
The remarks refer to ToString collapsing runs of blank lines, but ToString also trims leading/trailing whitespace (including newlines) from the final output. If callers might rely on leading/trailing blank lines being preserved, it may be worth calling out the Trim behavior explicitly in the docs.
| /// most one.</remarks> | |
| /// most one and trims leading and trailing whitespace, including leading and trailing newlines.</remarks> |
Clarify
WriteLineandAddBlockbehavior for empty line, empty block