You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A braced BodyFactory body keeps its leading/trailing blank lines: a blank line before {, and two blank lines between members #180
TemplateRendering.WriteBody (CodeBlocker/Templates/TemplateRendering.cs:280-307) ignores blank lines only when deciding the body's shape (the contentLines filter). For a braced body it then splices the unfiltered body, so a factory's leading and trailing blank lines end up in the output.
varc=newClassTemplate{Name="C"};c.Members.Add(newMethodTemplate{Type="void",Name="A",BodyFactory= b =>{using(newScope(b))b.WriteLine("x();");b.NewLine();}});c.Members.Add(newMethodTemplate{Type="void",Name="B",BodyFactory= b =>{b.NewLine();b.WriteLine("{");b.WriteLine("}");}});
Actual (→ = tab):
→}
→void B()
→{
→}
That gives two blank lines between A and B, and a blank line between void B() and its {.
Expected: one blank line between members, and { directly under the signature.
Why it matters
The output compiles, but it doesn't match the library's own rules. WriteExpressionBody already trims leading and trailing blank lines, and #119/#133 established that blank lines should not shape a body. A trailing NewLine() after a loop, which is the pattern #133 had in mind, now shows up as extra spacing in every generated file. That means formatting churn in generated diffs and failures in any whitespace-sensitive snapshot test.
Suggested fix
In WriteBody, trim leading and trailing empty entries from lines and splice only that range. Blank lines inside the body stay.
Acceptance: the repro above produces exactly one blank line between members and no blank line between a signature and its {. Interior blank lines in a body are preserved.
Priority: Medium. The output still compiles, but the extra blank lines appear in every generated file whose factory ends with a NewLine(), the pattern Render a body of only blank lines as an empty block #133 encourages. That causes churn in generated diffs and breaks whitespace-sensitive snapshot tests.
Area / suggested owner: template rendering (CodeBlocker/Templates/TemplateRendering.cs, WriteBody). I confirmed it in the code: contentLines filters out blank lines only to decide the body's shape, and the braced path then calls SpliceFragment(codeBlocker, body) with the untrimmed body.
Next steps: trim leading and trailing empty entries from lines, splice only that range, and keep interior blank lines. Add the repro from the issue as a test (one blank line between members, { directly under the signature), plus a test that interior blank lines survive.
Activity
matt-edmondson commentedon Nov 3, 2026
Triage
NewLine(), the pattern Render a body of only blank lines as an empty block #133 encourages. That causes churn in generated diffs and breaks whitespace-sensitive snapshot tests.CodeBlocker/Templates/TemplateRendering.cs,WriteBody). I confirmed it in the code:contentLinesfilters out blank lines only to decide the body's shape, and the braced path then callsSpliceFragment(codeBlocker, body)with the untrimmedbody.public void M()(CS0501) #119/Render a body of only blank lines as an empty block #133, which established that blank lines should not shape a body.WriteExpressionBodyalready trims them.WriteBodymethod. Land or rebase on Brace a member body that holds only comments or directives [patch] #161 first to avoid a conflict, and make sure the trimming applies to whatever line set Brace a member body that holds only comments or directives [patch] #161 ends up splicing.Next steps: trim leading and trailing empty entries from
lines, splice only that range, and keep interior blank lines. Add the repro from the issue as a test (one blank line between members,{directly under the signature), plus a test that interior blank lines survive.Generated by Claude Code