Skip to content

Commit 6c4aaa5

Browse files
authored
Merge pull request #2743 from vweijsters/fix-2721
Made the top-level tags that will not be analyzed by SA1629 configura…
2 parents 0c31e29 + 1b4f061 commit 6c4aaa5

13 files changed

Lines changed: 166 additions & 28 deletions

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
1919
/// </summary>
2020
public class SA1629UnitTests : CodeFixVerifier
2121
{
22+
private string currentTestSettings;
23+
2224
[Fact]
2325
public async Task TestDocumentationAsync()
2426
{
@@ -758,6 +760,91 @@ public interface ITest
758760
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
759761
}
760762

763+
[Fact]
764+
public async Task TestConfigurationSettingsAsync()
765+
{
766+
this.currentTestSettings = @"
767+
{
768+
""settings"": {
769+
""documentationRules"": {
770+
""excludeFromPunctuationCheck"": [ ""typeparam"",""example"",""exception"",""permission"",""author"" ]
771+
}
772+
}
773+
}
774+
";
775+
776+
var testCode = @"
777+
public interface ITest
778+
{
779+
/// <summary>
780+
/// Test method #1.
781+
/// </summary>
782+
/// <typeparam name=""T"">
783+
/// Template type
784+
/// </typeparam>
785+
/// <param name=""arg1"">
786+
/// First argument.
787+
/// </param>
788+
/// <returns>
789+
/// Some value.
790+
/// </returns>
791+
/// <remarks>
792+
/// Random remark.
793+
/// </remarks>
794+
/// <example>
795+
/// Random example
796+
/// </example>
797+
/// <exception cref=""System.Exception"">
798+
/// Exception description
799+
/// </exception>
800+
/// <permission cref=""System.Security.PermissionSet"">
801+
/// Everyone can access this method
802+
/// </permission>
803+
/// <author>
804+
/// john.doe@example.com
805+
/// </author>
806+
int TestMethod1<T>(T arg1);
807+
}
808+
";
809+
810+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
811+
}
812+
813+
[Fact]
814+
public async Task TestConfigurationSettingsEmptyAsync()
815+
{
816+
this.currentTestSettings = @"
817+
{
818+
""settings"": {
819+
""documentationRules"": {
820+
""excludeFromPunctuationCheck"": [ ]
821+
}
822+
}
823+
}
824+
";
825+
826+
var testCode = @"
827+
public interface ITest
828+
{
829+
/// <summary>Test method #1.</summary>
830+
/// <seealso>Missing period</seealso>
831+
void TestMethod1();
832+
}
833+
";
834+
835+
DiagnosticResult[] expectedResult =
836+
{
837+
this.CSharpDiagnostic().WithLocation(5, 32),
838+
};
839+
840+
await this.VerifyCSharpDiagnosticAsync(testCode, expectedResult, CancellationToken.None).ConfigureAwait(false);
841+
}
842+
843+
protected override string GetSettings()
844+
{
845+
return this.currentTestSettings ?? base.GetSettings();
846+
}
847+
761848
protected override Project ApplyCompilationOptions(Project project)
762849
{
763850
var resolver = new TestXmlReferenceResolver();

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/ElementDocumentationBase.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ public override void Initialize(AnalysisContext context)
6969
/// Analyzes the top-level elements of a documentation comment.
7070
/// </summary>
7171
/// <param name="context">The current analysis context.</param>
72+
/// <param name="settings">The StyleCop settings to use.</param>
7273
/// <param name="needsComment"><see langword="true"/> if the current documentation settings indicate that the
7374
/// element should be documented; otherwise, <see langword="false"/>.</param>
7475
/// <param name="syntaxList">The <see cref="XmlElementSyntax"/> or <see cref="XmlEmptyElementSyntax"/> of the node
7576
/// to examine.</param>
7677
/// <param name="diagnosticLocations">The location(s) where diagnostics, if any, should be reported.</param>
77-
protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations);
78+
protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations);
7879

7980
/// <summary>
8081
/// Analyzes the XML elements of a documentation comment.
@@ -100,7 +101,7 @@ private void HandleMethodDeclaration(SyntaxNodeAnalysisContext context, StyleCop
100101
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
101102
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
102103
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
103-
this.HandleDeclaration(context, needsComment, node, node.Identifier.GetLocation());
104+
this.HandleDeclaration(context, settings, needsComment, node, node.Identifier.GetLocation());
104105
}
105106

106107
private void HandleConstructorDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
@@ -114,7 +115,7 @@ private void HandleConstructorDeclaration(SyntaxNodeAnalysisContext context, Sty
114115
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
115116
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
116117
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
117-
this.HandleDeclaration(context, needsComment, node, node.Identifier.GetLocation());
118+
this.HandleDeclaration(context, settings, needsComment, node, node.Identifier.GetLocation());
118119
}
119120

120121
private void HandleDelegateDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
@@ -128,7 +129,7 @@ private void HandleDelegateDeclaration(SyntaxNodeAnalysisContext context, StyleC
128129
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
129130
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
130131
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
131-
this.HandleDeclaration(context, needsComment, node, node.Identifier.GetLocation());
132+
this.HandleDeclaration(context, settings, needsComment, node, node.Identifier.GetLocation());
132133
}
133134

134135
private void HandleIndexerDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
@@ -142,7 +143,7 @@ private void HandleIndexerDeclaration(SyntaxNodeAnalysisContext context, StyleCo
142143
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
143144
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
144145
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
145-
this.HandleDeclaration(context, needsComment, node, node.ThisKeyword.GetLocation());
146+
this.HandleDeclaration(context, settings, needsComment, node, node.ThisKeyword.GetLocation());
146147
}
147148

148149
private void HandleOperatorDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
@@ -156,7 +157,7 @@ private void HandleOperatorDeclaration(SyntaxNodeAnalysisContext context, StyleC
156157
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
157158
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
158159
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
159-
this.HandleDeclaration(context, needsComment, node, node.OperatorToken.GetLocation());
160+
this.HandleDeclaration(context, settings, needsComment, node, node.OperatorToken.GetLocation());
160161
}
161162

162163
private void HandleConversionOperatorDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
@@ -166,7 +167,7 @@ private void HandleConversionOperatorDeclaration(SyntaxNodeAnalysisContext conte
166167
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
167168
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
168169
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
169-
this.HandleDeclaration(context, needsComment, node, node.GetLocation());
170+
this.HandleDeclaration(context, settings, needsComment, node, node.GetLocation());
170171
}
171172

172173
private void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
@@ -176,7 +177,7 @@ private void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context, StyleC
176177
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
177178
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
178179
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
179-
this.HandleDeclaration(context, needsComment, node, node.Identifier.GetLocation());
180+
this.HandleDeclaration(context, settings, needsComment, node, node.Identifier.GetLocation());
180181
}
181182

182183
private void HandleFieldDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
@@ -186,7 +187,7 @@ private void HandleFieldDeclaration(SyntaxNodeAnalysisContext context, StyleCopS
186187
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
187188
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
188189
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
189-
this.HandleDeclaration(context, needsComment, node, node.Declaration.GetLocation());
190+
this.HandleDeclaration(context, settings, needsComment, node, node.Declaration.GetLocation());
190191
}
191192

192193
private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
@@ -196,10 +197,10 @@ private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context, StyleC
196197
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
197198
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
198199
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
199-
this.HandleDeclaration(context, needsComment, node, node.Identifier.GetLocation());
200+
this.HandleDeclaration(context, settings, needsComment, node, node.Identifier.GetLocation());
200201
}
201202

202-
private void HandleDeclaration(SyntaxNodeAnalysisContext context, bool needsComment, SyntaxNode node, params Location[] locations)
203+
private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, SyntaxNode node, params Location[] locations)
203204
{
204205
var documentation = node.GetDocumentationCommentTriviaSyntax();
205206
if (documentation == null)
@@ -242,7 +243,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, bool needsComm
242243
}
243244
}
244245

245-
this.HandleXmlElement(context, needsComment, matchingXmlElements, locations);
246+
this.HandleXmlElement(context, settings, needsComment, matchingXmlElements, locations);
246247
}
247248
}
248249
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1608ElementDocumentationMustNotHaveDefaultSummary.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1212
using Microsoft.CodeAnalysis.CSharp.Syntax;
1313
using Microsoft.CodeAnalysis.Diagnostics;
1414
using StyleCop.Analyzers.Helpers;
15+
using StyleCop.Analyzers.Settings.ObjectModel;
1516

1617
/// <summary>
1718
/// The <c>&lt;summary&gt;</c> tag within an element's XML header documentation contains the default text generated
@@ -56,7 +57,7 @@ public SA1608ElementDocumentationMustNotHaveDefaultSummary()
5657
ImmutableArray.Create(Descriptor);
5758

5859
/// <inheritdoc/>
59-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
60+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
6061
{
6162
foreach (var syntax in syntaxList)
6263
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1611ElementParametersMustBeDocumented.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1111
using Microsoft.CodeAnalysis.CSharp.Syntax;
1212
using Microsoft.CodeAnalysis.Diagnostics;
1313
using StyleCop.Analyzers.Helpers;
14+
using StyleCop.Analyzers.Settings.ObjectModel;
1415

1516
/// <summary>
1617
/// A C# method, constructor, delegate or indexer element is missing documentation for one or more of its
@@ -48,7 +49,7 @@ public SA1611ElementParametersMustBeDocumented()
4849
ImmutableArray.Create(Descriptor);
4950

5051
/// <inheritdoc/>
51-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
52+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
5253
{
5354
if (!needsComment)
5455
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1612ElementParameterDocumentationMustMatchElementParameters.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1111
using Microsoft.CodeAnalysis.CSharp.Syntax;
1212
using Microsoft.CodeAnalysis.Diagnostics;
1313
using StyleCop.Analyzers.Helpers;
14+
using StyleCop.Analyzers.Settings.ObjectModel;
1415

1516
/// <summary>
1617
/// The documentation describing the parameters to a C# method, constructor, delegate or indexer element does not
@@ -54,7 +55,7 @@ public SA1612ElementParameterDocumentationMustMatchElementParameters()
5455
ImmutableArray.Create(MissingParameterDescriptor);
5556

5657
/// <inheritdoc/>
57-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
58+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
5859
{
5960
var node = context.Node;
6061
var identifier = GetIdentifier(node);

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1613ElementParameterDocumentationMustDeclareParameterName.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1111
using Microsoft.CodeAnalysis.CSharp.Syntax;
1212
using Microsoft.CodeAnalysis.Diagnostics;
1313
using StyleCop.Analyzers.Helpers;
14+
using StyleCop.Analyzers.Settings.ObjectModel;
1415

1516
/// <summary>
1617
/// A <c>&lt;param&gt;</c> tag within a C# element's documentation header is missing a <c>name</c> attribute
@@ -53,7 +54,7 @@ public SA1613ElementParameterDocumentationMustDeclareParameterName()
5354
ImmutableArray.Create(Descriptor);
5455

5556
/// <inheritdoc/>
56-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
57+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
5758
{
5859
foreach (var syntax in syntaxList)
5960
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1614ElementParameterDocumentationMustHaveText.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1111
using Microsoft.CodeAnalysis.CSharp.Syntax;
1212
using Microsoft.CodeAnalysis.Diagnostics;
1313
using StyleCop.Analyzers.Helpers;
14+
using StyleCop.Analyzers.Settings.ObjectModel;
1415

1516
/// <summary>
1617
/// A <c>&lt;param&gt;</c> tag within a C# element's documentation header is empty.
@@ -49,7 +50,7 @@ public SA1614ElementParameterDocumentationMustHaveText()
4950
ImmutableArray.Create(Descriptor);
5051

5152
/// <inheritdoc/>
52-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
53+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
5354
{
5455
foreach (var syntax in syntaxList)
5556
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1616ElementReturnValueDocumentationMustHaveText.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1111
using Microsoft.CodeAnalysis.CSharp.Syntax;
1212
using Microsoft.CodeAnalysis.Diagnostics;
1313
using StyleCop.Analyzers.Helpers;
14+
using StyleCop.Analyzers.Settings.ObjectModel;
1415

1516
/// <summary>
1617
/// The <c>&lt;returns&gt;</c> tag within a C# element's documentation header is empty.
@@ -48,7 +49,7 @@ public SA1616ElementReturnValueDocumentationMustHaveText()
4849
ImmutableArray.Create(Descriptor);
4950

5051
/// <inheritdoc/>
51-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
52+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
5253
{
5354
foreach (var syntax in syntaxList)
5455
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1625ElementDocumentationMustNotBeCopiedAndPasted.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1515
using Microsoft.CodeAnalysis.Diagnostics;
1616
using StyleCop.Analyzers.Helpers;
1717
using StyleCop.Analyzers.Helpers.ObjectPools;
18+
using StyleCop.Analyzers.Settings.ObjectModel;
1819

1920
/// <summary>
2021
/// The XML documentation for a C# element contains two or more identical entries, indicating that the documentation
@@ -84,11 +85,10 @@ public SA1625ElementDocumentationMustNotBeCopiedAndPasted()
8485
ImmutableArray.Create(Descriptor);
8586

8687
/// <inheritdoc/>
87-
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
88+
protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, IEnumerable<XmlNodeSyntax> syntaxList, params Location[] diagnosticLocations)
8889
{
8990
var objectPool = SharedPools.Default<HashSet<string>>();
9091
HashSet<string> documentationTexts = objectPool.Allocate();
91-
var settings = context.Options.GetStyleCopSettings(context.CancellationToken);
9292
var culture = new CultureInfo(settings.DocumentationRules.DocumentationCulture);
9393
var resourceManager = DocumentationResources.ResourceManager;
9494

0 commit comments

Comments
 (0)