diff --git a/src/Analyzers.xml b/src/Analyzers.xml index 3668c8bb60..1964f63681 100644 --- a/src/Analyzers.xml +++ b/src/Analyzers.xml @@ -328,30 +328,6 @@ enum Bar - - - RCS0012 @@ -445,33 +421,6 @@ namespace N - - - RCS0016 @@ -698,29 +647,6 @@ namespace N - - - RCS0028 @@ -742,25 +668,6 @@ namespace N - - - RCS0029 @@ -832,23 +739,6 @@ namespace N - - - RCS0033 @@ -1231,28 +1121,6 @@ while (x);]]> - - - RCS0052 @@ -1272,23 +1140,6 @@ while (x);]]> - - - RCS0053 @@ -1900,35 +1751,6 @@ foreach (var item in items) RCS1015 @@ -1979,73 +1801,6 @@ foreach (var item in items) RCS1017 @@ -2100,32 +1855,6 @@ foreach (var item in items) - - - RCS1019 @@ -2504,42 +2233,6 @@ if (f) - - - RCS1037 @@ -2710,19 +2403,6 @@ catch (Exception ex) - - - RCS1046 @@ -2830,21 +2510,6 @@ if (!f) - - - RCS1051 @@ -2862,22 +2527,6 @@ if (!f) - - - RCS1052 @@ -3580,21 +3229,6 @@ object x = queue.Peek();]]> - - - RCS1079 @@ -3779,28 +3413,6 @@ public string Foo - - - RCS1091 @@ -3892,27 +3504,6 @@ namespace Foo - - - RCS1097 @@ -4105,23 +3696,6 @@ else - - - RCS1105 @@ -6045,21 +5619,6 @@ int i = (x != null) ? x.Value.GetHashCode() : 0;]]> - - - RCS1208 @@ -6234,15 +5793,6 @@ x = "";]]> RCS1214 @@ -7292,20 +6842,6 @@ public class C - - - RCS1247 @@ -7373,25 +6909,6 @@ void M() - - - RCS1249 diff --git a/src/Analyzers/CSharp/Analysis/AnalyzerOptionIsObsoleteAnalyzer.cs b/src/Analyzers/CSharp/Analysis/AnalyzerOptionIsObsoleteAnalyzer.cs deleted file mode 100644 index daf2669f50..0000000000 --- a/src/Analyzers/CSharp/Analysis/AnalyzerOptionIsObsoleteAnalyzer.cs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Immutable; -using System.IO; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; - -namespace Roslynator.CSharp.Analysis; - -[DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class AnalyzerOptionIsObsoleteAnalyzer : AbstractAnalyzerOptionIsObsoleteAnalyzer -{ - private static ImmutableArray _supportedDiagnostics; - - public override ImmutableArray SupportedDiagnostics - { - get - { - if (_supportedDiagnostics.IsDefault) - Immutable.InterlockedInitialize(ref _supportedDiagnostics, CommonDiagnosticRules.AnalyzerOptionIsObsolete); - - return _supportedDiagnostics; - } - } - - public override void Initialize(AnalysisContext context) - { - context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); - - context.RegisterCompilationStartAction(compilationContext => - { - var flags = Flags.None; - - CompilationOptions compilationOptions = compilationContext.Compilation.Options; - - compilationContext.RegisterSyntaxTreeAction(context => - { - // files generated by source generator have relative path - if (!Path.IsPathRooted(context.Tree.FilePath)) - return; - - AnalyzerConfigOptions options = context.GetConfigOptions(); - - Validate(ref context, compilationOptions, options, Flags.ConvertBitwiseOperationToHasFlagCall, ref flags, DiagnosticRules.UseHasFlagMethodOrBitwiseOperator, ConfigOptions.EnumHasFlagStyle, LegacyConfigOptions.ConvertBitwiseOperationToHasFlagCall, ConfigOptionValues.EnumHasFlagStyle_Method); - Validate(ref context, compilationOptions, options, Flags.ConvertExpressionBodyToBlockBody, ref flags, DiagnosticRules.UseBlockBodyOrExpressionBody, ConfigOptions.BodyStyle, LegacyConfigOptions.ConvertExpressionBodyToBlockBody, ConfigOptionValues.BodyStyle_Block); - Validate(ref context, compilationOptions, options, Flags.ConvertExpressionBodyToBlockBodyWhenDeclarationIsMultiLine, ref flags, DiagnosticRules.UseBlockBodyOrExpressionBody, ConfigOptions.BodyStyle, LegacyConfigOptions.ConvertExpressionBodyToBlockBodyWhenDeclarationIsMultiLine, "true"); - Validate(ref context, compilationOptions, options, Flags.ConvertExpressionBodyToBlockBodyWhenExpressionIsMultiLine, ref flags, DiagnosticRules.UseBlockBodyOrExpressionBody, ConfigOptions.BodyStyle, LegacyConfigOptions.ConvertExpressionBodyToBlockBodyWhenExpressionIsMultiLine, "true"); - Validate(ref context, compilationOptions, options, Flags.ConvertMethodGroupToAnonymousFunction, ref flags, DiagnosticRules.UseAnonymousFunctionOrMethodGroup, ConfigOptions.UseAnonymousFunctionOrMethodGroup, LegacyConfigOptions.ConvertMethodGroupToAnonymousFunction, ConfigOptionValues.UseAnonymousFunctionOrMethodGroup_AnonymousFunction); - Validate(ref context, compilationOptions, options, Flags.RemoveCallToConfigureAwait, ref flags, DiagnosticRules.ConfigureAwait, ConfigOptions.ConfigureAwait, LegacyConfigOptions.RemoveCallToConfigureAwait, "false"); - Validate(ref context, compilationOptions, options, Flags.RemoveAccessibilityModifiers, ref flags, DiagnosticRules.AddOrRemoveAccessibilityModifiers, ConfigOptions.AccessibilityModifiers, LegacyConfigOptions.RemoveAccessibilityModifiers, ConfigOptionValues.AccessibilityModifiers_Implicit); - Validate(ref context, compilationOptions, options, Flags.RemoveEmptyLineBetweenClosingBraceAndSwitchSection, ref flags, DiagnosticRules.RemoveUnnecessaryBlankLine, ConfigOptions.BlankLineBetweenClosingBraceAndSwitchSection, LegacyConfigOptions.RemoveEmptyLineBetweenClosingBraceAndSwitchSection, "false"); - Validate(ref context, compilationOptions, options, Flags.RemoveParenthesesFromConditionOfConditionalExpressionWhenExpressionIsSingleToken, ref flags, DiagnosticRules.AddOrRemoveParenthesesFromConditionInConditionalOperator, ConfigOptions.ConditionalOperatorConditionParenthesesStyle, LegacyConfigOptions.RemoveParenthesesFromConditionOfConditionalExpressionWhenExpressionIsSingleToken, ConfigOptionValues.ConditionalOperatorConditionParenthesesStyle_OmitWhenConditionIsSingleToken); - Validate(ref context, compilationOptions, options, Flags.RemoveParenthesesWhenCreatingNewObject, ref flags, DiagnosticRules.UseImplicitOrExplicitObjectCreation, ConfigOptions.ObjectCreationParenthesesStyle, LegacyConfigOptions.RemoveParenthesesWhenCreatingNewObject, ConfigOptionValues.ObjectCreationParenthesesStyle_Omit); -#pragma warning disable CS0618 // Type or member is obsolete - Validate(ref context, compilationOptions, options, Flags.SuppressUnityScriptMethods, ref flags, DiagnosticRules.RemoveUnusedMemberDeclaration, ConfigOptions.SuppressUnityScriptMethods, LegacyConfigOptions.SuppressUnityScriptMethods, "true"); -#pragma warning restore CS0618 // Type or member is obsolete - Validate(ref context, compilationOptions, options, Flags.UseComparisonInsteadPatternMatchingToCheckForNull, ref flags, DiagnosticRules.NormalizeNullCheck, ConfigOptions.NullCheckStyle, LegacyConfigOptions.UseComparisonInsteadPatternMatchingToCheckForNull, ConfigOptionValues.NullCheckStyle_EqualityOperator); - Validate(ref context, compilationOptions, options, Flags.UseImplicitlyTypedArray, ref flags, DiagnosticRules.UseExplicitlyOrImplicitlyTypedArray, ConfigOptions.ArrayCreationTypeStyle, LegacyConfigOptions.UseImplicitlyTypedArray, ConfigOptionValues.ArrayCreationTypeStyle_Implicit); - Validate(ref context, compilationOptions, options, Flags.UseImplicitlyTypedArrayWhenTypeIsObvious, ref flags, DiagnosticRules.UseExplicitlyOrImplicitlyTypedArray, ConfigOptions.ArrayCreationTypeStyle, LegacyConfigOptions.UseImplicitlyTypedArrayWhenTypeIsObvious, ConfigOptionValues.ArrayCreationTypeStyle_ImplicitWhenTypeIsObvious); - Validate(ref context, compilationOptions, options, Flags.UseStringEmptyInsteadOfEmptyStringLiteral, ref flags, DiagnosticRules.UseEmptyStringLiteralOrStringEmpty, ConfigOptions.EmptyStringStyle, LegacyConfigOptions.UseStringEmptyInsteadOfEmptyStringLiteral, ConfigOptionValues.EmptyStringStyle_Field); - }); - }); - } - - private static void Validate( - ref SyntaxTreeAnalysisContext context, - CompilationOptions compilationOptions, - AnalyzerConfigOptions configOptions, - Flags flag, - ref Flags flags, - DiagnosticDescriptor analyzer, - ConfigOptionDescriptor option, - LegacyConfigOptionDescriptor legacyOption, - string newValue) - { - if (!flags.HasFlag(flag) - && analyzer.IsEffective(context.Tree, compilationOptions, context.CancellationToken) - && TryReportObsoleteOption(context, configOptions, legacyOption, option, newValue)) - { - flags |= flag; - } - } - - [Flags] - private enum Flags - { - None, - ConvertBitwiseOperationToHasFlagCall, - ConvertExpressionBodyToBlockBody, - ConvertExpressionBodyToBlockBodyWhenDeclarationIsMultiLine, - ConvertExpressionBodyToBlockBodyWhenExpressionIsMultiLine, - ConvertMethodGroupToAnonymousFunction, - RemoveAccessibilityModifiers, - RemoveCallToConfigureAwait, - RemoveEmptyLineBetweenClosingBraceAndSwitchSection, - RemoveParenthesesFromConditionOfConditionalExpressionWhenExpressionIsSingleToken, - RemoveParenthesesWhenCreatingNewObject, - SuppressUnityScriptMethods, - UseComparisonInsteadPatternMatchingToCheckForNull, - UseImplicitlyTypedArray, - UseImplicitlyTypedArrayWhenTypeIsObvious, - UseStringEmptyInsteadOfEmptyStringLiteral, - } -} diff --git a/src/Common/CSharp/CodeStyle/BodyStyle.cs b/src/Common/CSharp/CodeStyle/BodyStyle.cs index 41e66d61b3..bb56d193bc 100644 --- a/src/Common/CSharp/CodeStyle/BodyStyle.cs +++ b/src/Common/CSharp/CodeStyle/BodyStyle.cs @@ -43,23 +43,17 @@ public static BodyStyle Create(SyntaxNodeAnalysisContext context) option = BodyStyleOption.Expression; } } - else if (configOptions.TryGetValueAsBool(LegacyConfigOptions.ConvertExpressionBodyToBlockBody, out bool useBlockBody)) - { - option = (useBlockBody) ? BodyStyleOption.Block : BodyStyleOption.Expression; - } bool? useBlockBodyWhenDeclarationIsMultiLine = null; - if (ConfigOptions.GetValueAsBool(configOptions, ConfigOptions.UseBlockBodyWhenDeclarationSpansOverMultipleLines) == true - || configOptions.IsEnabled(LegacyConfigOptions.ConvertExpressionBodyToBlockBodyWhenDeclarationIsMultiLine)) + if (ConfigOptions.GetValueAsBool(configOptions, ConfigOptions.UseBlockBodyWhenDeclarationSpansOverMultipleLines) == true) { useBlockBodyWhenDeclarationIsMultiLine = true; } bool? useBlockBodyWhenExpressionIsMultiline = null; - if (ConfigOptions.GetValueAsBool(configOptions, ConfigOptions.UseBlockBodyWhenExpressionSpansOverMultipleLines) == true - || configOptions.IsEnabled(LegacyConfigOptions.ConvertExpressionBodyToBlockBodyWhenExpressionIsMultiLine)) + if (ConfigOptions.GetValueAsBool(configOptions, ConfigOptions.UseBlockBodyWhenExpressionSpansOverMultipleLines) == true) { useBlockBodyWhenExpressionIsMultiline = true; } @@ -67,7 +61,7 @@ public static BodyStyle Create(SyntaxNodeAnalysisContext context) return new BodyStyle(option, useBlockBodyWhenDeclarationIsMultiLine, useBlockBodyWhenExpressionIsMultiline); } - internal enum BodyStyleOption + private enum BodyStyleOption { None, Block, diff --git a/src/Common/CSharp/Extensions/CodeStyleExtensions.cs b/src/Common/CSharp/Extensions/CodeStyleExtensions.cs index 48fafdc967..1abfbbab7b 100644 --- a/src/Common/CSharp/Extensions/CodeStyleExtensions.cs +++ b/src/Common/CSharp/Extensions/CodeStyleExtensions.cs @@ -102,9 +102,6 @@ public static NewLineStyle GetNewLineBeforeWhileInDoStatement(this SyntaxNodeAna if (ConfigOptions.TryGetValueAsBool(configOptions, ConfigOptions.NewLineBeforeWhileInDoStatement, out bool addNewLine)) return (addNewLine) ? NewLineStyle.Add : NewLineStyle.Remove; - if (configOptions.TryGetValueAsBool(LegacyConfigOptions.RemoveNewLineBetweenClosingBraceAndWhileKeyword, out bool removeLine)) - return (removeLine) ? NewLineStyle.Remove : NewLineStyle.Add; - return NewLineStyle.None; } @@ -113,9 +110,6 @@ public static NewLinePosition GetBinaryOperatorNewLinePosition(this AnalyzerConf if (TryGetNewLinePosition(configOptions, ConfigOptions.BinaryOperatorNewLine, out NewLinePosition newLinePosition)) return newLinePosition; - if (configOptions.IsEnabled(LegacyConfigOptions.AddNewLineAfterBinaryOperatorInsteadOfBeforeIt)) - return NewLinePosition.After; - return NewLinePosition.None; } @@ -124,9 +118,6 @@ public static NewLinePosition GetConditionalOperatorNewLinePosition(this Analyze if (TryGetNewLinePosition(configOptions, ConfigOptions.ConditionalOperatorNewLine, out NewLinePosition newLinePosition)) return newLinePosition; - if (configOptions.IsEnabled(LegacyConfigOptions.AddNewLineAfterConditionalOperatorInsteadOfBeforeIt)) - return NewLinePosition.After; - return NewLinePosition.None; } @@ -135,9 +126,6 @@ public static NewLinePosition GetArrowTokenNewLinePosition(this AnalyzerConfigOp if (TryGetNewLinePosition(configOptions, ConfigOptions.ArrowTokenNewLine, out NewLinePosition newLinePosition)) return newLinePosition; - if (configOptions.IsEnabled(LegacyConfigOptions.AddNewLineAfterExpressionBodyArrowInsteadOfBeforeIt)) - return NewLinePosition.After; - return NewLinePosition.None; } @@ -146,9 +134,6 @@ public static NewLinePosition GetEqualsTokenNewLinePosition(this AnalyzerConfigO if (TryGetNewLinePosition(configOptions, ConfigOptions.EqualsTokenNewLine, out NewLinePosition newLinePosition)) return newLinePosition; - if (configOptions.IsEnabled(LegacyConfigOptions.AddNewLineAfterEqualsSignInsteadOfBeforeIt)) - return NewLinePosition.After; - return NewLinePosition.None; } @@ -175,9 +160,6 @@ public static UsingDirectiveBlankLineStyle GetBlankLineBetweenUsingDirectives(th } } - if (ConfigOptions.TryGetValueAsBool(configOptions, LegacyConfigOptions.RemoveEmptyLineBetweenUsingDirectivesWithDifferentRootNamespace, out bool removeLine)) - return (removeLine) ? UsingDirectiveBlankLineStyle.Never : UsingDirectiveBlankLineStyle.SeparateGroups; - return UsingDirectiveBlankLineStyle.None; } @@ -226,9 +208,6 @@ public static BlankLineStyle GetBlankLineBetweenSingleLineAccessors(this SyntaxN if (ConfigOptions.TryGetValueAsBool(configOptions, ConfigOptions.BlankLineBetweenSingleLineAccessors, out bool addLine)) return (addLine) ? BlankLineStyle.Add : BlankLineStyle.Remove; - if (ConfigOptions.TryGetValueAsBool(configOptions, LegacyConfigOptions.RemoveEmptyLineBetweenSingleLineAccessors, out bool removeLine)) - return (removeLine) ? BlankLineStyle.Remove : BlankLineStyle.Add; - return BlankLineStyle.None; } @@ -248,9 +227,6 @@ public static BlankLineStyle GetBlankLineBetweenSingleLineAccessors(this SyntaxN } } - if (configOptions.IsEnabled(LegacyConfigOptions.ConvertMethodGroupToAnonymousFunction)) - return true; - return null; } @@ -270,9 +246,6 @@ public static EnumFlagOperationStyle GetEnumHasFlagStyle(this SyntaxNodeAnalysis } } - if (configOptions.IsEnabled(LegacyConfigOptions.ConvertBitwiseOperationToHasFlagCall)) - return EnumFlagOperationStyle.HasFlagMethod; - return EnumFlagOperationStyle.None; } @@ -285,9 +258,6 @@ public static ConfigureAwaitStyle GetConfigureAwaitStyle(this SyntaxNodeAnalysis return (value) ? ConfigureAwaitStyle.Include : ConfigureAwaitStyle.Omit; } - if (configOptions.IsEnabled(LegacyConfigOptions.RemoveCallToConfigureAwait)) - return ConfigureAwaitStyle.Omit; - return ConfigureAwaitStyle.None; } @@ -304,9 +274,6 @@ public static EmptyStringStyle GetEmptyStringStyle(this SyntaxNodeAnalysisContex return EmptyStringStyle.Literal; } - if (configOptions.IsEnabled(LegacyConfigOptions.UseStringEmptyInsteadOfEmptyStringLiteral)) - return EmptyStringStyle.Field; - return EmptyStringStyle.None; } @@ -323,9 +290,6 @@ public static NullCheckStyle GetNullCheckStyle(this SyntaxNodeAnalysisContext co return NullCheckStyle.PatternMatching; } - if (configOptions.IsEnabled(LegacyConfigOptions.UseComparisonInsteadPatternMatchingToCheckForNull)) - return NullCheckStyle.EqualityOperator; - return NullCheckStyle.None; } @@ -349,9 +313,6 @@ public static ConditionalExpressionParenthesesStyle GetConditionalExpressionPare } } - if (configOptions.IsEnabled(LegacyConfigOptions.RemoveParenthesesFromConditionOfConditionalExpressionWhenExpressionIsSingleToken)) - return ConditionalExpressionParenthesesStyle.OmitWhenConditionIsSingleToken; - return ConditionalExpressionParenthesesStyle.None; } @@ -371,9 +332,6 @@ public static ObjectCreationParenthesesStyle GetObjectCreationParenthesesStyle(t } } - if (context.IsEnabled(LegacyConfigOptions.RemoveParenthesesWhenCreatingNewObject)) - return ObjectCreationParenthesesStyle.Omit; - return ObjectCreationParenthesesStyle.None; } @@ -393,9 +351,6 @@ public static AccessibilityModifierStyle GetAccessModifiersStyle(this SyntaxNode } } - if (ConfigOptions.TryGetValueAsBool(configOptions, LegacyConfigOptions.RemoveAccessibilityModifiers, out bool useImplicit)) - return (useImplicit) ? AccessibilityModifierStyle.Implicit : AccessibilityModifierStyle.Explicit; - return AccessibilityModifierStyle.None; } @@ -498,12 +453,6 @@ public static TypeStyle GetArrayCreationTypeStyle(this SyntaxNodeAnalysisContext } } - if (context.IsEnabled(LegacyConfigOptions.UseImplicitlyTypedArrayWhenTypeIsObvious)) - return TypeStyle.ImplicitWhenTypeIsObvious; - - if (context.IsEnabled(LegacyConfigOptions.UseImplicitlyTypedArray)) - return TypeStyle.Implicit; - return TypeStyle.None; } @@ -582,9 +531,6 @@ public static BodyStyle GetBodyStyle(this SyntaxNodeAnalysisContext context) return value; } - if (context.TryGetOptionAsBool(LegacyConfigOptions.RemoveEmptyLineBetweenClosingBraceAndSwitchSection, out value)) - return !value; - return null; } @@ -608,9 +554,6 @@ public static BlankLineStyle GetBlankLineAfterFileScopedNamespaceDeclaration(thi return value; #pragma warning restore CS0618 // Type or member is obsolete - if (context.TryGetOptionAsBool(LegacyConfigOptions.SuppressUnityScriptMethods, out value)) - return value; - return null; } diff --git a/src/Common/LegacyConfigOptions.Generated.cs b/src/Common/LegacyConfigOptions.Generated.cs index bf02dbbffb..24a1ddcb54 100644 --- a/src/Common/LegacyConfigOptions.Generated.cs +++ b/src/Common/LegacyConfigOptions.Generated.cs @@ -6,28 +6,5 @@ namespace Roslynator { public static partial class LegacyConfigOptions { - public static readonly LegacyConfigOptionDescriptor AddNewLineAfterBinaryOperatorInsteadOfBeforeIt = new(key: "roslynator.RCS0027.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor AddNewLineAfterConditionalOperatorInsteadOfBeforeIt = new(key: "roslynator.RCS0028.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor AddNewLineAfterEqualsSignInsteadOfBeforeIt = new(key: "roslynator.RCS0052.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor AddNewLineAfterExpressionBodyArrowInsteadOfBeforeIt = new(key: "roslynator.RCS0032.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor ConvertBitwiseOperationToHasFlagCall = new(key: "roslynator.RCS1096.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor ConvertExpressionBodyToBlockBody = new(key: "roslynator.RCS1016.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor ConvertExpressionBodyToBlockBodyWhenDeclarationIsMultiLine = new(key: "roslynator.RCS1016.use_block_body_when_declaration_is_multiline", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor ConvertExpressionBodyToBlockBodyWhenExpressionIsMultiLine = new(key: "roslynator.RCS1016.use_block_body_when_expression_is_multiline", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor ConvertMethodGroupToAnonymousFunction = new(key: "roslynator.RCS1207.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor DoNotRenamePrivateStaticFieldToCamelCaseWithUnderscore = new(key: "roslynator.RCS1045.suppress_when_field_is_static", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor RemoveAccessibilityModifiers = new(key: "roslynator.RCS1018.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor RemoveCallToConfigureAwait = new(key: "roslynator.RCS1090.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor RemoveEmptyLineBetweenClosingBraceAndSwitchSection = new(key: "roslynator.RCS1036.remove_empty_line_between_closing_brace_and_switch_section", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor RemoveEmptyLineBetweenSingleLineAccessors = new(key: "roslynator.RCS0011.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor RemoveEmptyLineBetweenUsingDirectivesWithDifferentRootNamespace = new(key: "roslynator.RCS0015.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor RemoveNewLineBetweenClosingBraceAndWhileKeyword = new(key: "roslynator.RCS0051.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor RemoveParenthesesFromConditionOfConditionalExpressionWhenExpressionIsSingleToken = new(key: "roslynator.RCS1051.do_not_parenthesize_single_token", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor RemoveParenthesesWhenCreatingNewObject = new(key: "roslynator.RCS1050.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor SuppressUnityScriptMethods = new(key: "roslynator.RCS1213.suppress_unity_script_methods", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor UseComparisonInsteadPatternMatchingToCheckForNull = new(key: "roslynator.RCS1248.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor UseImplicitlyTypedArray = new(key: "roslynator.RCS1014.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor UseImplicitlyTypedArrayWhenTypeIsObvious = new(key: "roslynator.RCS1014.use_implicit_type_when_obvious", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); - public static readonly LegacyConfigOptionDescriptor UseStringEmptyInsteadOfEmptyStringLiteral = new(key: "roslynator.RCS1078.invert", defaultValue: null, defaultValuePlaceholder: "true|false", description: ""); } } \ No newline at end of file diff --git a/src/Formatting.Analyzers/CSharp/AnalyzerOptionIsObsoleteAnalyzer.cs b/src/Formatting.Analyzers/CSharp/AnalyzerOptionIsObsoleteAnalyzer.cs deleted file mode 100644 index d1f5573dd9..0000000000 --- a/src/Formatting.Analyzers/CSharp/AnalyzerOptionIsObsoleteAnalyzer.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Immutable; -using System.IO; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; - -namespace Roslynator.Formatting.CSharp; - -[DiagnosticAnalyzer(LanguageNames.CSharp)] -internal sealed class AnalyzerOptionIsObsoleteAnalyzer : AbstractAnalyzerOptionIsObsoleteAnalyzer -{ - private static ImmutableArray _supportedDiagnostics; - - public override ImmutableArray SupportedDiagnostics - { - get - { - if (_supportedDiagnostics.IsDefault) - Immutable.InterlockedInitialize(ref _supportedDiagnostics, CommonDiagnosticRules.AnalyzerOptionIsObsolete); - - return _supportedDiagnostics; - } - } - - public override void Initialize(AnalysisContext context) - { - context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); - - context.RegisterCompilationStartAction(compilationContext => - { - var flags = Flags.None; - - CompilationOptions compilationOptions = compilationContext.Compilation.Options; - - compilationContext.RegisterSyntaxTreeAction(context => - { - // files generated by source generator have relative path - if (!Path.IsPathRooted(context.Tree.FilePath)) - return; - - AnalyzerConfigOptions configOptions = context.GetConfigOptions(); - - Validate(ref context, compilationOptions, configOptions, Flags.AddOrRemoveNewLineBeforeWhileInDoStatement, ref flags, DiagnosticRules.AddOrRemoveNewLineBeforeWhileInDoStatement, ConfigOptions.NewLineBeforeWhileInDoStatement, LegacyConfigOptions.RemoveNewLineBetweenClosingBraceAndWhileKeyword, "false"); - Validate(ref context, compilationOptions, configOptions, Flags.BlankLineBetweenSingleLineAccessors, ref flags, DiagnosticRules.BlankLineBetweenSingleLineAccessors, ConfigOptions.BlankLineBetweenSingleLineAccessors, LegacyConfigOptions.RemoveEmptyLineBetweenSingleLineAccessors, "false"); - Validate(ref context, compilationOptions, configOptions, Flags.BlankLineBetweenUsingDirectives, ref flags, DiagnosticRules.BlankLineBetweenUsingDirectives, ConfigOptions.BlankLineBetweenUsingDirectives, LegacyConfigOptions.RemoveEmptyLineBetweenUsingDirectivesWithDifferentRootNamespace, ConfigOptionValues.BlankLineBetweenUsingDirectives_Never); - Validate(ref context, compilationOptions, configOptions, Flags.PlaceNewLineAfterOrBeforeArrowToken, ref flags, DiagnosticRules.PlaceNewLineAfterOrBeforeArrowToken, ConfigOptions.ArrowTokenNewLine, LegacyConfigOptions.AddNewLineAfterExpressionBodyArrowInsteadOfBeforeIt, "after"); - Validate(ref context, compilationOptions, configOptions, Flags.PlaceNewLineAfterOrBeforeConditionalOperator, ref flags, DiagnosticRules.PlaceNewLineAfterOrBeforeConditionalOperator, ConfigOptions.ConditionalOperatorNewLine, LegacyConfigOptions.AddNewLineAfterConditionalOperatorInsteadOfBeforeIt, "after"); - Validate(ref context, compilationOptions, configOptions, Flags.PlaceNewLineAfterOrBeforeBinaryOperator, ref flags, DiagnosticRules.PlaceNewLineAfterOrBeforeBinaryOperator, ConfigOptions.BinaryOperatorNewLine, LegacyConfigOptions.AddNewLineAfterBinaryOperatorInsteadOfBeforeIt, "after"); - Validate(ref context, compilationOptions, configOptions, Flags.PlaceNewLineAfterOrBeforeEqualsToken, ref flags, DiagnosticRules.PlaceNewLineAfterOrBeforeEqualsToken, ConfigOptions.EqualsTokenNewLine, LegacyConfigOptions.AddNewLineAfterEqualsSignInsteadOfBeforeIt, "after"); - }); - }); - } - - private static void Validate( - ref SyntaxTreeAnalysisContext context, - CompilationOptions compilationOptions, - AnalyzerConfigOptions configOptions, - Flags flag, - ref Flags flags, - DiagnosticDescriptor analyzer, - ConfigOptionDescriptor option, - LegacyConfigOptionDescriptor legacyOption, - string newValue) - { - if (!flags.HasFlag(flag) - && analyzer.IsEffective(context.Tree, compilationOptions, context.CancellationToken) - && TryReportObsoleteOption(context, configOptions, legacyOption, option, newValue)) - { - flags |= flag; - } - } - - [Flags] - private enum Flags - { - None, - AddOrRemoveNewLineBeforeWhileInDoStatement, - BlankLineBetweenSingleLineAccessors, - BlankLineBetweenUsingDirectives, - PlaceNewLineAfterOrBeforeArrowToken, - PlaceNewLineAfterOrBeforeBinaryOperator, - PlaceNewLineAfterOrBeforeConditionalOperator, - PlaceNewLineAfterOrBeforeEqualsToken, - } -} diff --git a/src/Tests/Analyzers.Tests/ROS002AnalyzerOptionIsObsoleteTests.cs b/src/Tests/Analyzers.Tests/ROS002AnalyzerOptionIsObsoleteTests.cs deleted file mode 100644 index 722dbfe99c..0000000000 --- a/src/Tests/Analyzers.Tests/ROS002AnalyzerOptionIsObsoleteTests.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Roslynator.Testing; -using Roslynator.Testing.CSharp; -using Xunit; - -namespace Roslynator.CSharp.Analysis.Tests; - -public class ROS0002AnalyzerOptionIsObsoleteTests : AbstractCSharpDiagnosticVerifier -{ - public override DiagnosticDescriptor Descriptor { get; } = CommonDiagnosticRules.AnalyzerOptionIsObsolete; - - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.RemoveBracesFromIfElse)] - public async Task Test() - { - await VerifyDiagnosticAsync(@" -class C -{ - void M() - { - } -} -", options: Options.AddConfigOption("dotnet_diagnostic.RCS1207.severity", "suggestion") - .AddConfigOption(LegacyConfigOptions.ConvertMethodGroupToAnonymousFunction.Key, "true")); - } - - [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.RemoveBracesFromIfElse)] - public async Task Test2() - { - await VerifyDiagnosticAsync(@" -class C -{ - void M() - { - } -} -", options: Options.EnableDiagnostic(DiagnosticRules.UseAnonymousFunctionOrMethodGroup) - .AddConfigOption(LegacyConfigOptions.ConvertMethodGroupToAnonymousFunction.Key, "true")); - } -} diff --git a/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs b/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs index a8f3859aab..03ca75baa0 100644 --- a/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs +++ b/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs @@ -77,36 +77,6 @@ public static CompilationUnitSyntax GenerateConfigOptions(IEnumerable analyzers) - { - return CompilationUnit( - UsingDirectives(), - NamespaceDeclaration( - "Roslynator", - ClassDeclaration( - Modifiers.Public_Static_Partial(), - "LegacyConfigOptions", - analyzers - .SelectMany(f => f.LegacyOptions) - .Where(f => f.Status != AnalyzerStatus.Disabled) - .OrderBy(f => f.Identifier, StringComparer.InvariantCulture) - .Select(f => - { - return FieldDeclaration( - Modifiers.Public_Static_ReadOnly(), - IdentifierName("LegacyConfigOptionDescriptor"), - f.Identifier, - ImplicitObjectCreationExpression( - ArgumentList( - Argument(NameColon("key"), StringLiteralExpression($"roslynator.{f.ParentId}.{f.OptionKey}")), - Argument(NameColon("defaultValue"), NullLiteralExpression()), - Argument(NameColon("defaultValuePlaceholder"), StringLiteralExpression("true|false")), - Argument(NameColon("description"), StringLiteralExpression(""))), - default(InitializerExpressionSyntax))); - }) - .ToSyntaxList()))); - } - public static CompilationUnitSyntax GenerateConfigOptionKeys(IEnumerable options) { CompilationUnitSyntax compilationUnit = CompilationUnit( diff --git a/src/Tools/CodeGeneration/Markdown/MarkdownGenerator.cs b/src/Tools/CodeGeneration/Markdown/MarkdownGenerator.cs index 499ba4a85e..d2a5188905 100644 --- a/src/Tools/CodeGeneration/Markdown/MarkdownGenerator.cs +++ b/src/Tools/CodeGeneration/Markdown/MarkdownGenerator.cs @@ -159,17 +159,12 @@ public static string CreateAnalyzerMarkdown(AnalyzerMetadata analyzer, Immutable static IEnumerable CreateSamples(AnalyzerMetadata analyzer) { IReadOnlyList samples = analyzer.Samples; - LegacyAnalyzerOptionKind kind = analyzer.Kind; if (samples.Count > 0) { yield return Heading2("Examples"); - string beforeHeading = (kind == LegacyAnalyzerOptionKind.Disable) - ? "code" - : "diagnostic"; - - foreach (MElement item in MarkdownGenerator.CreateSamples(samples, beforeHeading, "fix")) + foreach (MElement item in MarkdownGenerator.CreateSamples(samples, "diagnostic", "fix")) yield return item; } } diff --git a/src/Tools/CodeGenerator/Program.cs b/src/Tools/CodeGenerator/Program.cs index 08f479e8df..55ce6a7491 100644 --- a/src/Tools/CodeGenerator/Program.cs +++ b/src/Tools/CodeGenerator/Program.cs @@ -82,10 +82,6 @@ private static void Main(string[] args) Roslynator.CodeGeneration.CSharp.CodeGenerator.GenerateConfigOptions(options, metadata.Analyzers), normalizeWhitespace: false); - WriteCompilationUnit( - @"Common\LegacyConfigOptions.Generated.cs", - Roslynator.CodeGeneration.CSharp.CodeGenerator.GenerateLegacyConfigOptions(metadata.Analyzers)); - WriteCompilationUnit( @"Common\ConfigOptionKeys.Generated.cs", Roslynator.CodeGeneration.CSharp.CodeGenerator.GenerateConfigOptionKeys(options), diff --git a/src/Tools/Metadata/AnalyzerMetadata.cs b/src/Tools/Metadata/AnalyzerMetadata.cs index 11cc8b519c..d6ff925117 100644 --- a/src/Tools/Metadata/AnalyzerMetadata.cs +++ b/src/Tools/Metadata/AnalyzerMetadata.cs @@ -42,12 +42,6 @@ public class AnalyzerMetadata public List Links { get; } = []; - public List LegacyOptions { get; } = []; - - public List LegacyOptionAnalyzers { get; } = []; - - public LegacyAnalyzerOptionKind Kind { get; init; } - public AnalyzerMetadata Parent { get; init; } public AnalyzerStatus Status { get; init; } diff --git a/src/Tools/Metadata/LegacyAnalyzerOptionKind.cs b/src/Tools/Metadata/LegacyAnalyzerOptionKind.cs deleted file mode 100644 index 9a7c857a30..0000000000 --- a/src/Tools/Metadata/LegacyAnalyzerOptionKind.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Roslynator.Metadata; - -public enum LegacyAnalyzerOptionKind -{ - None, - Enable, - Disable, - Change, - Invert, -} diff --git a/src/Tools/Metadata/LegacyAnalyzerOptionMetadata.cs b/src/Tools/Metadata/LegacyAnalyzerOptionMetadata.cs deleted file mode 100644 index e903ba3730..0000000000 --- a/src/Tools/Metadata/LegacyAnalyzerOptionMetadata.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Roslynator.Metadata; - -public class LegacyAnalyzerOptionMetadata -{ - public AnalyzerMetadata CreateAnalyzerMetadata(AnalyzerMetadata parent) - { - var analyzer = new AnalyzerMetadata() - { - Id = (Id is not null) ? parent.Id + Id : null, - Identifier = Identifier, - Title = Title, - MessageFormat = Title, - Category = "AnalyzerOption", - DefaultSeverity = parent.DefaultSeverity, - IsEnabledByDefault = IsEnabledByDefault, - Status = (parent.Status != AnalyzerStatus.Enabled) ? parent.Status : Status, - SupportsFadeOut = SupportsFadeOut, - SupportsFadeOutAnalyzer = false, - MinLanguageVersion = MinLanguageVersion ?? parent.MinLanguageVersion, - Summary = Summary, - Kind = Kind, - Parent = parent, - }; - - analyzer.Samples.AddRange(Samples); - analyzer.Tags.AddRange(parent.Tags.Concat(Tags)); - - return analyzer; - } - - public string Identifier { get; init; } - - public string Id { get; init; } - - public string ParentId { get; init; } - - public string OptionKey { get; init; } - - public string OptionValue { get; init; } - - public string NewOptionKey { get; init; } - - public LegacyAnalyzerOptionKind Kind { get; init; } - - public string Title { get; init; } - - public bool IsEnabledByDefault { get; init; } - - public bool SupportsFadeOut { get; init; } - - public string MinLanguageVersion { get; init; } - - public string Summary { get; init; } - - public List Samples { get; } = []; - - [Obsolete("This property is obsolete", error: true)] - public bool IsObsolete { get; init; } - - public AnalyzerStatus Status { get; init; } - - public List Tags { get; } = []; -} diff --git a/src/Tools/Metadata/MetadataFile.cs b/src/Tools/Metadata/MetadataFile.cs index aa17991b39..444b35aa3b 100644 --- a/src/Tools/Metadata/MetadataFile.cs +++ b/src/Tools/Metadata/MetadataFile.cs @@ -42,7 +42,6 @@ public static IEnumerable ReadAnalyzers(string filePath) string remarks = element.Element("Remarks")?.Value.NormalizeNewLine(); IEnumerable samples = LoadSamples(element)?.Select(f => f with { Before = f.Before.Replace("[|Id|]", id) }); IEnumerable links = LoadLinks(element); - IEnumerable options = LoadOptions(element, id); IEnumerable configOptions = LoadConfigOptions(element); string[] tags = (element.Element("Tags")?.Value ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); AnalyzerStatus status = ParseStatus(element); @@ -73,8 +72,6 @@ public static IEnumerable ReadAnalyzers(string filePath) analyzer.ConfigOptions.AddRange(configOptions ?? Enumerable.Empty()); analyzer.Samples.AddRange(samples ?? Enumerable.Empty()); analyzer.Links.AddRange(links ?? Enumerable.Empty()); - analyzer.LegacyOptions.AddRange(options ?? Enumerable.Empty()); - analyzer.LegacyOptionAnalyzers.AddRange(analyzer.LegacyOptions.Select(f => f.CreateAnalyzerMetadata(analyzer))); yield return analyzer; } @@ -161,14 +158,6 @@ private static IEnumerable LoadLinks(XElement element) .Select(f => new LinkMetadata() { Url = f.Element("Url").Value, Text = f.Element("Text")?.Value, Title = f.Element("Title")?.Value }); } - private static IEnumerable LoadOptions(XElement element, string parentId) - { - return element - .Element("Options")? - .Elements("Option") - .Select(f => LoadOption(f, parentId)); - } - private static IEnumerable LoadConfigOptions(XElement element) { return element @@ -177,54 +166,6 @@ private static IEnumerable LoadConfigOptions(XElement elem .Select(f => new AnalyzerConfigOption("roslynator_" + f.Attribute("Key").Value, bool.Parse(f.Attribute("IsRequired")?.Value ?? bool.FalseString))); } - private static LegacyAnalyzerOptionMetadata LoadOption(XElement element, string parentId) - { - string title = element.Element("Title").Value; - - string identifier = element.Attribute("Identifier").Value; - string id = element.Element("Id")?.Value; - string optionKey = element.Element("OptionKey").Value; - string optionValue = element.Element("OptionValue")?.Value; - var kind = (LegacyAnalyzerOptionKind)Enum.Parse(typeof(LegacyAnalyzerOptionKind), element.Element("Kind").Value); - bool isEnabledByDefault = element.ElementValueAsBooleanOrDefault("IsEnabledByDefault"); - bool supportsFadeOut = element.ElementValueAsBooleanOrDefault("SupportsFadeOut"); - string minLanguageVersion = element.Element("MinLanguageVersion")?.Value; - string summary = element.Element("Summary")?.Value.NormalizeNewLine(); - IEnumerable samples = LoadSamples(element)?.Select(f => f with { Before = f.Before.Replace("[|Id|]", parentId) }); - bool isObsolete = element.AttributeValueAsBooleanOrDefault("IsObsolete"); - string[] tags = (element.Element("Tags")?.Value ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - AnalyzerStatus status = ParseStatus(element); - - string newOptionKey = element.Element("NewOptionKey")?.Value; - - if (newOptionKey?.StartsWith("roslynator_") == false) - newOptionKey = "roslynator_" + newOptionKey; - - var analyzerOption = new LegacyAnalyzerOptionMetadata() - { - Identifier = identifier, - Id = id, - ParentId = parentId, - OptionKey = optionKey, - OptionValue = optionValue, - NewOptionKey = newOptionKey, - Kind = kind, - Title = title, - IsEnabledByDefault = isEnabledByDefault, - SupportsFadeOut = supportsFadeOut, - MinLanguageVersion = minLanguageVersion, - Summary = summary, - Status = status, - }; - - if (samples is not null) - analyzerOption.Samples.AddRange(samples); - - analyzerOption.Tags.AddRange(tags); - - return analyzerOption; - } - public static IEnumerable ReadCodeFixes(string filePath) { XDocument doc = XDocument.Load(filePath); diff --git a/src/Tools/MetadataGenerator/Program.cs b/src/Tools/MetadataGenerator/Program.cs index 224da448e9..dff29c8a98 100644 --- a/src/Tools/MetadataGenerator/Program.cs +++ b/src/Tools/MetadataGenerator/Program.cs @@ -55,7 +55,6 @@ void UpdateChangeLog() string s = File.ReadAllText(path, _utf8NoBom); ImmutableDictionary dic = metadata.Analyzers - .Concat(metadata.Analyzers.SelectMany(f => f.LegacyOptionAnalyzers)) .Where(f => f.Id is not null) .ToImmutableDictionary(f => f.Id, f => f); @@ -101,9 +100,7 @@ private static void GenerateAnalyzersMarkdown(RoslynatorMetadata metadata, strin void DeleteInvalidAnalyzerMarkdowns() { - IEnumerable allIds = metadata.Analyzers - .Concat(metadata.Analyzers.SelectMany(f => f.LegacyOptionAnalyzers)) - .Select(f => f.Id); + IEnumerable allIds = metadata.Analyzers.Select(f => f.Id); foreach (string id in Directory.GetFiles(analyzersDirPath, "*.*", SearchOption.TopDirectoryOnly) .Select(f => Path.GetFileNameWithoutExtension(f))