diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/ElementDocumentationBase.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/ElementDocumentationBase.cs
index cad9d89af..355d50b61 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/ElementDocumentationBase.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/ElementDocumentationBase.cs
@@ -86,6 +86,7 @@ public override void Initialize(AnalysisContext context)
/// Analyzes the XML elements of a documentation comment.
///
/// The current analysis context.
+ /// The StyleCop settings to use.
/// if the current documentation settings indicate that the
/// element should be documented; otherwise, .
/// The complete documentation for the declared symbol, with any
@@ -93,7 +94,7 @@ public override void Initialize(AnalysisContext context)
/// element, this value will be , even if the XML documentation comment also included an
/// <include> element.
/// The location(s) where diagnostics, if any, should be reported.
- protected abstract void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations);
+ protected abstract void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations);
private void HandleMethodDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
@@ -232,7 +233,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettin
}
var hasIncludedDocumentation =
- documentation.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag) is object;
+ documentation.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag) != null;
if (hasIncludedDocumentation)
{
@@ -255,7 +256,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettin
return;
}
- this.HandleCompleteDocumentation(context, needsComment, completeDocumentation, locations);
+ this.HandleCompleteDocumentation(context, settings, needsComment, completeDocumentation, locations);
return;
}
}
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertyDocumentationBase.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertyDocumentationBase.cs
index 8427923d2..04050e083 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertyDocumentationBase.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertyDocumentationBase.cs
@@ -51,6 +51,7 @@ public override void Initialize(AnalysisContext context)
/// Analyzes the top-level <summary> element of a documentation comment.
///
/// The current analysis context.
+ /// The StyleCop settings to use.
/// if the current documentation settings indicate that the
/// element should be documented; otherwise, .
/// The or of the node
@@ -60,7 +61,7 @@ public override void Initialize(AnalysisContext context)
/// element, this value will be , even if the XML documentation comment also included an
/// <include> element.
/// The location where diagnostics, if any, should be reported.
- protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation);
+ protected abstract void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation);
private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
@@ -73,10 +74,10 @@ private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context, StyleC
Accessibility declaredAccessibility = node.GetDeclaredAccessibility(context.SemanticModel, context.CancellationToken);
Accessibility effectiveAccessibility = node.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
bool needsComment = SA1600ElementsMustBeDocumented.NeedsComment(settings.DocumentationRules, node.Kind(), node.Parent.Kind(), declaredAccessibility, effectiveAccessibility);
- this.HandleDeclaration(context, needsComment, node, node.Identifier.GetLocation());
+ this.HandleDeclaration(context, settings, needsComment, node, node.Identifier.GetLocation());
}
- private void HandleDeclaration(SyntaxNodeAnalysisContext context, bool needsComment, SyntaxNode node, Location location)
+ private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, SyntaxNode node, Location location)
{
var documentation = node.GetDocumentationCommentTriviaSyntax();
if (documentation == null)
@@ -110,7 +111,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, bool needsComm
}
}
- this.HandleXmlElement(context, needsComment, relevantXmlElement, completeDocumentation, location);
+ this.HandleXmlElement(context, settings, needsComment, relevantXmlElement, completeDocumentation, location);
}
}
}
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertySummaryDocumentationAnalyzer.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertySummaryDocumentationAnalyzer.cs
index b69bd1011..0580c4aad 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertySummaryDocumentationAnalyzer.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertySummaryDocumentationAnalyzer.cs
@@ -7,13 +7,13 @@ namespace StyleCop.Analyzers.DocumentationRules
{
using System;
using System.Collections.Immutable;
- using System.Globalization;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Helpers;
+ using StyleCop.Analyzers.Settings.ObjectModel;
///
/// Analyzes the correct usage of property summary documentation.
@@ -59,11 +59,10 @@ internal class PropertySummaryDocumentationAnalyzer : PropertyDocumentationBase
protected override string XmlTagToHandle => XmlCommentHelper.SummaryXmlTag;
///
- protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
+ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
{
var propertyDeclaration = (PropertyDeclarationSyntax)context.Node;
var propertyType = context.SemanticModel.GetTypeInfo(propertyDeclaration.Type.StripRefFromType());
- var settings = context.GetStyleCopSettings(context.CancellationToken);
var culture = settings.DocumentationRules.DocumentationCultureInfo;
var resourceManager = DocumentationResources.ResourceManager;
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1608ElementDocumentationMustNotHaveDefaultSummary.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1608ElementDocumentationMustNotHaveDefaultSummary.cs
index 4ad453b17..2a52d84b6 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1608ElementDocumentationMustNotHaveDefaultSummary.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1608ElementDocumentationMustNotHaveDefaultSummary.cs
@@ -79,7 +79,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
///
- protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
+ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
// We are working with an element
var includedSummaryElement = completeDocumentation.Nodes().OfType().FirstOrDefault(element => element.Name == XmlCommentHelper.SummaryXmlTag);
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1609PropertyDocumentationMustHaveValue.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1609PropertyDocumentationMustHaveValue.cs
index 6ed0abd2e..ca06e1dae 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1609PropertyDocumentationMustHaveValue.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1609PropertyDocumentationMustHaveValue.cs
@@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.DocumentationRules
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Helpers;
+ using StyleCop.Analyzers.Settings.ObjectModel;
///
/// The XML header documentation for a C# property does not contain a <value> tag.
@@ -48,7 +49,7 @@ internal class SA1609PropertyDocumentationMustHaveValue : PropertyDocumentationB
protected override string XmlTagToHandle => XmlCommentHelper.ValueXmlTag;
///
- protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
+ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
{
if (!needsComment)
{
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1610PropertyDocumentationMustHaveValueText.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1610PropertyDocumentationMustHaveValueText.cs
index dba50c67c..d0b733ff1 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1610PropertyDocumentationMustHaveValueText.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1610PropertyDocumentationMustHaveValueText.cs
@@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.DocumentationRules
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Helpers;
+ using StyleCop.Analyzers.Settings.ObjectModel;
///
/// The XML header documentation for a C# property contains an empty <value> tag.
@@ -48,7 +49,7 @@ internal class SA1610PropertyDocumentationMustHaveValueText : PropertyDocumentat
protected override string XmlTagToHandle => XmlCommentHelper.ValueXmlTag;
///
- protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
+ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XmlNodeSyntax syntax, XElement completeDocumentation, Location diagnosticLocation)
{
var properties = ImmutableDictionary.Create();
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1611ElementParametersMustBeDocumented.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1611ElementParametersMustBeDocumented.cs
index b2dff23a3..13ec45241 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1611ElementParametersMustBeDocumented.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1611ElementParametersMustBeDocumented.cs
@@ -75,7 +75,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
///
- protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
+ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
if (!needsComment)
{
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1612ElementParameterDocumentationMustMatchElementParameters.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1612ElementParameterDocumentationMustMatchElementParameters.cs
index 5a895a875..6990202bb 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1612ElementParameterDocumentationMustMatchElementParameters.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1612ElementParameterDocumentationMustMatchElementParameters.cs
@@ -127,7 +127,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
///
- protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
+ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var node = context.Node;
var identifier = GetIdentifier(node);
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1613ElementParameterDocumentationMustDeclareParameterName.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1613ElementParameterDocumentationMustDeclareParameterName.cs
index 481dc20b4..e3828e01b 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1613ElementParameterDocumentationMustDeclareParameterName.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1613ElementParameterDocumentationMustDeclareParameterName.cs
@@ -72,7 +72,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
///
- protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
+ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var xmlParamTags = completeDocumentation.Nodes()
.OfType()
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1614ElementParameterDocumentationMustHaveText.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1614ElementParameterDocumentationMustHaveText.cs
index 431b6f1ed..29196f26d 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1614ElementParameterDocumentationMustHaveText.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1614ElementParameterDocumentationMustHaveText.cs
@@ -66,7 +66,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
///
- protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
+ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var xmlParamTags = completeDocumentation.Nodes()
.OfType()
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1616ElementReturnValueDocumentationMustHaveText.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1616ElementReturnValueDocumentationMustHaveText.cs
index 895a0d497..062d1e315 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1616ElementReturnValueDocumentationMustHaveText.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1616ElementReturnValueDocumentationMustHaveText.cs
@@ -64,7 +64,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
///
- protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
+ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var returnsNodes = completeDocumentation.Nodes()
.OfType()
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1625ElementDocumentationMustNotBeCopiedAndPasted.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1625ElementDocumentationMustNotBeCopiedAndPasted.cs
index 7167679df..6c18750eb 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1625ElementDocumentationMustNotBeCopiedAndPasted.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1625ElementDocumentationMustNotBeCopiedAndPasted.cs
@@ -8,7 +8,6 @@ namespace StyleCop.Analyzers.DocumentationRules
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
- using System.Globalization;
using System.Linq;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
@@ -117,11 +116,10 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
///
- protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
+ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
var objectPool = SharedPools.Default>();
HashSet documentationTexts = objectPool.Allocate();
- var settings = context.GetStyleCopSettings(context.CancellationToken);
var culture = settings.DocumentationRules.DocumentationCultureInfo;
var resourceManager = DocumentationResources.ResourceManager;
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs
index ce50fc3b0..9fd770d77 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1629DocumentationTextMustEndWithAPeriod.cs
@@ -88,7 +88,7 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, Styl
}
///
- protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
+ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext context, StyleCopSettings settings, bool needsComment, XElement completeDocumentation, params Location[] diagnosticLocations)
{
foreach (var node in completeDocumentation.Nodes().OfType())
{
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1642ConstructorSummaryDocumentationMustBeginWithStandardText.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1642ConstructorSummaryDocumentationMustBeginWithStandardText.cs
index 5191c8209..b485a0b0d 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1642ConstructorSummaryDocumentationMustBeginWithStandardText.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1642ConstructorSummaryDocumentationMustBeginWithStandardText.cs
@@ -7,12 +7,12 @@ namespace StyleCop.Analyzers.DocumentationRules
{
using System;
using System.Collections.Immutable;
- using System.Globalization;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
+ using StyleCop.Analyzers.Settings.ObjectModel;
///
/// The XML documentation header for a C# constructor does not contain the appropriate summary text.
@@ -107,7 +107,7 @@ internal class SA1642ConstructorSummaryDocumentationMustBeginWithStandardText :
private static readonly DiagnosticDescriptor Descriptor =
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.DocumentationRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);
- private static readonly Action ConstructorDeclarationAction = HandleConstructorDeclaration;
+ private static readonly Action ConstructorDeclarationAction = HandleConstructorDeclaration;
///
public override ImmutableArray SupportedDiagnostics { get; } =
@@ -122,11 +122,10 @@ public override void Initialize(AnalysisContext context)
context.RegisterSyntaxNodeAction(ConstructorDeclarationAction, SyntaxKind.ConstructorDeclaration);
}
- private static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext context)
+ private static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var constructorDeclarationSyntax = (ConstructorDeclarationSyntax)context.Node;
- var settings = context.GetStyleCopSettings(context.CancellationToken);
var culture = settings.DocumentationRules.DocumentationCultureInfo;
var resourceManager = DocumentationResources.ResourceManager;
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1643DestructorSummaryDocumentationMustBeginWithStandardText.cs b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1643DestructorSummaryDocumentationMustBeginWithStandardText.cs
index abf8fffd6..e9d7060cc 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1643DestructorSummaryDocumentationMustBeginWithStandardText.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1643DestructorSummaryDocumentationMustBeginWithStandardText.cs
@@ -7,10 +7,10 @@ namespace StyleCop.Analyzers.DocumentationRules
{
using System;
using System.Collections.Immutable;
- using System.Globalization;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
+ using StyleCop.Analyzers.Settings.ObjectModel;
///
/// The XML documentation header for a C# finalizer does not contain the appropriate summary text.
@@ -62,7 +62,7 @@ internal class SA1643DestructorSummaryDocumentationMustBeginWithStandardText : S
private static readonly DiagnosticDescriptor Descriptor =
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.DocumentationRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);
- private static readonly Action DestructorDeclarationAction = HandleDestructor;
+ private static readonly Action DestructorDeclarationAction = HandleDestructor;
///
public override ImmutableArray SupportedDiagnostics { get; } =
@@ -77,9 +77,8 @@ public override void Initialize(AnalysisContext context)
context.RegisterSyntaxNodeAction(DestructorDeclarationAction, SyntaxKind.DestructorDeclaration);
}
- private static void HandleDestructor(SyntaxNodeAnalysisContext context)
+ private static void HandleDestructor(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
- var settings = context.GetStyleCopSettings(context.CancellationToken);
var culture = settings.DocumentationRules.DocumentationCultureInfo;
var resourceManager = DocumentationResources.ResourceManager;
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1500BracesForMultiLineStatementsMustNotShareLine.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1500BracesForMultiLineStatementsMustNotShareLine.cs
index cb8f51ddc..e38583efd 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1500BracesForMultiLineStatementsMustNotShareLine.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1500BracesForMultiLineStatementsMustNotShareLine.cs
@@ -13,6 +13,7 @@ namespace StyleCop.Analyzers.LayoutRules
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Helpers;
using StyleCop.Analyzers.Lightup;
+ using StyleCop.Analyzers.Settings.ObjectModel;
///
/// The opening or closing brace within a C# statement, element, or expression is not placed on its own line.
@@ -71,13 +72,13 @@ internal class SA1500BracesForMultiLineStatementsMustNotShareLine : DiagnosticAn
private static readonly DiagnosticDescriptor Descriptor =
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.LayoutRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);
- private static readonly Action NamespaceDeclarationAction = HandleNamespaceDeclaration;
- private static readonly Action BaseTypeDeclarationAction = HandleBaseTypeDeclaration;
- private static readonly Action AccessorListAction = HandleAccessorList;
- private static readonly Action BlockAction = HandleBlock;
- private static readonly Action SwitchStatementAction = HandleSwitchStatement;
- private static readonly Action InitializerExpressionAction = HandleInitializerExpression;
- private static readonly Action AnonymousObjectCreationExpressionAction = HandleAnonymousObjectCreationExpression;
+ private static readonly Action NamespaceDeclarationAction = HandleNamespaceDeclaration;
+ private static readonly Action BaseTypeDeclarationAction = HandleBaseTypeDeclaration;
+ private static readonly Action AccessorListAction = HandleAccessorList;
+ private static readonly Action BlockAction = HandleBlock;
+ private static readonly Action SwitchStatementAction = HandleSwitchStatement;
+ private static readonly Action InitializerExpressionAction = HandleInitializerExpression;
+ private static readonly Action AnonymousObjectCreationExpressionAction = HandleAnonymousObjectCreationExpression;
///
public override ImmutableArray SupportedDiagnostics { get; } =
@@ -98,49 +99,49 @@ public override void Initialize(AnalysisContext context)
context.RegisterSyntaxNodeAction(AnonymousObjectCreationExpressionAction, SyntaxKind.AnonymousObjectCreationExpression);
}
- private static void HandleNamespaceDeclaration(SyntaxNodeAnalysisContext context)
+ private static void HandleNamespaceDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var syntax = (NamespaceDeclarationSyntax)context.Node;
- CheckBraces(context, syntax.OpenBraceToken, syntax.CloseBraceToken);
+ CheckBraces(context, settings, syntax.OpenBraceToken, syntax.CloseBraceToken);
}
- private static void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context)
+ private static void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var syntax = (BaseTypeDeclarationSyntax)context.Node;
- CheckBraces(context, syntax.OpenBraceToken, syntax.CloseBraceToken);
+ CheckBraces(context, settings, syntax.OpenBraceToken, syntax.CloseBraceToken);
}
- private static void HandleAccessorList(SyntaxNodeAnalysisContext context)
+ private static void HandleAccessorList(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var syntax = (AccessorListSyntax)context.Node;
- CheckBraces(context, syntax.OpenBraceToken, syntax.CloseBraceToken);
+ CheckBraces(context, settings, syntax.OpenBraceToken, syntax.CloseBraceToken);
}
- private static void HandleBlock(SyntaxNodeAnalysisContext context)
+ private static void HandleBlock(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var syntax = (BlockSyntax)context.Node;
- CheckBraces(context, syntax.OpenBraceToken, syntax.CloseBraceToken);
+ CheckBraces(context, settings, syntax.OpenBraceToken, syntax.CloseBraceToken);
}
- private static void HandleSwitchStatement(SyntaxNodeAnalysisContext context)
+ private static void HandleSwitchStatement(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var syntax = (SwitchStatementSyntax)context.Node;
- CheckBraces(context, syntax.OpenBraceToken, syntax.CloseBraceToken);
+ CheckBraces(context, settings, syntax.OpenBraceToken, syntax.CloseBraceToken);
}
- private static void HandleInitializerExpression(SyntaxNodeAnalysisContext context)
+ private static void HandleInitializerExpression(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var syntax = (InitializerExpressionSyntax)context.Node;
- CheckBraces(context, syntax.OpenBraceToken, syntax.CloseBraceToken);
+ CheckBraces(context, settings, syntax.OpenBraceToken, syntax.CloseBraceToken);
}
- private static void HandleAnonymousObjectCreationExpression(SyntaxNodeAnalysisContext context)
+ private static void HandleAnonymousObjectCreationExpression(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
var syntax = (AnonymousObjectCreationExpressionSyntax)context.Node;
- CheckBraces(context, syntax.OpenBraceToken, syntax.CloseBraceToken);
+ CheckBraces(context, settings, syntax.OpenBraceToken, syntax.CloseBraceToken);
}
- private static void CheckBraces(SyntaxNodeAnalysisContext context, SyntaxToken openBraceToken, SyntaxToken closeBraceToken)
+ private static void CheckBraces(SyntaxNodeAnalysisContext context, StyleCopSettings settings, SyntaxToken openBraceToken, SyntaxToken closeBraceToken)
{
if (openBraceToken.IsKind(SyntaxKind.None) || closeBraceToken.IsKind(SyntaxKind.None))
{
@@ -234,10 +235,10 @@ private static void CheckBraces(SyntaxNodeAnalysisContext context, SyntaxToken o
}
}
- CheckBraceToken(context, openBraceToken);
+ CheckBraceToken(context, settings, openBraceToken);
if (checkCloseBrace)
{
- CheckBraceToken(context, closeBraceToken, openBraceToken);
+ CheckBraceToken(context, settings, closeBraceToken, openBraceToken);
}
}
@@ -249,7 +250,7 @@ private static bool InitializerExpressionSharesLine(InitializerExpressionSyntax
return (index > 0) && (parent.Expressions[index - 1].GetEndLine() == parent.Expressions[index].GetLine());
}
- private static void CheckBraceToken(SyntaxNodeAnalysisContext context, SyntaxToken token, SyntaxToken openBraceToken = default)
+ private static void CheckBraceToken(SyntaxNodeAnalysisContext context, StyleCopSettings settings, SyntaxToken token, SyntaxToken openBraceToken = default)
{
if (token.IsMissing)
{
@@ -290,7 +291,7 @@ private static void CheckBraceToken(SyntaxNodeAnalysisContext context, SyntaxTok
// Because the default Visual Studio code completion snippet for a do-while loop
// places the while expression on the same line as the closing brace, some users
// may want to allow that and not have SA1500 report it as a style error.
- if (context.GetStyleCopSettings(context.CancellationToken).LayoutRules.AllowDoWhileOnClosingBrace)
+ if (settings.LayoutRules.AllowDoWhileOnClosingBrace)
{
if (openBraceToken.Parent.IsKind(SyntaxKind.Block)
&& openBraceToken.Parent.Parent.IsKind(SyntaxKind.DoStatement))
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs
index 29740e5b6..00e0cf708 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs
@@ -37,8 +37,8 @@ internal class SA1316TupleElementNamesShouldUseCorrectCasing : DiagnosticAnalyze
private static readonly DiagnosticDescriptor Descriptor =
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.NamingRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);
- private static readonly Action TupleTypeAction = HandleTupleTypeAction;
- private static readonly Action TupleExpressionAction = HandleTupleExpressionAction;
+ private static readonly Action TupleTypeAction = HandleTupleTypeAction;
+ private static readonly Action TupleExpressionAction = HandleTupleExpressionAction;
///
public override ImmutableArray SupportedDiagnostics { get; } =
@@ -54,14 +54,13 @@ public override void Initialize(AnalysisContext context)
context.RegisterSyntaxNodeAction(TupleExpressionAction, SyntaxKindEx.TupleExpression);
}
- private static void HandleTupleTypeAction(SyntaxNodeAnalysisContext context)
+ private static void HandleTupleTypeAction(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
if (!context.SupportsTuples())
{
return;
}
- var settings = context.GetStyleCopSettings(context.CancellationToken);
var tupleType = (TupleTypeSyntaxWrapper)context.Node;
foreach (var tupleElement in tupleType.Elements)
@@ -70,14 +69,13 @@ private static void HandleTupleTypeAction(SyntaxNodeAnalysisContext context)
}
}
- private static void HandleTupleExpressionAction(SyntaxNodeAnalysisContext context)
+ private static void HandleTupleExpressionAction(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
{
if (!context.SupportsInferredTupleElementNames())
{
return;
}
- var settings = context.GetStyleCopSettings(context.CancellationToken);
if (!settings.NamingRules.IncludeInferredTupleElementNames)
{
return;
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs
index 73157dfca..f22685a30 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs
@@ -27,7 +27,7 @@ internal static class SettingsHelper
private static SourceTextValueProvider SettingsValueProvider { get; } =
new SourceTextValueProvider(
- text => GetStyleCopSettings(options: null, tree: null, SettingsFileName, text, DeserializationFailureBehavior.ReturnDefaultSettings));
+ text => GetSettings(options: null, tree: null, SettingsFileName, text, DeserializationFailureBehavior.ReturnDefaultSettings));
///
/// Gets the StyleCop settings.
@@ -41,7 +41,7 @@ internal static class SettingsHelper
/// A instance that represents the StyleCop settings for the given context.
internal static StyleCopSettings GetStyleCopSettings(this SyntaxTreeAnalysisContext context, CancellationToken cancellationToken)
{
- return GetStyleCopSettings(context.Options, context.Tree, cancellationToken);
+ return GetSettings(context.Options, context.Tree, DeserializationFailureBehavior.ReturnDefaultSettings, cancellationToken);
}
///
@@ -56,7 +56,7 @@ internal static StyleCopSettings GetStyleCopSettings(this SyntaxTreeAnalysisCont
/// A instance that represents the StyleCop settings for the given context.
internal static StyleCopSettings GetStyleCopSettings(this SyntaxNodeAnalysisContext context, CancellationToken cancellationToken)
{
- return GetStyleCopSettings(context.Options, context.Node.SyntaxTree, cancellationToken);
+ return GetSettings(context.Options, context.Node.SyntaxTree, DeserializationFailureBehavior.ReturnDefaultSettings, cancellationToken);
}
///
@@ -72,21 +72,21 @@ internal static StyleCopSettings GetStyleCopSettings(this SyntaxNodeAnalysisCont
/// A instance that represents the StyleCop settings for the given context.
internal static StyleCopSettings GetStyleCopSettings(this AnalyzerOptions options, SyntaxTree tree, CancellationToken cancellationToken)
{
- return GetStyleCopSettings(options, tree, DeserializationFailureBehavior.ReturnDefaultSettings, cancellationToken);
+ return GetSettings(options, tree, DeserializationFailureBehavior.ReturnDefaultSettings, cancellationToken);
}
///
/// Gets the StyleCop settings.
///
- /// The analyzer options that will be used to determine the StyleCop settings.
+ /// The context that will be used to determine the StyleCop settings.
/// The syntax tree.
/// The behavior of the method when a or
/// occurs while deserializing the settings file.
/// The cancellation token that the operation will observe.
/// A instance that represents the StyleCop settings for the given context.
- internal static StyleCopSettings GetStyleCopSettings(this AnalyzerOptions options, SyntaxTree tree, DeserializationFailureBehavior failureBehavior, CancellationToken cancellationToken)
+ internal static StyleCopSettings GetStyleCopSettings(this CompilationAnalysisContext context, SyntaxTree tree, DeserializationFailureBehavior failureBehavior, CancellationToken cancellationToken)
{
- return GetStyleCopSettings(options, tree, options != null ? options.AdditionalFiles : ImmutableArray.Create(), failureBehavior, cancellationToken);
+ return GetSettings(context.Options, tree, failureBehavior, cancellationToken);
}
///
@@ -108,9 +108,30 @@ internal static bool IsStyleCopSettingsFile(string path)
|| string.Equals(fileName, AltSettingsFileName, StringComparison.OrdinalIgnoreCase);
}
- private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, SyntaxTree tree, string path, SourceText text, DeserializationFailureBehavior failureBehavior)
+ private static StyleCopSettings GetSettings(AnalyzerOptions options, SyntaxTree tree, DeserializationFailureBehavior failureBehavior, CancellationToken cancellationToken)
+ {
+ var additionalFiles = options != null ? options.AdditionalFiles : ImmutableArray.Create();
+ foreach (var additionalFile in additionalFiles)
+ {
+ if (IsStyleCopSettingsFile(additionalFile.Path))
+ {
+ SourceText additionalTextContent = additionalFile.GetText(cancellationToken);
+ return GetSettings(options, tree, additionalFile.Path, additionalTextContent, failureBehavior);
+ }
+ }
+
+ if (tree != null)
+ {
+ var analyzerConfigOptions = options.AnalyzerConfigOptionsProvider().GetOptions(tree);
+ return new StyleCopSettings(new JsonObject(), analyzerConfigOptions);
+ }
+
+ return new StyleCopSettings();
+ }
+
+ private static StyleCopSettings GetSettings(AnalyzerOptions options, SyntaxTree tree, string path, SourceText text, DeserializationFailureBehavior failureBehavior)
{
- var optionsProvider = options.AnalyzerConfigOptionsProvider().GetOptions(tree);
+ var analyzerConfigOptions = options.AnalyzerConfigOptionsProvider().GetOptions(tree);
try
{
@@ -126,7 +147,7 @@ private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, Syn
var settingsObject = rootValue.AsJsonObject["settings"];
if (settingsObject.IsJsonObject)
{
- return new StyleCopSettings(settingsObject.AsJsonObject, optionsProvider);
+ return new StyleCopSettings(settingsObject.AsJsonObject, analyzerConfigOptions);
}
else if (settingsObject.IsNull)
{
@@ -146,25 +167,5 @@ private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, Syn
return new StyleCopSettings();
}
-
- private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, SyntaxTree tree, ImmutableArray additionalFiles, DeserializationFailureBehavior failureBehavior, CancellationToken cancellationToken)
- {
- foreach (var additionalFile in additionalFiles)
- {
- if (IsStyleCopSettingsFile(additionalFile.Path))
- {
- SourceText additionalTextContent = additionalFile.GetText(cancellationToken);
- return GetStyleCopSettings(options, tree, additionalFile.Path, additionalTextContent, failureBehavior);
- }
- }
-
- if (tree != null)
- {
- var optionsProvider = options.AnalyzerConfigOptionsProvider().GetOptions(tree);
- return new StyleCopSettings(new JsonObject(), optionsProvider);
- }
-
- return new StyleCopSettings();
- }
}
}
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SA0002InvalidSettingsFile.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SA0002InvalidSettingsFile.cs
index 9604c4775..8bb93b623 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SA0002InvalidSettingsFile.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SA0002InvalidSettingsFile.cs
@@ -58,7 +58,7 @@ private static void HandleCompilation(CompilationAnalysisContext context)
try
{
- SettingsHelper.GetStyleCopSettings(context.Options, firstSyntaxTree, DeserializationFailureBehavior.ThrowException, context.CancellationToken);
+ context.GetStyleCopSettings(firstSyntaxTree, DeserializationFailureBehavior.ThrowException, context.CancellationToken);
}
catch (Exception ex) when (ex is JsonParseException || ex is InvalidSettingsException)
{