diff --git a/src/Analyzers/CSharp/Analyzers/ConvertNamespace/ConvertToBlockScopedNamespaceDiagnosticAnalyzer.cs b/src/Analyzers/CSharp/Analyzers/ConvertNamespace/ConvertToBlockScopedNamespaceDiagnosticAnalyzer.cs index b8288c97c4d5f..c62fe6113b6af 100644 --- a/src/Analyzers/CSharp/Analyzers/ConvertNamespace/ConvertToBlockScopedNamespaceDiagnosticAnalyzer.cs +++ b/src/Analyzers/CSharp/Analyzers/ConvertNamespace/ConvertToBlockScopedNamespaceDiagnosticAnalyzer.cs @@ -60,7 +60,7 @@ private void AnalyzeNamespace(SyntaxNodeAnalysisContext context) diagnosticLocation, severity, ImmutableArray.Create(declaration.GetLocation()), - ImmutableDictionary.Empty); + ImmutableDictionary.Empty).Diagnostic; } } } diff --git a/src/Analyzers/CSharp/Analyzers/ConvertNamespace/ConvertToFileScopedNamespaceDiagnosticAnalyzer.cs b/src/Analyzers/CSharp/Analyzers/ConvertNamespace/ConvertToFileScopedNamespaceDiagnosticAnalyzer.cs index a1b53d61f3b65..f1be949b61746 100644 --- a/src/Analyzers/CSharp/Analyzers/ConvertNamespace/ConvertToFileScopedNamespaceDiagnosticAnalyzer.cs +++ b/src/Analyzers/CSharp/Analyzers/ConvertNamespace/ConvertToFileScopedNamespaceDiagnosticAnalyzer.cs @@ -64,7 +64,7 @@ private void AnalyzeNamespace(SyntaxNodeAnalysisContext context) diagnosticLocation, severity, ImmutableArray.Create(declaration.GetLocation()), - ImmutableDictionary.Empty); + ImmutableDictionary.Empty).Diagnostic; } } } diff --git a/src/Analyzers/CSharp/Analyzers/UseExpressionBody/UseExpressionBodyDiagnosticAnalyzer.cs b/src/Analyzers/CSharp/Analyzers/UseExpressionBody/UseExpressionBodyDiagnosticAnalyzer.cs index 8d3703f1e526e..981c943207428 100644 --- a/src/Analyzers/CSharp/Analyzers/UseExpressionBody/UseExpressionBodyDiagnosticAnalyzer.cs +++ b/src/Analyzers/CSharp/Analyzers/UseExpressionBody/UseExpressionBodyDiagnosticAnalyzer.cs @@ -104,7 +104,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context) var properties = ImmutableDictionary.Empty.Add(nameof(UseExpressionBody), ""); return DiagnosticHelper.Create( CreateDescriptorWithId(helper.DiagnosticId, helper.EnforceOnBuild, helper.UseExpressionBodyTitle, helper.UseExpressionBodyTitle), - location, severity, additionalLocations: additionalLocations, properties: properties); + location, severity, additionalLocations: additionalLocations, properties: properties).Diagnostic; } if (helper.CanOfferUseBlockBody(preference, declaration, forAnalyzer: true, out var fixesError, out var expressionBody)) @@ -122,7 +122,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context) var additionalLocations = ImmutableArray.Create(declaration.GetLocation()); return DiagnosticHelper.Create( CreateDescriptorWithId(helper.DiagnosticId, helper.EnforceOnBuild, helper.UseBlockBodyTitle, helper.UseBlockBodyTitle), - location, severity, additionalLocations: additionalLocations, properties: properties); + location, severity, additionalLocations: additionalLocations, properties: properties).Diagnostic; } return null; diff --git a/src/Analyzers/CSharp/Analyzers/UseImplicitOrExplicitType/CSharpTypeStyleDiagnosticAnalyzerBase.cs b/src/Analyzers/CSharp/Analyzers/UseImplicitOrExplicitType/CSharpTypeStyleDiagnosticAnalyzerBase.cs index 6f976b6947d45..6149fcc73d83c 100644 --- a/src/Analyzers/CSharp/Analyzers/UseImplicitOrExplicitType/CSharpTypeStyleDiagnosticAnalyzerBase.cs +++ b/src/Analyzers/CSharp/Analyzers/UseImplicitOrExplicitType/CSharpTypeStyleDiagnosticAnalyzerBase.cs @@ -78,7 +78,7 @@ private void HandleVariableDeclaration(SyntaxNodeAnalysisContext context) context.ReportDiagnostic(CreateDiagnostic(descriptor, declarationStatement, declaredType.StripRefIfNeeded().Span, typeStyle.Severity)); } - private static Diagnostic CreateDiagnostic(DiagnosticDescriptor descriptor, SyntaxNode declaration, TextSpan diagnosticSpan, ReportDiagnostic severity) + private static DiagnosticHelper.DiagnosticWrapper CreateDiagnostic(DiagnosticDescriptor descriptor, SyntaxNode declaration, TextSpan diagnosticSpan, ReportDiagnostic severity) => DiagnosticHelper.Create(descriptor, declaration.SyntaxTree.GetLocation(diagnosticSpan), severity, additionalLocations: null, properties: null); } } diff --git a/src/Analyzers/CSharp/Analyzers/UseIndexOrRangeOperator/CSharpUseRangeOperatorDiagnosticAnalyzer.cs b/src/Analyzers/CSharp/Analyzers/UseIndexOrRangeOperator/CSharpUseRangeOperatorDiagnosticAnalyzer.cs index 99d59c8b0719f..7a4b3113a5b91 100644 --- a/src/Analyzers/CSharp/Analyzers/UseIndexOrRangeOperator/CSharpUseRangeOperatorDiagnosticAnalyzer.cs +++ b/src/Analyzers/CSharp/Analyzers/UseIndexOrRangeOperator/CSharpUseRangeOperatorDiagnosticAnalyzer.cs @@ -243,7 +243,7 @@ private static bool IsValidIndexing(IInvocationOperation invocation, InfoCache i return !invocation.Syntax.IsLeftSideOfAnyAssignExpression() || indexer == null || !IsWriteableIndexer(invocation, indexer); } - private Diagnostic CreateDiagnostic(Result result, ReportDiagnostic severity) + private DiagnosticHelper.DiagnosticWrapper CreateDiagnostic(Result result, ReportDiagnostic severity) { // Keep track of the invocation node var invocation = result.Invocation; diff --git a/src/Analyzers/Core/Analyzers/AnalyzersResources.resx b/src/Analyzers/Core/Analyzers/AnalyzersResources.resx index c1a6d115745b4..341c239003f3c 100644 --- a/src/Analyzers/Core/Analyzers/AnalyzersResources.resx +++ b/src/Analyzers/Core/Analyzers/AnalyzersResources.resx @@ -1,17 +1,17 @@  - @@ -136,10 +136,10 @@ Private member '{0}' can be removed as the value assigned to it is never read - Private method '{0}' can be removed as it is never invoked. + Private method '{0}' can be removed as it is never invoked - Private property '{0}' can be converted to a method as its get accessor is never invoked. + Private property '{0}' can be converted to a method as its get accessor is never invoked A source file is missing a required header. diff --git a/src/Analyzers/Core/Analyzers/Helpers/DiagnosticHelper.cs b/src/Analyzers/Core/Analyzers/Helpers/DiagnosticHelper.cs index 02f58e3f3aa32..a36440ff23aa3 100644 --- a/src/Analyzers/Core/Analyzers/Helpers/DiagnosticHelper.cs +++ b/src/Analyzers/Core/Analyzers/Helpers/DiagnosticHelper.cs @@ -10,13 +10,102 @@ using System.Linq; using System.Runtime.Serialization.Json; using System.Text; -using Microsoft.CodeAnalysis.PooledObjects; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Diagnostics { internal static class DiagnosticHelper { + public readonly struct DiagnosticWrapper + { + /// + /// Code-style options can have a ReportDiagnostic.Suppress severity. Such diagnostics shouldn't + /// be reported, so to do that we want to create a "null" diagnostic. + /// Because context.ReportDiagnostic doesn't take null, and it's tedious to do null check in every analyzer, + /// we create extension methods that check for null. But the parameter type has to be different for the + /// compiler to resolve it during overload resolution. So we use DiagnosticWrapper as the parameter type. + /// + /// + public DiagnosticWrapper(Diagnostic? diagnostic) + { + Diagnostic = diagnostic; + } + + public Diagnostic? Diagnostic { get; } + } + + public static void ReportDiagnostic(this AdditionalFileAnalysisContext context, DiagnosticWrapper diagnostic) + { + if (diagnostic.Diagnostic is not null) + { + context.ReportDiagnostic(diagnostic.Diagnostic); + } + } + + public static void ReportDiagnostic(this CodeBlockAnalysisContext context, DiagnosticWrapper diagnostic) + { + if (diagnostic.Diagnostic is not null) + { + context.ReportDiagnostic(diagnostic.Diagnostic); + } + } + + public static void ReportDiagnostic(this CompilationAnalysisContext context, DiagnosticWrapper diagnostic) + { + if (diagnostic.Diagnostic is not null) + { + context.ReportDiagnostic(diagnostic.Diagnostic); + } + } + + public static void ReportDiagnostic(this OperationAnalysisContext context, DiagnosticWrapper diagnostic) + { + if (diagnostic.Diagnostic is not null) + { + context.ReportDiagnostic(diagnostic.Diagnostic); + } + } + + public static void ReportDiagnostic(this OperationBlockAnalysisContext context, DiagnosticWrapper diagnostic) + { + if (diagnostic.Diagnostic is not null) + { + context.ReportDiagnostic(diagnostic.Diagnostic); + } + } + + public static void ReportDiagnostic(this SemanticModelAnalysisContext context, DiagnosticWrapper diagnostic) + { + if (diagnostic.Diagnostic is not null) + { + context.ReportDiagnostic(diagnostic.Diagnostic); + } + } + + public static void ReportDiagnostic(this SymbolAnalysisContext context, DiagnosticWrapper diagnostic) + { + if (diagnostic.Diagnostic is not null) + { + context.ReportDiagnostic(diagnostic.Diagnostic); + } + } + + public static void ReportDiagnostic(this SyntaxNodeAnalysisContext context, DiagnosticWrapper diagnostic) + { + if (diagnostic.Diagnostic is not null) + { + context.ReportDiagnostic(diagnostic.Diagnostic); + } + } + + public static void ReportDiagnostic(this SyntaxTreeAnalysisContext context, DiagnosticWrapper diagnostic) + { + if (diagnostic.Diagnostic is not null) + { + context.ReportDiagnostic(diagnostic.Diagnostic); + } + } + /// /// Creates a instance. /// @@ -35,7 +124,7 @@ internal static class DiagnosticHelper /// /// Arguments to the message of the diagnostic. /// The instance. - public static Diagnostic Create( + public static DiagnosticWrapper Create( DiagnosticDescriptor descriptor, Location location, ReportDiagnostic effectiveSeverity, @@ -48,17 +137,12 @@ public static Diagnostic Create( throw new ArgumentNullException(nameof(descriptor)); } - LocalizableString message; - if (messageArgs == null || messageArgs.Length == 0) - { - message = descriptor.MessageFormat; - } - else + if (effectiveSeverity == CodeAnalysis.ReportDiagnostic.Suppress) { - message = new LocalizableStringWithArguments(descriptor.MessageFormat, messageArgs); + return new(null); } - return CreateWithMessage(descriptor, location, effectiveSeverity, additionalLocations, properties, message); + return new(Diagnostic.Create(descriptor, location, effectiveSeverity.ToDiagnosticSeverity() ?? descriptor.DefaultSeverity, additionalLocations, properties, messageArgs)); } /// @@ -80,7 +164,7 @@ public static Diagnostic Create( /// /// Arguments to the message of the diagnostic. /// The instance. - public static Diagnostic CreateWithLocationTags( + public static DiagnosticWrapper CreateWithLocationTags( DiagnosticDescriptor descriptor, Location location, ReportDiagnostic effectiveSeverity, @@ -128,7 +212,7 @@ public static Diagnostic CreateWithLocationTags( /// /// Arguments to the message of the diagnostic. /// The instance. - public static Diagnostic CreateWithLocationTags( + public static DiagnosticWrapper CreateWithLocationTags( DiagnosticDescriptor descriptor, Location location, ReportDiagnostic effectiveSeverity, @@ -174,7 +258,7 @@ public static Diagnostic CreateWithLocationTags( /// /// Arguments to the message of the diagnostic. /// The instance. - private static Diagnostic CreateWithLocationTags( + private static DiagnosticWrapper CreateWithLocationTags( DiagnosticDescriptor descriptor, Location location, ReportDiagnostic effectiveSeverity, @@ -206,55 +290,6 @@ static string EncodeIndices(IEnumerable indices, int additionalLocationsLen } } - /// - /// Creates a instance. - /// - /// A describing the diagnostic. - /// An optional primary location of the diagnostic. If null, will return . - /// Effective severity of the diagnostic. - /// - /// An optional set of additional locations related to the diagnostic. - /// Typically, these are locations of other items referenced in the message. - /// If null, will return an empty list. - /// - /// - /// An optional set of name-value pairs by means of which the analyzer that creates the diagnostic - /// can convey more detailed information to the fixer. If null, will return - /// . - /// - /// Localizable message for the diagnostic. - /// The instance. - public static Diagnostic CreateWithMessage( - DiagnosticDescriptor descriptor, - Location location, - ReportDiagnostic effectiveSeverity, - IEnumerable? additionalLocations, - ImmutableDictionary? properties, - LocalizableString message) - { - if (descriptor == null) - { - throw new ArgumentNullException(nameof(descriptor)); - } - - return Diagnostic.Create( - descriptor.Id, - descriptor.Category, - message, - effectiveSeverity.ToDiagnosticSeverity() ?? descriptor.DefaultSeverity, - descriptor.DefaultSeverity, - descriptor.IsEnabledByDefault, - warningLevel: effectiveSeverity.WithDefaultSeverity(descriptor.DefaultSeverity) == ReportDiagnostic.Error ? 0 : 1, - effectiveSeverity == ReportDiagnostic.Suppress, - descriptor.Title, - descriptor.Description, - descriptor.HelpLinkUri, - location, - additionalLocations, - descriptor.CustomTags, - properties); - } - public static string? GetHelpLinkForDiagnosticId(string id) { // TODO: Add documentation for Regex and Json analyzer @@ -268,90 +303,5 @@ public static Diagnostic CreateWithMessage( Debug.Assert(id.StartsWith("IDE", StringComparison.Ordinal)); return $"https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/{id.ToLowerInvariant()}"; } - - public sealed class LocalizableStringWithArguments : LocalizableString, IObjectWritable - { - private readonly LocalizableString _messageFormat; - private readonly string[] _formatArguments; - - static LocalizableStringWithArguments() - => ObjectBinder.RegisterTypeReader(typeof(LocalizableStringWithArguments), reader => new LocalizableStringWithArguments(reader)); - - public LocalizableStringWithArguments(LocalizableString messageFormat, params object[] formatArguments) - { - if (messageFormat == null) - { - throw new ArgumentNullException(nameof(messageFormat)); - } - - if (formatArguments == null) - { - throw new ArgumentNullException(nameof(formatArguments)); - } - - _messageFormat = messageFormat; - _formatArguments = new string[formatArguments.Length]; - for (var i = 0; i < formatArguments.Length; i++) - { - _formatArguments[i] = $"{formatArguments[i]}"; - } - } - - private LocalizableStringWithArguments(ObjectReader reader) - { - _messageFormat = (LocalizableString)reader.ReadValue(); - - var length = reader.ReadInt32(); - if (length == 0) - { - _formatArguments = Array.Empty(); - } - else - { - using var argumentsBuilderDisposer = ArrayBuilder.GetInstance(length, out var argumentsBuilder); - for (var i = 0; i < length; i++) - { - argumentsBuilder.Add(reader.ReadString()); - } - - _formatArguments = argumentsBuilder.ToArray(); - } - } - - bool IObjectWritable.ShouldReuseInSerialization => false; - - void IObjectWritable.WriteTo(ObjectWriter writer) - { - writer.WriteValue(_messageFormat); - var length = _formatArguments.Length; - writer.WriteInt32(length); - for (var i = 0; i < length; i++) - { - writer.WriteString(_formatArguments[i]); - } - } - - protected override string GetText(IFormatProvider? formatProvider) - { - var messageFormat = _messageFormat.ToString(formatProvider); - return messageFormat != null ? - (_formatArguments.Length > 0 ? string.Format(formatProvider, messageFormat, _formatArguments) : messageFormat) : - string.Empty; - } - - protected override bool AreEqual(object? other) - { - return other is LocalizableStringWithArguments otherResourceString && - _messageFormat.Equals(otherResourceString._messageFormat) && - _formatArguments.SequenceEqual(otherResourceString._formatArguments, (a, b) => a == b); - } - - protected override int GetHash() - { - return Hash.Combine( - _messageFormat.GetHashCode(), - Hash.CombineValues(_formatArguments)); - } - } } } diff --git a/src/Analyzers/Core/Analyzers/NamingStyle/NamingStyleDiagnosticAnalyzerBase.cs b/src/Analyzers/Core/Analyzers/NamingStyle/NamingStyleDiagnosticAnalyzerBase.cs index d0654f0214c51..b5487f658fb24 100644 --- a/src/Analyzers/Core/Analyzers/NamingStyle/NamingStyleDiagnosticAnalyzerBase.cs +++ b/src/Analyzers/Core/Analyzers/NamingStyle/NamingStyleDiagnosticAnalyzerBase.cs @@ -165,7 +165,7 @@ void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext) builder["OptionName"] = nameof(NamingStyleOptions.NamingPreferences); builder["OptionLanguage"] = compilation.Language; - return DiagnosticHelper.Create(Descriptor, symbol.Locations.First(), applicableRule.EnforcementLevel, additionalLocations: null, builder.ToImmutable(), failureReason); + return DiagnosticHelper.Create(Descriptor, symbol.Locations.First(), applicableRule.EnforcementLevel, additionalLocations: null, builder.ToImmutable(), failureReason).Diagnostic; } public override DiagnosticAnalyzerCategory GetAnalyzerCategory() diff --git a/src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs b/src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs index 52fb5b1a6786e..e01fd21e0807c 100644 --- a/src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs @@ -41,8 +41,22 @@ internal abstract class AbstractRemoveUnusedMembersDiagnosticAnalyzer GetAttributesForMethodsToIgnore(Compilation compilation) diff --git a/src/Analyzers/Core/Analyzers/RemoveUnusedParametersAndValues/AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs b/src/Analyzers/Core/Analyzers/RemoveUnusedParametersAndValues/AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs index 9e11f83d22ebc..39f31f46629fa 100644 --- a/src/Analyzers/Core/Analyzers/RemoveUnusedParametersAndValues/AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/RemoveUnusedParametersAndValues/AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs @@ -87,6 +87,30 @@ internal abstract partial class AbstractRemoveUnusedParametersAndValuesDiagnosti description: new LocalizableResourceString(nameof(AnalyzersResources.Avoid_unused_parameters_in_your_code_If_the_parameter_cannot_be_removed_then_change_its_name_so_it_starts_with_an_underscore_and_is_optionally_followed_by_an_integer_such_as__comma__1_comma__2_etc_These_are_treated_as_special_discard_symbol_names), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), isUnnecessary: true); + private static readonly DiagnosticDescriptor s_unusedParameterRuleForPublicApiHasReference = CreateDescriptorWithId( + IDEDiagnosticIds.UnusedParameterDiagnosticId, + EnforceOnBuildValues.UnusedParameter, + new LocalizableResourceString(nameof(AnalyzersResources.Remove_unused_parameter), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), + new LocalizableResourceString(nameof(AnalyzersResources.Parameter_0_can_be_removed_if_it_is_not_part_of_a_shipped_public_API_its_initial_value_is_never_used), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), + description: new LocalizableResourceString(nameof(AnalyzersResources.Avoid_unused_parameters_in_your_code_If_the_parameter_cannot_be_removed_then_change_its_name_so_it_starts_with_an_underscore_and_is_optionally_followed_by_an_integer_such_as__comma__1_comma__2_etc_These_are_treated_as_special_discard_symbol_names), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), + isUnnecessary: true); + + private static readonly DiagnosticDescriptor s_unusedParameterRuleForPublicApiNoReference = CreateDescriptorWithId( + IDEDiagnosticIds.UnusedParameterDiagnosticId, + EnforceOnBuildValues.UnusedParameter, + new LocalizableResourceString(nameof(AnalyzersResources.Remove_unused_parameter), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), + new LocalizableResourceString(nameof(AnalyzersResources.Remove_unused_parameter_0_if_it_is_not_part_of_a_shipped_public_API), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), + description: new LocalizableResourceString(nameof(AnalyzersResources.Avoid_unused_parameters_in_your_code_If_the_parameter_cannot_be_removed_then_change_its_name_so_it_starts_with_an_underscore_and_is_optionally_followed_by_an_integer_such_as__comma__1_comma__2_etc_These_are_treated_as_special_discard_symbol_names), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), + isUnnecessary: true); + + private static readonly DiagnosticDescriptor s_unusedParameterRuleForNonPublicApiHasReference = CreateDescriptorWithId( + IDEDiagnosticIds.UnusedParameterDiagnosticId, + EnforceOnBuildValues.UnusedParameter, + new LocalizableResourceString(nameof(AnalyzersResources.Remove_unused_parameter), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), + new LocalizableResourceString(nameof(AnalyzersResources.Parameter_0_can_be_removed_its_initial_value_is_never_used), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), + description: new LocalizableResourceString(nameof(AnalyzersResources.Avoid_unused_parameters_in_your_code_If_the_parameter_cannot_be_removed_then_change_its_name_so_it_starts_with_an_underscore_and_is_optionally_followed_by_an_integer_such_as__comma__1_comma__2_etc_These_are_treated_as_special_discard_symbol_names), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)), + isUnnecessary: true); + private static readonly PropertiesMap s_propertiesMap = CreatePropertiesMap(); protected AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer( @@ -97,7 +121,10 @@ protected AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer( .Add(s_expressionValueIsUnusedRule, unusedValueExpressionStatementOption) .Add(s_valueAssignedIsUnusedRule, unusedValueAssignmentOption), ImmutableDictionary.Empty - .Add(s_unusedParameterRule, CodeStyleOptions2.UnusedParameters), + .Add(s_unusedParameterRule, CodeStyleOptions2.UnusedParameters) + .Add(s_unusedParameterRuleForPublicApiHasReference, CodeStyleOptions2.UnusedParameters) + .Add(s_unusedParameterRuleForPublicApiNoReference, CodeStyleOptions2.UnusedParameters) + .Add(s_unusedParameterRuleForNonPublicApiHasReference, CodeStyleOptions2.UnusedParameters), language) { } diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.cs.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.cs.xlf index 326690d1a38ab..a8af1d646c156 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.cs.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.cs.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - Soukromá metoda {0} se může odebrat, protože se nikdy nevolá. + Private method '{0}' can be removed as it is never invoked + Soukromá metoda {0} se může odebrat, protože se nikdy nevolá. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - Privátní vlastnost {0} se dá převést na metodu, protože její přístupový objekt get se nikdy nevyvolá. + Private property '{0}' can be converted to a method as its get accessor is never invoked + Privátní vlastnost {0} se dá převést na metodu, protože její přístupový objekt get se nikdy nevyvolá. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.de.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.de.xlf index 8aa00ebcaba61..d0b04cd0100e7 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.de.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.de.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - Die private Methode "{0}" kann entfernt werden, da sie nie aufgerufen wird. + Private method '{0}' can be removed as it is never invoked + Die private Methode "{0}" kann entfernt werden, da sie nie aufgerufen wird. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - Die private Eigenschaft "{0}" kann in eine Methode konvertiert werden, weil ihr get-Accessor niemals aufgerufen wird. + Private property '{0}' can be converted to a method as its get accessor is never invoked + Die private Eigenschaft "{0}" kann in eine Methode konvertiert werden, weil ihr get-Accessor niemals aufgerufen wird. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.es.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.es.xlf index 87b1d5ddbeda3..4dd507136da48 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.es.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.es.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - El método privado "{0}" se puede quitar porque nunca se invoca. + Private method '{0}' can be removed as it is never invoked + El método privado "{0}" se puede quitar porque nunca se invoca. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - La propiedad privada "{0}" se puede convertir en un método porque su descriptor de acceso get nunca se invoca. + Private property '{0}' can be converted to a method as its get accessor is never invoked + La propiedad privada "{0}" se puede convertir en un método porque su descriptor de acceso get nunca se invoca. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.fr.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.fr.xlf index 742c3c8147542..9471ea1551bef 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.fr.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.fr.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - Impossible de supprimer la méthode privée '{0}', car elle n'est jamais appelée. + Private method '{0}' can be removed as it is never invoked + Impossible de supprimer la méthode privée '{0}', car elle n'est jamais appelée. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - La propriété privée '{0}' peut être convertie en méthode, car son accesseur get n'est jamais appelé. + Private property '{0}' can be converted to a method as its get accessor is never invoked + La propriété privée '{0}' peut être convertie en méthode, car son accesseur get n'est jamais appelé. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.it.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.it.xlf index e3e6b009e414b..6fe3a540d36cc 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.it.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.it.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - Il metodo privato '{0}' può essere rimosso perché non viene mai richiamato. + Private method '{0}' can be removed as it is never invoked + Il metodo privato '{0}' può essere rimosso perché non viene mai richiamato. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - È possibile convertire la proprietà privata '{0}' in un metodo perché la relativa funzione di accesso get non viene mai richiamata. + Private property '{0}' can be converted to a method as its get accessor is never invoked + È possibile convertire la proprietà privata '{0}' in un metodo perché la relativa funzione di accesso get non viene mai richiamata. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ja.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ja.xlf index 57762aa136dd4..b54e405b760c3 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ja.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ja.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - プライベート メソッド '{0}' が呼び出されることがないよう削除できます。 + Private method '{0}' can be removed as it is never invoked + プライベート メソッド '{0}' が呼び出されることがないよう削除できます。 - Private property '{0}' can be converted to a method as its get accessor is never invoked. - プライベート プロパティ '{0}' は、その get アクセサーが呼び出されることがないため、メソッドに変換できます。 + Private property '{0}' can be converted to a method as its get accessor is never invoked + プライベート プロパティ '{0}' は、その get アクセサーが呼び出されることがないため、メソッドに変換できます。 diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ko.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ko.xlf index 3dbcdb4e2162a..1bec22439da5b 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ko.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ko.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - 프라이빗 메서드 '{0}'은(는) 호출되지 않으므로 제거할 수 있습니다. + Private method '{0}' can be removed as it is never invoked + 프라이빗 메서드 '{0}'은(는) 호출되지 않으므로 제거할 수 있습니다. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - 해당 get 접근자가 호출되지 않았으므로 프라이빗 속성 '{0}'을(를) 메서드로 변환할 수 있습니다. + Private property '{0}' can be converted to a method as its get accessor is never invoked + 해당 get 접근자가 호출되지 않았으므로 프라이빗 속성 '{0}'을(를) 메서드로 변환할 수 있습니다. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pl.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pl.xlf index 7574ee31fa8ca..a362912ba9ab5 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pl.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pl.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - Metodę prywatną „{0}” można usunąć, ponieważ nie jest nigdy wywoływana. + Private method '{0}' can be removed as it is never invoked + Metodę prywatną „{0}” można usunąć, ponieważ nie jest nigdy wywoływana. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - Właściwość prywatną „{0}” można przekonwertować na metodę, ponieważ jej metoda dostępu get nie jest nigdy wywoływana. + Private property '{0}' can be converted to a method as its get accessor is never invoked + Właściwość prywatną „{0}” można przekonwertować na metodę, ponieważ jej metoda dostępu get nie jest nigdy wywoływana. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pt-BR.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pt-BR.xlf index f91b7c61305a3..d6e1ed9efc888 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pt-BR.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pt-BR.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - O método particular '{0}' pode ser removido pois nunca é invocado. + Private method '{0}' can be removed as it is never invoked + O método particular '{0}' pode ser removido pois nunca é invocado. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - A propriedade privada '{0}' pode ser convertida em um método porque seu acessador get nunca é invocado. + Private property '{0}' can be converted to a method as its get accessor is never invoked + A propriedade privada '{0}' pode ser convertida em um método porque seu acessador get nunca é invocado. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ru.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ru.xlf index ba5dd45ad4f41..001ad30ff67e1 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ru.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ru.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - Закрытый метод "{0}" можно удалить, так как он никогда не вызывается. + Private method '{0}' can be removed as it is never invoked + Закрытый метод "{0}" можно удалить, так как он никогда не вызывается. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - Частное свойство "{0}" можно преобразовать в метод, так как его метод доступа get никогда не вызывается. + Private property '{0}' can be converted to a method as its get accessor is never invoked + Частное свойство "{0}" можно преобразовать в метод, так как его метод доступа get никогда не вызывается. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.tr.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.tr.xlf index 27950da9d1f48..4688688ad30dc 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.tr.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.tr.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - '{0}' özel metodu hiç çağrılmadığından kaldırılabilir. + Private method '{0}' can be removed as it is never invoked + '{0}' özel metodu hiç çağrılmadığından kaldırılabilir. - Private property '{0}' can be converted to a method as its get accessor is never invoked. - '{0}' özel özelliği, bu özelliğin get erişimcisi hiçbir zaman çağrılmadığı için bir yönteme dönüştürülebilir. + Private property '{0}' can be converted to a method as its get accessor is never invoked + '{0}' özel özelliği, bu özelliğin get erişimcisi hiçbir zaman çağrılmadığı için bir yönteme dönüştürülebilir. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hans.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hans.xlf index 2086c7ecd8b4a..04c3e875167ff 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hans.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hans.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - 私有方法“{0}”可以删除,因为它永远不会被调用。 + Private method '{0}' can be removed as it is never invoked + 私有方法“{0}”可以删除,因为它永远不会被调用。 - Private property '{0}' can be converted to a method as its get accessor is never invoked. - 私有属性 "{0}" 可以转换为方法,因为永远不会调用它的 get 访问器。 + Private property '{0}' can be converted to a method as its get accessor is never invoked + 私有属性 "{0}" 可以转换为方法,因为永远不会调用它的 get 访问器。 diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hant.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hant.xlf index d194807948f40..86a12b484e56b 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hant.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hant.xlf @@ -243,13 +243,13 @@ - Private method '{0}' can be removed as it is never invoked. - 因為永遠不會叫用私用方法 ‘{0}’,所以可予以移除。 + Private method '{0}' can be removed as it is never invoked + 因為永遠不會叫用私用方法 ‘{0}’,所以可予以移除。 - Private property '{0}' can be converted to a method as its get accessor is never invoked. - 系統永遠不會叫用私用屬性 '{0}' 的 get 存取子,因此該屬性可以轉換成方法。 + Private property '{0}' can be converted to a method as its get accessor is never invoked + 系統永遠不會叫用私用屬性 '{0}' 的 get 存取子,因此該屬性可以轉換成方法。 diff --git a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider_Analysis.cs b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider_Analysis.cs index bb21394dadfff..5e554b8e628a2 100644 --- a/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider_Analysis.cs +++ b/src/Features/CSharp/Portable/UseExpressionBodyForLambda/UseExpressionBodyForLambdaCodeStyleProvider_Analysis.cs @@ -47,7 +47,7 @@ private Diagnostic AnalyzeSyntax( var properties = ImmutableDictionary.Empty; return DiagnosticHelper.Create( CreateDescriptorWithId(UseExpressionBodyTitle, UseExpressionBodyTitle), - location, option.Notification.Severity, additionalLocations, properties); + location, option.Notification.Severity, additionalLocations, properties).Diagnostic; } if (CanOfferUseBlockBody(semanticModel, option.Value, declaration, cancellationToken)) @@ -60,7 +60,7 @@ private Diagnostic AnalyzeSyntax( var additionalLocations = ImmutableArray.Create(declaration.GetLocation()); return DiagnosticHelper.Create( CreateDescriptorWithId(UseBlockBodyTitle, UseBlockBodyTitle), - location, option.Notification.Severity, additionalLocations, properties); + location, option.Notification.Severity, additionalLocations, properties).Diagnostic; } return null; diff --git a/src/Features/Core/Portable/SimplifyTypeNames/SimplifyTypeNamesDiagnosticAnalyzerBase.cs b/src/Features/Core/Portable/SimplifyTypeNames/SimplifyTypeNamesDiagnosticAnalyzerBase.cs index fac87b03a0323..ed0298bb9efe9 100644 --- a/src/Features/Core/Portable/SimplifyTypeNames/SimplifyTypeNamesDiagnosticAnalyzerBase.cs +++ b/src/Features/Core/Portable/SimplifyTypeNames/SimplifyTypeNamesDiagnosticAnalyzerBase.cs @@ -145,10 +145,10 @@ public bool TrySimplify(SemanticModel model, SyntaxNode node, [NotNullWhen(true) } diagnostic = CreateDiagnostic(model, options, issueSpan, diagnosticId, inDeclaration); - return true; + return diagnostic is not null; } - internal static Diagnostic CreateDiagnostic(SemanticModel model, TSimplifierOptions options, TextSpan issueSpan, string diagnosticId, bool inDeclaration) + private static Diagnostic? CreateDiagnostic(SemanticModel model, TSimplifierOptions options, TextSpan issueSpan, string diagnosticId, bool inDeclaration) { DiagnosticDescriptor descriptor; ReportDiagnostic severity; @@ -203,7 +203,7 @@ internal static Diagnostic CreateDiagnostic(SemanticModel model, TSimplifierOpti } #endif - return diagnostic; + return diagnostic.Diagnostic; } public DiagnosticAnalyzerCategory GetAnalyzerCategory()