Skip to content

Commit c398c6b

Browse files
Merge f18c68a into b029a8e
2 parents b029a8e + f18c68a commit c398c6b

File tree

3 files changed

+14
-48
lines changed

3 files changed

+14
-48
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
1010
using Microsoft.CodeAnalysis.CSharp;
1111
using Microsoft.CodeAnalysis.Testing;
1212
using StyleCop.Analyzers.DocumentationRules;
13+
using StyleCop.Analyzers.Test.Helpers;
1314
using Xunit;
1415
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1516
StyleCop.Analyzers.DocumentationRules.SA1600ElementsMustBeDocumented,
@@ -40,52 +41,19 @@ public async Task TestRegressionMethodGlobalNamespaceAsync(string code)
4041
await VerifyCSharpDiagnosticAsync(this.LanguageVersion, testCode, expected, CancellationToken.None).ConfigureAwait(false);
4142
}
4243

43-
[Fact]
44-
public async Task TestClassWithoutDocumentationAsync()
45-
{
46-
await this.TestTypeWithoutDocumentationAsync("class", false).ConfigureAwait(false);
47-
}
48-
49-
[Fact]
50-
public async Task TestStructWithoutDocumentationAsync()
51-
{
52-
await this.TestTypeWithoutDocumentationAsync("struct", false).ConfigureAwait(false);
53-
}
54-
55-
[Fact]
56-
public async Task TestEnumWithoutDocumentationAsync()
57-
{
58-
await this.TestTypeWithoutDocumentationAsync("enum", false).ConfigureAwait(false);
59-
}
60-
61-
[Fact]
62-
public async Task TestInterfaceWithoutDocumentationAsync()
63-
{
64-
await this.TestTypeWithoutDocumentationAsync("interface", true).ConfigureAwait(false);
65-
}
66-
67-
[Fact]
68-
public async Task TestClassWithDocumentationAsync()
69-
{
70-
await this.TestTypeWithDocumentationAsync("class").ConfigureAwait(false);
71-
}
72-
73-
[Fact]
74-
public async Task TestStructWithDocumentationAsync()
75-
{
76-
await this.TestTypeWithDocumentationAsync("struct").ConfigureAwait(false);
77-
}
78-
79-
[Fact]
80-
public async Task TestEnumWithDocumentationAsync()
44+
[Theory]
45+
[MemberData(nameof(CommonMemberData.BaseTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
46+
public async Task TestBaseTypeWithoutDocumentationAsync(string type)
8147
{
82-
await this.TestTypeWithDocumentationAsync("enum").ConfigureAwait(false);
48+
var isInterface = type == "interface";
49+
await this.TestTypeWithoutDocumentationAsync(type, isInterface).ConfigureAwait(false);
8350
}
8451

85-
[Fact]
86-
public async Task TestInterfaceWithDocumentationAsync()
52+
[Theory]
53+
[MemberData(nameof(CommonMemberData.BaseTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
54+
public async Task TestBaseTypeWithDocumentationAsync(string type)
8755
{
88-
await this.TestTypeWithDocumentationAsync("interface").ConfigureAwait(false);
56+
await this.TestTypeWithDocumentationAsync(type).ConfigureAwait(false);
8957
}
9058

9159
[Fact]

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1600ElementsMustBeDocumented.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1313
using Microsoft.CodeAnalysis.CSharp.Syntax;
1414
using Microsoft.CodeAnalysis.Diagnostics;
1515
using StyleCop.Analyzers.Helpers;
16+
using StyleCop.Analyzers.Lightup;
1617
using StyleCop.Analyzers.Settings.ObjectModel;
1718

1819
/// <summary>
@@ -24,7 +25,7 @@ namespace StyleCop.Analyzers.DocumentationRules
2425
///
2526
/// <para>A violation of this rule occurs if an element is completely missing a documentation header, or if the
2627
/// header is empty. In C# the following types of elements can have documentation headers: classes, constructors,
27-
/// delegates, enums, events, finalizers, indexers, interfaces, methods, properties, and structs.</para>
28+
/// delegates, enums, events, finalizers, indexers, interfaces, methods, properties, records, and structs.</para>
2829
/// </remarks>
2930
[DiagnosticAnalyzer(LanguageNames.CSharp)]
3031
internal class SA1600ElementsMustBeDocumented : DiagnosticAnalyzer
@@ -41,9 +42,6 @@ internal class SA1600ElementsMustBeDocumented : DiagnosticAnalyzer
4142
private static readonly DiagnosticDescriptor Descriptor =
4243
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.DocumentationRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);
4344

44-
private static readonly ImmutableArray<SyntaxKind> BaseTypeDeclarationKinds =
45-
ImmutableArray.Create(SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.EnumDeclaration);
46-
4745
private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> BaseTypeDeclarationAction = Analyzer.HandleBaseTypeDeclaration;
4846
private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> MethodDeclarationAction = Analyzer.HandleMethodDeclaration;
4947
private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> ConstructorDeclarationAction = Analyzer.HandleConstructorDeclaration;
@@ -114,7 +112,7 @@ public override void Initialize(AnalysisContext context)
114112

115113
context.RegisterCompilationStartAction(context =>
116114
{
117-
context.RegisterSyntaxNodeAction(BaseTypeDeclarationAction, BaseTypeDeclarationKinds);
115+
context.RegisterSyntaxNodeAction(BaseTypeDeclarationAction, SyntaxKinds.BaseTypeDeclaration);
118116
context.RegisterSyntaxNodeAction(MethodDeclarationAction, SyntaxKind.MethodDeclaration);
119117
context.RegisterSyntaxNodeAction(ConstructorDeclarationAction, SyntaxKind.ConstructorDeclaration);
120118
context.RegisterSyntaxNodeAction(DestructorDeclarationAction, SyntaxKind.DestructorDeclaration);

documentation/SA1600.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ A C# code element is missing a documentation header.
2323

2424
C# syntax provides a mechanism for inserting documentation for classes and elements directly into the code, through the use of Xml documentation headers. For an introduction to these headers and a description of the header syntax, see the following article: [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/xml-documentation-comments](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/xml-documentation-comments).
2525

26-
A violation of this rule occurs if an element is completely missing a documentation header, or if the header is empty. In C# the following types of elements can have documentation headers: classes, constructors, delegates, enums, events, finalizers, indexers, interfaces, methods, properties, and structs.
26+
A violation of this rule occurs if an element is completely missing a documentation header, or if the header is empty. In C# the following types of elements can have documentation headers: classes, constructors, delegates, enums, events, finalizers, indexers, interfaces, methods, properties, records, and structs.
2727

2828
## How to fix violations
2929

0 commit comments

Comments
 (0)