From 51d3cbefc77b4c61256e6c6bf63571e3187d175c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Hellander?= <bjorn.hellander@gmail.com> Date: Mon, 10 Apr 2023 09:52:43 +0200 Subject: [PATCH 1/4] Straighten out code in SettingsHelper --- .../Settings/SettingsHelper.cs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs index 73157dfca..781894e4b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs @@ -108,6 +108,26 @@ internal static bool IsStyleCopSettingsFile(string path) || string.Equals(fileName, AltSettingsFileName, StringComparison.OrdinalIgnoreCase); } + private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, SyntaxTree tree, ImmutableArray<AdditionalText> 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(); + } + private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, SyntaxTree tree, string path, SourceText text, DeserializationFailureBehavior failureBehavior) { var optionsProvider = options.AnalyzerConfigOptionsProvider().GetOptions(tree); @@ -146,25 +166,5 @@ private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, Syn return new StyleCopSettings(); } - - private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, SyntaxTree tree, ImmutableArray<AdditionalText> 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(); - } } } From 77c498d0b27956c3ffd4e0e873ee56a7a589b16d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Hellander?= <bjorn.hellander@gmail.com> Date: Mon, 10 Apr 2023 09:53:16 +0200 Subject: [PATCH 2/4] Improve some variable names in SettingsHelper --- .../StyleCop.Analyzers/Settings/SettingsHelper.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs index 781894e4b..f139ce5a0 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs @@ -121,8 +121,8 @@ private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, Syn if (tree != null) { - var optionsProvider = options.AnalyzerConfigOptionsProvider().GetOptions(tree); - return new StyleCopSettings(new JsonObject(), optionsProvider); + var analyzerConfigOptions = options.AnalyzerConfigOptionsProvider().GetOptions(tree); + return new StyleCopSettings(new JsonObject(), analyzerConfigOptions); } return new StyleCopSettings(); @@ -130,7 +130,7 @@ private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, Syn private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, SyntaxTree tree, string path, SourceText text, DeserializationFailureBehavior failureBehavior) { - var optionsProvider = options.AnalyzerConfigOptionsProvider().GetOptions(tree); + var analyzerConfigOptions = options.AnalyzerConfigOptionsProvider().GetOptions(tree); try { @@ -146,7 +146,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) { From 7524fc32e7069ec5e64dae0fbe878fcc08c5d8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Hellander?= <bjorn.hellander@gmail.com> Date: Mon, 10 Apr 2023 11:29:42 +0200 Subject: [PATCH 3/4] Improve SettingsHelper by making sure that its internal GetStyleCopSettings methods are only called by other classes --- .../Settings/SettingsHelper.cs | 21 ++++++++++--------- .../SpecialRules/SA0002InvalidSettingsFile.cs | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs index f139ce5a0..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<StyleCopSettings> SettingsValueProvider { get; } = new SourceTextValueProvider<StyleCopSettings>( - text => GetStyleCopSettings(options: null, tree: null, SettingsFileName, text, DeserializationFailureBehavior.ReturnDefaultSettings)); + text => GetSettings(options: null, tree: null, SettingsFileName, text, DeserializationFailureBehavior.ReturnDefaultSettings)); /// <summary> /// Gets the StyleCop settings. @@ -41,7 +41,7 @@ internal static class SettingsHelper /// <returns>A <see cref="StyleCopSettings"/> instance that represents the StyleCop settings for the given context.</returns> 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); } /// <summary> @@ -56,7 +56,7 @@ internal static StyleCopSettings GetStyleCopSettings(this SyntaxTreeAnalysisCont /// <returns>A <see cref="StyleCopSettings"/> instance that represents the StyleCop settings for the given context.</returns> 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); } /// <summary> @@ -72,21 +72,21 @@ internal static StyleCopSettings GetStyleCopSettings(this SyntaxNodeAnalysisCont /// <returns>A <see cref="StyleCopSettings"/> instance that represents the StyleCop settings for the given context.</returns> 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); } /// <summary> /// Gets the StyleCop settings. /// </summary> - /// <param name="options">The analyzer options that will be used to determine the StyleCop settings.</param> + /// <param name="context">The context that will be used to determine the StyleCop settings.</param> /// <param name="tree">The syntax tree.</param> /// <param name="failureBehavior">The behavior of the method when a <see cref="JsonParseException"/> or /// <see cref="InvalidSettingsException"/> occurs while deserializing the settings file.</param> /// <param name="cancellationToken">The cancellation token that the operation will observe.</param> /// <returns>A <see cref="StyleCopSettings"/> instance that represents the StyleCop settings for the given context.</returns> - 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<AdditionalText>(), failureBehavior, cancellationToken); + return GetSettings(context.Options, tree, failureBehavior, cancellationToken); } /// <summary> @@ -108,14 +108,15 @@ internal static bool IsStyleCopSettingsFile(string path) || string.Equals(fileName, AltSettingsFileName, StringComparison.OrdinalIgnoreCase); } - private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, SyntaxTree tree, ImmutableArray<AdditionalText> additionalFiles, DeserializationFailureBehavior failureBehavior, CancellationToken cancellationToken) + private static StyleCopSettings GetSettings(AnalyzerOptions options, SyntaxTree tree, DeserializationFailureBehavior failureBehavior, CancellationToken cancellationToken) { + var additionalFiles = options != null ? options.AdditionalFiles : ImmutableArray.Create<AdditionalText>(); foreach (var additionalFile in additionalFiles) { if (IsStyleCopSettingsFile(additionalFile.Path)) { SourceText additionalTextContent = additionalFile.GetText(cancellationToken); - return GetStyleCopSettings(options, tree, additionalFile.Path, additionalTextContent, failureBehavior); + return GetSettings(options, tree, additionalFile.Path, additionalTextContent, failureBehavior); } } @@ -128,7 +129,7 @@ private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, Syn return new StyleCopSettings(); } - private static StyleCopSettings GetStyleCopSettings(AnalyzerOptions options, SyntaxTree tree, string path, SourceText text, DeserializationFailureBehavior failureBehavior) + private static StyleCopSettings GetSettings(AnalyzerOptions options, SyntaxTree tree, string path, SourceText text, DeserializationFailureBehavior failureBehavior) { var analyzerConfigOptions = options.AnalyzerConfigOptionsProvider().GetOptions(tree); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SA0002InvalidSettingsFile.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SA0002InvalidSettingsFile.cs index f030056cd..90168d41e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SA0002InvalidSettingsFile.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SA0002InvalidSettingsFile.cs @@ -59,7 +59,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) { From ab8a6e89d379553bb34f6c13674a39a1e7383da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Hellander?= <bjorn.hellander@gmail.com> Date: Mon, 10 Apr 2023 16:48:53 +0200 Subject: [PATCH 4/4] Update code so all analyzers get the settings through the syntax actions if they can, instead of retrieving it themselves ##3634 --- .../ElementDocumentationBase.cs | 7 +-- .../PropertyDocumentationBase.cs | 9 ++-- .../PropertySummaryDocumentationAnalyzer.cs | 5 +- ...tDocumentationMustNotHaveDefaultSummary.cs | 2 +- ...A1609PropertyDocumentationMustHaveValue.cs | 3 +- ...0PropertyDocumentationMustHaveValueText.cs | 3 +- ...SA1611ElementParametersMustBeDocumented.cs | 2 +- ...DocumentationMustMatchElementParameters.cs | 2 +- ...erDocumentationMustDeclareParameterName.cs | 2 +- ...ementParameterDocumentationMustHaveText.cs | 2 +- ...entReturnValueDocumentationMustHaveText.cs | 2 +- ...ntDocumentationMustNotBeCopiedAndPasted.cs | 4 +- ...1629DocumentationTextMustEndWithAPeriod.cs | 2 +- ...yDocumentationMustBeginWithStandardText.cs | 7 ++- ...yDocumentationMustBeginWithStandardText.cs | 7 ++- ...sForMultiLineStatementsMustNotShareLine.cs | 53 ++++++++++--------- ...TupleElementNamesShouldUseCorrectCasing.cs | 10 ++-- 17 files changed, 60 insertions(+), 62 deletions(-) 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. /// </summary> /// <param name="context">The current analysis context.</param> + /// <param name="settings">The StyleCop settings to use.</param> /// <param name="needsComment"><see langword="true"/> if the current documentation settings indicate that the /// element should be documented; otherwise, <see langword="false"/>.</param> /// <param name="completeDocumentation">The complete documentation for the declared symbol, with any @@ -93,7 +94,7 @@ public override void Initialize(AnalysisContext context) /// element, this value will be <see langword="null"/>, even if the XML documentation comment also included an /// <c><include></c> element.</param> /// <param name="diagnosticLocations">The location(s) where diagnostics, if any, should be reported.</param> - 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 <c><summary></c> element of a documentation comment. /// </summary> /// <param name="context">The current analysis context.</param> + /// <param name="settings">The StyleCop settings to use.</param> /// <param name="needsComment"><see langword="true"/> if the current documentation settings indicate that the /// element should be documented; otherwise, <see langword="false"/>.</param> /// <param name="syntax">The <see cref="XmlElementSyntax"/> or <see cref="XmlEmptyElementSyntax"/> of the node @@ -60,7 +61,7 @@ public override void Initialize(AnalysisContext context) /// element, this value will be <see langword="null"/>, even if the XML documentation comment also included an /// <c><include></c> element.</param> /// <param name="diagnosticLocation">The location where diagnostics, if any, should be reported.</param> - 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; /// <summary> /// Analyzes the correct usage of property summary documentation. @@ -59,11 +59,10 @@ internal class PropertySummaryDocumentationAnalyzer : PropertyDocumentationBase protected override string XmlTagToHandle => XmlCommentHelper.SummaryXmlTag; /// <inheritdoc/> - 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 } /// <inheritdoc/> - 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 <include> element var includedSummaryElement = completeDocumentation.Nodes().OfType<XElement>().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; /// <summary> /// The XML header documentation for a C# property does not contain a <c><value></c> tag. @@ -48,7 +49,7 @@ internal class SA1609PropertyDocumentationMustHaveValue : PropertyDocumentationB protected override string XmlTagToHandle => XmlCommentHelper.ValueXmlTag; /// <inheritdoc/> - 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; /// <summary> /// The XML header documentation for a C# property contains an empty <c><value></c> tag. @@ -48,7 +49,7 @@ internal class SA1610PropertyDocumentationMustHaveValueText : PropertyDocumentat protected override string XmlTagToHandle => XmlCommentHelper.ValueXmlTag; /// <inheritdoc/> - 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<string, string>(); 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 } /// <inheritdoc/> - 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 } /// <inheritdoc/> - 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 } /// <inheritdoc/> - 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<XElement>() 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 } /// <inheritdoc/> - 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<XElement>() 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 } /// <inheritdoc/> - 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<XElement>() 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 } /// <inheritdoc/> - 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<string>>(); HashSet<string> 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 } /// <inheritdoc/> - 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<XElement>()) { 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; /// <summary> /// 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<SyntaxNodeAnalysisContext> ConstructorDeclarationAction = HandleConstructorDeclaration; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> ConstructorDeclarationAction = HandleConstructorDeclaration; /// <inheritdoc/> public override ImmutableArray<DiagnosticDescriptor> 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; /// <summary> /// 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<SyntaxNodeAnalysisContext> DestructorDeclarationAction = HandleDestructor; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> DestructorDeclarationAction = HandleDestructor; /// <inheritdoc/> public override ImmutableArray<DiagnosticDescriptor> 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; /// <summary> /// 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<SyntaxNodeAnalysisContext> NamespaceDeclarationAction = HandleNamespaceDeclaration; - private static readonly Action<SyntaxNodeAnalysisContext> BaseTypeDeclarationAction = HandleBaseTypeDeclaration; - private static readonly Action<SyntaxNodeAnalysisContext> AccessorListAction = HandleAccessorList; - private static readonly Action<SyntaxNodeAnalysisContext> BlockAction = HandleBlock; - private static readonly Action<SyntaxNodeAnalysisContext> SwitchStatementAction = HandleSwitchStatement; - private static readonly Action<SyntaxNodeAnalysisContext> InitializerExpressionAction = HandleInitializerExpression; - private static readonly Action<SyntaxNodeAnalysisContext> AnonymousObjectCreationExpressionAction = HandleAnonymousObjectCreationExpression; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> NamespaceDeclarationAction = HandleNamespaceDeclaration; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> BaseTypeDeclarationAction = HandleBaseTypeDeclaration; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> AccessorListAction = HandleAccessorList; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> BlockAction = HandleBlock; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> SwitchStatementAction = HandleSwitchStatement; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> InitializerExpressionAction = HandleInitializerExpression; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> AnonymousObjectCreationExpressionAction = HandleAnonymousObjectCreationExpression; /// <inheritdoc/> public override ImmutableArray<DiagnosticDescriptor> 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<SyntaxNodeAnalysisContext> TupleTypeAction = HandleTupleTypeAction; - private static readonly Action<SyntaxNodeAnalysisContext> TupleExpressionAction = HandleTupleExpressionAction; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> TupleTypeAction = HandleTupleTypeAction; + private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> TupleExpressionAction = HandleTupleExpressionAction; /// <inheritdoc/> public override ImmutableArray<DiagnosticDescriptor> 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;