Repository navigation
Check a template's doc comment before writing the class that holds it [patch] - #193
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
… [patch] The doc-comment attribute checks ran only inside DocComment.WriteTo, so a member, nested class or later class with a line break in a param name, seealso cref or inheritdoc cref threw after the class had been partly written. TemplateBase.Validate now runs those checks for the template's own Documentation, and every Validate override calls it, so ClassTemplate and SourceFileTemplate refuse it before writing anything. Fixes #188 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5kkYGVswnWUL9YgPE
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #188
What was wrong
ClassTemplate.Validateexists to refuse a bad class before writing any of it (#169). It checked the kind, the members and the nested classes, but never the doc comments. The doc-comment attribute checks (a line break in aparam/typeparamname, anexception/seealsocref, or aninheritdoccref) ran only insideDocComment.WriteTo. SoAddClasswrotepublic class C { void A() { } }and then threw on memberB.AddSourceFilewrote the namespace, the usings and all ofclass First, then threw on the second class.Change
DocComment.EnsureAttributesFitOnOneLineis nowinternal void ValidateAttributes().WriteTostill calls it, so a standaloneAddDocumentationbehaves as before.TemplateBase.Validatenow runsDocumentation?.ValidateAttributes(). TheClassTemplate,PropertyTemplateandOperatorTemplateoverrides callbase.Validate()first. That makes the existing up-front validation cover the class itself, every member and every nested class, and throughSourceFileTemplateevery class in the file.Tests
AClassWithAMemberWhoseDocCommentCannotBeWrittenWritesNothing: the issue's first case.B's param name is"a\nb",AddClassthrowsArgumentException, and the CodeBlocker keeps only what it held before.ASourceFileWhoseLaterClassHasADocCommentThatCannotBeWrittenWritesNothing: the issue's second case (SeeAlso"A\nB"on the second class). Nothing is written.ANestedClassWhoseDocCommentCannotBeWrittenLeavesTheOuterClassUnwritten: aninheritdoccref with a line break on a nested class.Templates/changes reverted, all three new tests fail.This PR and #192 (for #190) both branch from
mainand touch different lines ofPropertyTemplate.Validate, so they merge in either order.Generated by Claude Code