Skip to content

Comment every line of a multi-line copyright, and refuse a multi-line region name [patch] - #152

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/151-multiline-header-and-region
Oct 30, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/151-multiline-header-and-region

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #151

What changed

  • WriteAutoGeneratedHeader used to write // {copyright} once, so only the first line of a multi-line notice was commented. It now splits the copyright into lines and writes // {line} for each one, or a bare // for an empty line. The split happens at every terminator the C# compiler recognises: LF, CRLF, CR, NEL (U+0085), LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029). A single-line copyright gives the same output as before.
  • RegionScope now throws ArgumentException when the name contains any of those terminators. It throws before anything is written, the same validate-first approach as Unknown TypeKind or AccessorKind writes half a declaration before throwing, and an Expression accessor with no BodyFactory emits get => ; #142, so the rest of the name can no longer end up outside the #region directive.
  • New LineTerminators helper (internal). DocComment's private SplitLines has moved here, so all three callers use the same list of terminators. DocComment's behaviour is unchanged.
  • The copyright parameter docs now describe how a multi-line notice is written.

The null check on copyright is now copyright is { Length: > 0 } instead of !string.IsNullOrEmpty(...). On netstandard2.0, IsNullOrEmpty has no nullable annotations, so the old form raised CS8604 when the value was passed to the splitter.

Tests

  • AutoGeneratedHeaderCommentsEveryLineOfAMultiLineCopyright: one data row for each of the six terminators.
  • AutoGeneratedHeaderWritesABlankCopyrightLineAsABareComment: an SPDX line, a blank line, then a holder line.
  • RegionScopeRejectsANameThatSpansLinesBeforeWriting: one row for each terminator. Each row checks that the exception is thrown and that nothing was written.

With the CodeBlockerExtensions.cs and Scopes.cs changes reverted, all 13 new cases fail. With them in place, the full suite passes (236/236, net10.0, Linux). The local Sonar run (-p:CustomAfterMicrosoftCommonProps=.sonarlint/sonar-local.props) reports no new findings in the library.

Notes


Generated by Claude Code

… region name [patch]

WriteAutoGeneratedHeader prefixed the whole copyright with "// " once, so
the second and later lines of a multi-line notice were written as code and
the generated file failed to compile. Each line is now written as its own
comment, split at every terminator the C# compiler recognises (LF, CRLF,
CR, NEL, LINE SEPARATOR and PARAGRAPH SEPARATOR), and an empty line becomes
a bare "//".

RegionScope had the same root cause: a name containing a line break left
the rest of the name outside the #region directive. It now throws
ArgumentException before writing anything.

The line splitting DocComment already used moves into an internal
LineTerminators helper that all three share.

Fixes #151

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit f7eead9 into main Oct 30, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/151-multiline-header-and-region branch October 30, 2026 02:46
matt-edmondson added a commit that referenced this pull request Nov 4, 2026
…tch] (#155)

DirectiveScope wrote its condition verbatim, so an empty, null or
whitespace condition produced a bare "#if" (CS1517), and a condition with
a line break left the rest of the expression outside the directive as
code. PragmaScope had the same line-break problem with its warning list,
including a single entry of the IEnumerable overload that kept a stray CR.

Both now throw ArgumentException before writing anything, using the same
LineTerminators check RegionScope got in #152. PragmaScope still treats
empty or whitespace warnings as a no-op.

Fixes #154


Claude-Session: https://claude.ai/code/session_017vfJW2yWAiM4Xm9iHUvALj

Co-authored-by: Claude <noreply@anthropic.com>
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.

WriteAutoGeneratedHeader with a multi-line copyright writes the second and later lines as code, so the generated file doesn't compile

2 participants