Skip to content

Commit 807e7b3

Browse files
committed
Updated SA1622
1 parent 6b2e1ef commit 807e7b3

8 files changed

Lines changed: 92 additions & 105 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1621UnitTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ protected override Project ApplyCompilationOptions(Project project)
415415
return project;
416416
}
417417

418+
protected override IEnumerable<string> GetDisabledDiagnostics()
419+
{
420+
yield return GenericTypeParameterDocumentationAnalyzer.SA1622Descriptor.Id;
421+
}
422+
418423
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
419424
{
420425
yield return new GenericTypeParameterDocumentationAnalyzer();

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1622UnitTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ public class ClassName
123123
/// <summary>
124124
/// Foo
125125
/// </summary>
126-
///<typeparam name=""foo""></typeparam>
127-
///<typeparam name=""bar"">
126+
///<typeparam name=""Ta""></typeparam>
127+
///<typeparam name=""Tb"">
128128
129129
///</typeparam>
130130
$$
131131
}";
132132

133133
var expected = new[]
134134
{
135-
this.CSharpDiagnostic().WithLocation(10, 8),
136-
this.CSharpDiagnostic().WithLocation(11, 8)
135+
this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1622Descriptor).WithLocation(10, 8),
136+
this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1622Descriptor).WithLocation(11, 8)
137137
};
138138

139139
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("$$", declaration), expected, CancellationToken.None).ConfigureAwait(false);
@@ -147,16 +147,16 @@ public async Task TestTypesWithEmptyParamsAsync(string declaration)
147147
/// <summary>
148148
/// Foo
149149
/// </summary>
150-
///<typeparam name=""foo""></typeparam>
151-
///<typeparam name=""bar"">
150+
///<typeparam name=""Ta""></typeparam>
151+
///<typeparam name=""Tb"">
152152
153153
///</typeparam>
154154
public $$";
155155

156156
var expected = new[]
157157
{
158-
this.CSharpDiagnostic().WithLocation(5, 4),
159-
this.CSharpDiagnostic().WithLocation(6, 4)
158+
this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1622Descriptor).WithLocation(5, 4),
159+
this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1622Descriptor).WithLocation(6, 4)
160160
};
161161

162162
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("$$", declaration), expected, CancellationToken.None).ConfigureAwait(false);
@@ -175,8 +175,8 @@ public class ClassName
175175
/// <summary>
176176
/// Foo
177177
/// </summary>
178-
///<typeparam name=""foo""/>
179-
///<typeparam name=""bar"">
178+
///<typeparam name=""Ta""/>
179+
///<typeparam name=""Tb"">
180180
///<para>
181181
///
182182
///</para>
@@ -186,8 +186,8 @@ public class ClassName
186186

187187
var expected = new[]
188188
{
189-
this.CSharpDiagnostic().WithLocation(10, 8),
190-
this.CSharpDiagnostic().WithLocation(11, 8)
189+
this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1622Descriptor).WithLocation(10, 8),
190+
this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1622Descriptor).WithLocation(11, 8)
191191
};
192192

193193
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("$$", declaration), expected, CancellationToken.None).ConfigureAwait(false);
@@ -201,25 +201,25 @@ public async Task TestTypesWithEmptyParams2Async(string declaration)
201201
/// <summary>
202202
/// Foo
203203
/// </summary>
204-
///<typeparam name=""foo""/>
205-
///<typeparam name=""bar"">
204+
///<typeparam name=""Ta""/>
205+
///<typeparam name=""Tb"">
206206
///<para>
207207
///
208208
///</para>
209209
public $$";
210210

211211
var expected = new[]
212212
{
213-
this.CSharpDiagnostic().WithLocation(5, 4),
214-
this.CSharpDiagnostic().WithLocation(6, 4)
213+
this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1622Descriptor).WithLocation(5, 4),
214+
this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1622Descriptor).WithLocation(6, 4)
215215
};
216216

217217
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("$$", declaration), expected, CancellationToken.None).ConfigureAwait(false);
218218
}
219219

220220
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
221221
{
222-
yield return new SA1622GenericTypeParameterDocumentationMustHaveText();
222+
yield return new GenericTypeParameterDocumentationAnalyzer();
223223
}
224224
}
225225
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.Designer.cs

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@
162162
<data name="SA1621Title" xml:space="preserve">
163163
<value>Generic type parameter documentation must declare parameter name</value>
164164
</data>
165+
<data name="SA1622Description" xml:space="preserve">
166+
<value>A &lt;typeparam&gt; tag within the Xml header documentation for a generic C# element is empty.</value>
167+
</data>
168+
<data name="SA1622MessageFormat" xml:space="preserve">
169+
<value>Generic type parameter documentation must have text.</value>
170+
</data>
171+
<data name="SA1622Title" xml:space="preserve">
172+
<value>Generic type parameter documentation must have text</value>
173+
</data>
165174
<data name="SA1623Description" xml:space="preserve">
166175
<value>The documentation text within a C# property’s &lt;summary&gt; tag does not match the accessors within the property.</value>
167176
</data>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/GenericTypeParameterDocumentationAnalyzer.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1515
using StyleCop.Analyzers.Helpers;
1616

1717
/// <summary>
18-
/// Analyzer that covers generic typeparam documentation checks. This currently includes SA1620, SA1621.
18+
/// Analyzer that covers generic typeparam documentation checks. This currently includes SA1620, SA1621, and SA1622.
1919
/// </summary>
2020
[DiagnosticAnalyzer(LanguageNames.CSharp)]
2121
internal class GenericTypeParameterDocumentationAnalyzer : DiagnosticAnalyzer
@@ -33,6 +33,12 @@ internal class GenericTypeParameterDocumentationAnalyzer : DiagnosticAnalyzer
3333
private static readonly LocalizableString SA1621Description = new LocalizableResourceString(nameof(DocumentationResources.SA1621Description), DocumentationResources.ResourceManager, typeof(DocumentationResources));
3434
private static readonly string SA1621HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1621.md";
3535

36+
private static readonly string SA1622DiagnosticId = "SA1622";
37+
private static readonly LocalizableString SA1622Title = new LocalizableResourceString(nameof(DocumentationResources.SA1622Title), DocumentationResources.ResourceManager, typeof(DocumentationResources));
38+
private static readonly LocalizableString SA1622MessageFormat = new LocalizableResourceString(nameof(DocumentationResources.SA1622MessageFormat), DocumentationResources.ResourceManager, typeof(DocumentationResources));
39+
private static readonly LocalizableString SA1622Description = new LocalizableResourceString(nameof(DocumentationResources.SA1622Description), DocumentationResources.ResourceManager, typeof(DocumentationResources));
40+
private static readonly string SA1622HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1622.md";
41+
3642
private static readonly Action<SyntaxNodeAnalysisContext> TypeDeclarationAction = HandleTypeDeclaration;
3743
private static readonly Action<SyntaxNodeAnalysisContext> DelegateDeclarationAction = HandleDelegateDeclaration;
3844
private static readonly Action<SyntaxNodeAnalysisContext> MethodDeclarationAction = HandleMethodDeclaration;
@@ -58,9 +64,16 @@ internal class GenericTypeParameterDocumentationAnalyzer : DiagnosticAnalyzer
5864
public static DiagnosticDescriptor SA1621Descriptor { get; } =
5965
new DiagnosticDescriptor(SA1621DiagnosticId, SA1621Title, SA1621MessageFormat, AnalyzerCategory.DocumentationRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, SA1621Description, SA1621HelpLink);
6066

67+
/// <summary>
68+
/// Gets the descriptor for SA1622.
69+
/// </summary>
70+
/// <value>The <see cref="DiagnosticDescriptor"/> for SA1621.</value>
71+
public static DiagnosticDescriptor SA1622Descriptor { get; } =
72+
new DiagnosticDescriptor(SA1622DiagnosticId, SA1622Title, SA1622MessageFormat, AnalyzerCategory.DocumentationRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, SA1622Description, SA1622HelpLink);
73+
6174
/// <inheritdoc/>
6275
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
63-
ImmutableArray.Create(SA1620MissingTypeParameterDescriptor, SA1621Descriptor);
76+
ImmutableArray.Create(SA1620MissingTypeParameterDescriptor, SA1621Descriptor, SA1622Descriptor);
6477

6578
/// <inheritdoc/>
6679
public override void Initialize(AnalysisContext context)
@@ -136,6 +149,14 @@ private static void HandleDeclaration(SyntaxNodeAnalysisContext context, SyntaxN
136149
{
137150
var documentedParameterName = typeParameterAttributes[i].Attribute(XmlCommentHelper.NameArgumentName)?.Value;
138151
HandleTypeParamElement(context, documentedParameterName, i, typeParameterList, includeElement.GetLocation());
152+
153+
if (XmlCommentHelper.IsConsideredEmpty(typeParameterAttributes[i]))
154+
{
155+
context.ReportDiagnostic(
156+
Diagnostic.Create(
157+
SA1622Descriptor,
158+
includeElement.GetLocation()));
159+
}
139160
}
140161
}
141162
else
@@ -152,6 +173,14 @@ private static void HandleDeclaration(SyntaxNodeAnalysisContext context, SyntaxN
152173

153174
var location = nameAttribute?.Identifier?.GetLocation() ?? typeParameterTags[i].GetLocation();
154175
HandleTypeParamElement(context, documentedParameterName, i, typeParameterList, location);
176+
177+
if (XmlCommentHelper.IsConsideredEmpty(typeParameterTags[i], true))
178+
{
179+
context.ReportDiagnostic(
180+
Diagnostic.Create(
181+
SA1622Descriptor,
182+
typeParameterTags[i].GetLocation()));
183+
}
155184
}
156185
}
157186
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1622GenericTypeParameterDocumentationMustHaveText.cs

Lines changed: 0 additions & 83 deletions
This file was deleted.

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/XmlCommentHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ internal static bool IsConsideredEmpty(DocumentationCommentTriviaSyntax xmlComme
7171
/// A comment is empty if it does not have any text in any XML element and it does not have an empty XML element in it.
7272
/// </summary>
7373
/// <param name="xmlSyntax">The xmlSyntax that should be checked</param>
74+
/// <param name="considerEmptyElements">Flag indicating if empty elements should be considered or assumed non-empty.</param>
7475
/// <returns>true, if the comment should be considered empty, false otherwise.</returns>
75-
internal static bool IsConsideredEmpty(XmlNodeSyntax xmlSyntax)
76+
internal static bool IsConsideredEmpty(XmlNodeSyntax xmlSyntax, bool considerEmptyElements = false)
7677
{
7778
var text = xmlSyntax as XmlTextSyntax;
7879
if (text != null)
@@ -120,7 +121,7 @@ internal static bool IsConsideredEmpty(XmlNodeSyntax xmlSyntax)
120121
if (emptyElement != null)
121122
{
122123
// This includes <inheritdoc/>
123-
return false;
124+
return considerEmptyElements;
124125
}
125126

126127
var processingElement = xmlSyntax as XmlProcessingInstructionSyntax;

StyleCop.Analyzers/StyleCop.Analyzers/StyleCop.Analyzers.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
<Compile Include="DocumentationRules\SA1617VoidReturnValueMustNotBeDocumented.cs" />
8484
<Compile Include="DocumentationRules\SA1618GenericTypeParametersMustBeDocumented.cs" />
8585
<Compile Include="DocumentationRules\SA1619GenericTypeParametersMustBeDocumentedPartialClass.cs" />
86-
<Compile Include="DocumentationRules\SA1622GenericTypeParameterDocumentationMustHaveText.cs" />
8786
<Compile Include="DocumentationRules\SA1625ElementDocumentationMustNotBeCopiedAndPasted.cs" />
8887
<Compile Include="DocumentationRules\SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes.cs" />
8988
<Compile Include="DocumentationRules\SA1627DocumentationTextMustNotBeEmpty.cs" />

0 commit comments

Comments
 (0)