-
Notifications
You must be signed in to change notification settings - Fork 14
Document whitespace-suppression behavior on CodeBlock #4571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -46,6 +46,9 @@ public CodeBlock() | |||||
|
|
||||||
| /// <summary>Adds another code block to this one, separated by newlines.</summary> | ||||||
| /// <param name="block">The block to add.</param> | ||||||
| /// <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> | ||||||
| public void AddBlock(CodeBlock block) => Write($"\n{block}\n"); | ||||||
|
|
||||||
| /// <summary>Creates a new code block with the content indented by 4 spaces.</summary> | ||||||
|
|
@@ -103,5 +106,11 @@ public void Write(string value) | |||||
|
|
||||||
| /// <summary>Writes the specified value followed by a newline to the code block.</summary> | ||||||
| /// <param name="value">The value to write.</param> | ||||||
| /// <remarks><see cref="Write"/> drops empty and whitespace-only strings, so <c>WriteLine("")</c> | ||||||
| /// and <c>WriteLine(" ")</c> are no-ops. This is intentional: it lets callers interpolate values | ||||||
| /// 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> | ||||||
|
||||||
| /// most one.</remarks> | |
| /// most one and trims leading and trailing whitespace, including leading and trailing newlines.</remarks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).