From 997ef4f753c36a5c19895670dab0477bed34db31 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 22:28:43 +0000 Subject: [PATCH] Split a copyright at NEL, LINE SEPARATOR and PARAGRAPH SEPARATOR too [patch] WriteFileHeader split the copyright only at CR, LF and CRLF. The C# lexer also ends a line at U+0085, U+2028 and U+2029, so text after one of them left the // comment and the generated file failed to compile. The header is now split at all six terminators. Fixes #39 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017vfJW67iMrjvYtnNY3p2qt --- SourceGeneratorToolkit.Test/GeneratorBaseTests.cs | 3 +++ SourceGeneratorToolkit/GeneratorBase.cs | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/SourceGeneratorToolkit.Test/GeneratorBaseTests.cs b/SourceGeneratorToolkit.Test/GeneratorBaseTests.cs index 38ba293..31897a5 100644 --- a/SourceGeneratorToolkit.Test/GeneratorBaseTests.cs +++ b/SourceGeneratorToolkit.Test/GeneratorBaseTests.cs @@ -289,6 +289,9 @@ public void TheHeaderCarriesTheCopyrightAndTheGeneratedMarker() [DataRow("\n")] [DataRow("\r\n")] [DataRow("\r")] + [DataRow("\u0085")] + [DataRow("\u2028")] + [DataRow("\u2029")] public void AMultiLineCopyrightIsCommentedOnEveryLine(string lineBreak) { string source = HeaderProbe.Write($"Copyright (c) Example.{lineBreak}{lineBreak}All rights reserved."); diff --git a/SourceGeneratorToolkit/GeneratorBase.cs b/SourceGeneratorToolkit/GeneratorBase.cs index 0ba1891..4ef50fe 100644 --- a/SourceGeneratorToolkit/GeneratorBase.cs +++ b/SourceGeneratorToolkit/GeneratorBase.cs @@ -110,9 +110,10 @@ protected static CodeBlocker CreateCodeBlocker() => CodeBlocker.Create(CodeBlocker.DefaultIndentString, NewLines.Lf); /// - /// The line breaks a copyright is split on, longest first so CRLF is one break rather than two. + /// Every line terminator the C# compiler recognises, which a copyright is split on so no text escapes its + /// comment. Longest first, so CRLF is one break rather than two. /// - private static readonly string[] CopyrightLineBreaks = ["\r\n", "\n", "\r"]; + private static readonly string[] CopyrightLineBreaks = ["\r\n", "\n", "\r", "\u0085", "\u2028", "\u2029"]; /// /// Writes the header every generated file starts with. @@ -121,7 +122,8 @@ protected static CodeBlocker CreateCodeBlocker() => /// /// The copyright written above the generated-file marker, without its // prefix. /// or empty writes only the marker. A multi-line copyright is commented - /// line by line, whichever line break it uses, so a consumer's multi-line file header template + /// line by line at every line terminator the C# compiler recognises (CR, LF, CRLF, NEL, + /// LINE SEPARATOR and PARAGRAPH SEPARATOR), so a consumer's multi-line file header template /// still compiles. /// ///