diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs index a786b3f8c..593941aea 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs @@ -10,6 +10,7 @@ namespace StyleCop.Analyzers.Test.DocumentationRules using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.DocumentationRules; + using StyleCop.Analyzers.Test.Helpers; using Xunit; using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< StyleCop.Analyzers.DocumentationRules.SA1600ElementsMustBeDocumented, @@ -40,52 +41,19 @@ public async Task TestRegressionMethodGlobalNamespaceAsync(string code) await VerifyCSharpDiagnosticAsync(this.LanguageVersion, testCode, expected, CancellationToken.None).ConfigureAwait(false); } - [Fact] - public async Task TestClassWithoutDocumentationAsync() - { - await this.TestTypeWithoutDocumentationAsync("class", false).ConfigureAwait(false); - } - - [Fact] - public async Task TestStructWithoutDocumentationAsync() - { - await this.TestTypeWithoutDocumentationAsync("struct", false).ConfigureAwait(false); - } - - [Fact] - public async Task TestEnumWithoutDocumentationAsync() - { - await this.TestTypeWithoutDocumentationAsync("enum", false).ConfigureAwait(false); - } - - [Fact] - public async Task TestInterfaceWithoutDocumentationAsync() - { - await this.TestTypeWithoutDocumentationAsync("interface", true).ConfigureAwait(false); - } - - [Fact] - public async Task TestClassWithDocumentationAsync() - { - await this.TestTypeWithDocumentationAsync("class").ConfigureAwait(false); - } - - [Fact] - public async Task TestStructWithDocumentationAsync() - { - await this.TestTypeWithDocumentationAsync("struct").ConfigureAwait(false); - } - - [Fact] - public async Task TestEnumWithDocumentationAsync() + [Theory] + [MemberData(nameof(CommonMemberData.BaseTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))] + public async Task TestBaseTypeWithoutDocumentationAsync(string type) { - await this.TestTypeWithDocumentationAsync("enum").ConfigureAwait(false); + var isInterface = type == "interface"; + await this.TestTypeWithoutDocumentationAsync(type, isInterface).ConfigureAwait(false); } - [Fact] - public async Task TestInterfaceWithDocumentationAsync() + [Theory] + [MemberData(nameof(CommonMemberData.BaseTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))] + public async Task TestBaseTypeWithDocumentationAsync(string type) { - await this.TestTypeWithDocumentationAsync("interface").ConfigureAwait(false); + await this.TestTypeWithDocumentationAsync(type).ConfigureAwait(false); } [Fact] diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1600ElementsMustBeDocumented.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1600ElementsMustBeDocumented.cs index f952bb6a4..f64633941 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1600ElementsMustBeDocumented.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1600ElementsMustBeDocumented.cs @@ -13,6 +13,7 @@ namespace StyleCop.Analyzers.DocumentationRules using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using StyleCop.Analyzers.Helpers; + using StyleCop.Analyzers.Lightup; using StyleCop.Analyzers.Settings.ObjectModel; /// @@ -24,7 +25,7 @@ namespace StyleCop.Analyzers.DocumentationRules /// /// 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. + /// delegates, enums, events, finalizers, indexers, interfaces, methods, properties, records, and structs. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] internal class SA1600ElementsMustBeDocumented : DiagnosticAnalyzer @@ -41,9 +42,6 @@ internal class SA1600ElementsMustBeDocumented : DiagnosticAnalyzer private static readonly DiagnosticDescriptor Descriptor = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.DocumentationRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink); - private static readonly ImmutableArray BaseTypeDeclarationKinds = - ImmutableArray.Create(SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.EnumDeclaration); - private static readonly Action BaseTypeDeclarationAction = Analyzer.HandleBaseTypeDeclaration; private static readonly Action MethodDeclarationAction = Analyzer.HandleMethodDeclaration; private static readonly Action ConstructorDeclarationAction = Analyzer.HandleConstructorDeclaration; @@ -114,7 +112,7 @@ public override void Initialize(AnalysisContext context) context.RegisterCompilationStartAction(context => { - context.RegisterSyntaxNodeAction(BaseTypeDeclarationAction, BaseTypeDeclarationKinds); + context.RegisterSyntaxNodeAction(BaseTypeDeclarationAction, SyntaxKinds.BaseTypeDeclaration); context.RegisterSyntaxNodeAction(MethodDeclarationAction, SyntaxKind.MethodDeclaration); context.RegisterSyntaxNodeAction(ConstructorDeclarationAction, SyntaxKind.ConstructorDeclaration); context.RegisterSyntaxNodeAction(DestructorDeclarationAction, SyntaxKind.DestructorDeclaration); diff --git a/documentation/SA1600.md b/documentation/SA1600.md index 806ef0a8b..a93042599 100644 --- a/documentation/SA1600.md +++ b/documentation/SA1600.md @@ -23,7 +23,7 @@ A C# code element is missing a documentation header. 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). -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. +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. ## How to fix violations