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
WriteAutoGeneratedHeader with a multi-line copyright writes the second and later lines as code, so the generated file doesn't compile #151
WriteAutoGeneratedHeader (CodeBlocker/CodeBlockerExtensions.cs:27-39) prefixes the whole copyright string with // once:
codeBlocker.WriteLine($"// {copyright}");
CodeBlocker.WriteLine(string) passes the text straight to IndentedTextWriter.WriteLine, so only the first line of a multi-line value is commented.
codeBlocker.WriteAutoGeneratedHeader("Copyright (c) 2026 Acme Corp.\nAll rights reserved.");
emits
// Copyright (c) 2026 Acme Corp.
All rights reserved.
// <auto-generated />
All rights reserved. is now top-level code, and the generated file fails to compile (CS0116 and similar). The same happens with \r\n, \r, NEL (U+0085), LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029), because the C# compiler treats all of them as line terminators.
Why it matters
Copyright and licence notices are often more than one line, for example an SPDX identifier plus a holder line.
Generators commonly forward the notice from configuration, such as .editorconfig's file_header_template, which is multi-line by convention.
The header is the first thing written, so every generated file breaks.
#129 fixed this class of bug for doc comments: DocComment.SplitLines (CodeBlocker/Templates/DocComment.cs:233-234) splits on all five terminators. This helper was not covered by that fix.
RegionScope (CodeBlocker/Scopes.cs:114) has the same root cause: it writes #region {name} verbatim. A name containing a line break leaves the rest of the name on its own line as code.
Suggested fix
Split copyright on the same terminators DocComment uses. Extract SplitLines into a shared internal helper.
Write // {line} for each line, and a bare // for an empty line.
Priority: Medium. The output fails to compile, but only when a caller passes a multi-line notice. The parameter is documented as "an optional copyright line", and a caller can work around it by passing only the first line. It isn't Low, though: forwarding a multi-line file_header_template is a natural use, and the failure lands at the top of every generated file.
Area:CodeBlockerExtensions.WriteAutoGeneratedHeader (CodeBlocker/CodeBlockerExtensions.cs). On main it still writes codeBlocker.WriteLine($"// {copyright}"); with no line splitting, so the report is accurate. The same root cause shows up in RegionScope (Scopes.cs), and the shared fix is DocComment.SplitLines (Templates/DocComment.cs).
Next step: implement the fix as the issue describes. Extract SplitLines into an internal helper, write // {line} per line (a bare // for an empty line), and reject a line terminator in a RegionScope name with ArgumentException. Add one test per terminator.
Activity
matt-edmondson commentedon Oct 29, 2026
Triage
file_header_templateis a natural use, and the failure lands at the top of every generated file.CodeBlockerExtensions.WriteAutoGeneratedHeader(CodeBlocker/CodeBlockerExtensions.cs). Onmainit still writescodeBlocker.WriteLine($"// {copyright}");with no line splitting, so the report is accurate. The same root cause shows up inRegionScope(Scopes.cs), and the shared fix isDocComment.SplitLines(Templates/DocComment.cs).get => ;#142 or reviews PR Reject an unknown type or accessor kind, or a bodiless expression accessor, before writing [patch] #150 is a good fit, because rejecting a badRegionScopename follows the same validate-before-write rule.WriteFileHeaderemit code that doesn't compile. A shared line-splitting helper here could serve both, so the two should be fixed consistently.WriteAutoGeneratedHeaderorRegionScope.SplitLinesinto an internal helper, write// {line}per line (a bare//for an empty line), and reject a line terminator in aRegionScopename withArgumentException. Add one test per terminator.Generated by Claude Code