Skip to content

Drop the blank lines around a braced member body [patch] - #182

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/180-trim-braced-body-blank-lines
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/180-trim-braced-body-blank-lines

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #180

What was wrong

TemplateRendering.WriteBody left blank lines out only when it was deciding a body's shape (the contentLines filter). For a braced body it then spliced the factory's whole output. So:

Change

  • WriteBody now trims leading and trailing empty lines before it splices. This covers both the braced path and the comment-only path (Brace a member body that holds only comments or directives [patch] #161). Blank lines inside the body are kept.
  • SpliceFragment is split so that already-split lines can be spliced (SpliceLines).
  • The trim uses Skip/Take rather than a range on the array, because the netstandard2.0 target has no RuntimeHelpers.GetSubArray.

Tests

  • ABracedBodyDropsTheBlankLinesAroundIt: the repro from the issue, inside a class. It expects one blank line between members and each { directly under its signature.
  • ABracedBodyKeepsItsInteriorBlankLinesWhenItsOuterOnesAreDropped
  • ACommentOnlyBodyDropsTheBlankLinesAroundIt

All three fail with the fix reverted. The full suite passes with it (332/332, dotnet test on Linux).


Generated by Claude Code

WriteBody left blank lines out only when deciding a body's shape, then
spliced the factory's whole output. A factory that ended with NewLine()
(the pattern #133 had in mind) added a second blank line between
members, and one that started with NewLine() put a blank line between
the signature and its opening brace. Leading and trailing blank lines
are now trimmed before the body is spliced, for braced and comment-only
bodies alike; blank lines inside the body are kept.

Fixes #180

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3rHMVCnBN5uuK5G3N
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A braced BodyFactory body keeps its leading/trailing blank lines: a blank line before {, and two blank lines between members

2 participants