Skip to content

Keep the next line indented when NewLine() ends a partial Write() [patch] - #116

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/newline-after-partial-write
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/newline-after-partial-write

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #115

What changed

  • CodeBlocker now tracks whether a line is under way. A non-empty Write sets the flag, and WriteLine/NewLine clear it.
  • NewLine() ends a line that is under way with IndentedTextWriter.WriteLine(). That call writes no tabs in that state and re-arms the indent for the next line. At the start of a line it still uses WriteLineNoTabs, so blank lines stay free of whitespace.
  • WriteExpressionBody skips leading blank lines, as it already skipped trailing ones. => no longer dangles, with a trailing space, at the end of the declaration line.
  • The comment in WriteConstraints described the old NewLine() hazard, so it has been trimmed.

Tests

  • NewLineAfterAPartialWriteKeepsTheNextLineIndented is the core reproduction from the issue.
  • NewLineAtTheStartOfALineStillWritesNoIndentation checks that a blank line after a partial write stays unindented and that the line after it is indented.
  • AnExpressionBodyStartingWithABlankLineKeepsItsFirstLineOnTheDeclaration is the template reproduction from the issue.

With the library changes reverted, all three new tests fail. With them applied, the full suite passes, 185 of 185 on net10.0. NewLineShouldAddEmptyLine, BlankLineUsesTheConfiguredTerminator and AMultiLineExpressionBodyKeepsABlankLineWithoutIndentingIt pass unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_018fKEEvMM2dQpZfMjTCXhRL


Generated by Claude Code

…tch]

NewLine() wrote through IndentedTextWriter.WriteLineNoTabs, which does not
re-arm the pending-tab flag, so after a partial Write() the next line came
out at column zero. CodeBlocker now tracks whether a line is under way and
ends it with WriteLine() in that case, keeping WriteLineNoTabs for blank
lines so they stay free of whitespace.

WriteExpressionBody also skips leading blank lines, as it already skips
trailing ones, so the arrow is no longer left dangling with a trailing
space at the end of the declaration line.

Fixes #115

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 6e931fc into main Sep 27, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/newline-after-partial-write branch September 27, 2026 15:11
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.

NewLine() after a partial Write() makes the next line lose its indentation (also breaks expression bodies that start with a blank line)

2 participants