From a6e872d0c25fdce4a919aa5e0d945d1829154908 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 12:25:06 +0000 Subject: [PATCH] Report an undeclared duplicate doc tag once [patch] DocComment.Validate ran the "does not match any declared" check for every copy of a tag, so two entries for an undeclared y gave that message twice. Run it only on the first copy and leave the later copies to the "documented more than once" message. Fixes ktsu-dev/CodeBlocker#171 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017vfJW5LkA4KtEKYNbjk5tz --- CodeBlocker.Test/DocCommentTests.cs | 31 +++++++++++++++++++++++++++++ CodeBlocker/Templates/DocComment.cs | 3 +-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CodeBlocker.Test/DocCommentTests.cs b/CodeBlocker.Test/DocCommentTests.cs index f802433..9c535fa 100644 --- a/CodeBlocker.Test/DocCommentTests.cs +++ b/CodeBlocker.Test/DocCommentTests.cs @@ -204,6 +204,37 @@ public void ValidationReportsADuplicateTag() Assert.Contains("more than once", issues[0]); } + [TestMethod] + public void ValidationReportsADuplicateUndeclaredTagOnce() + { + DocComment documentation = new(); + documentation.Params.Add(new DocTag { Name = "y", Text = "First." }); + documentation.Params.Add(new DocTag { Name = "y", Text = "Again." }); + documentation.Params.Add(new DocTag { Name = "y", Text = "Third." }); + + IReadOnlyList issues = documentation.Validate(["x"], []); + + Assert.HasCount(4, issues); + Assert.AreEqual(" does not match any declared parameter.", issues[0]); + Assert.AreEqual(" is documented more than once.", issues[1]); + Assert.AreEqual(" is documented more than once.", issues[2]); + Assert.AreEqual("The parameter 'x' has no entry.", issues[3]); + } + + [TestMethod] + public void ValidationReportsADuplicateUndeclaredTypeParameterTagOnce() + { + DocComment documentation = new(); + documentation.TypeParams.Add(new DocTag { Name = "U", Text = "First." }); + documentation.TypeParams.Add(new DocTag { Name = "U", Text = "Again." }); + + IReadOnlyList issues = documentation.Validate([], []); + + Assert.HasCount(2, issues); + Assert.AreEqual(" does not match any declared type parameter.", issues[0]); + Assert.AreEqual(" is documented more than once.", issues[1]); + } + [TestMethod] public void ANamedTagWithEmptyTextIsStillWritten() { diff --git a/CodeBlocker/Templates/DocComment.cs b/CodeBlocker/Templates/DocComment.cs index d82f857..505c3e4 100644 --- a/CodeBlocker/Templates/DocComment.cs +++ b/CodeBlocker/Templates/DocComment.cs @@ -167,8 +167,7 @@ void Check(Collection tags, HashSet declared, string tagName, st { issues.Add($"<{tagName} name=\"{name}\"> is documented more than once."); } - - if (!declared.Contains(name)) + else if (!declared.Contains(name)) { issues.Add($"<{tagName} name=\"{name}\"> does not match any declared {what}."); }