From 7c3ceb959a8cf3ab83243de868f67aafb2b8f4ad Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 30 Nov 2023 14:34:57 +0100 Subject: [PATCH 1/4] Remove legacy config options --- src/Analyzers.xml | 483 ---------------------------------------------- 1 file changed, 483 deletions(-) diff --git a/src/Analyzers.xml b/src/Analyzers.xml index f3b61637dd..92c1c1d95c 100644 --- a/src/Analyzers.xml +++ b/src/Analyzers.xml @@ -328,30 +328,6 @@ enum Bar - - - RCS0012 @@ -443,33 +419,6 @@ namespace N - - - RCS0016 @@ -696,29 +645,6 @@ namespace N - - - RCS0028 @@ -740,25 +666,6 @@ namespace N - - - RCS0029 @@ -830,23 +737,6 @@ namespace N - - - RCS0033 @@ -1229,28 +1119,6 @@ while (x);]]> - - - RCS0052 @@ -1270,23 +1138,6 @@ while (x);]]> - - - RCS0053 @@ -1792,35 +1643,6 @@ foreach (var item in items) - - - - RCS1015 @@ -1871,73 +1693,6 @@ foreach (var item in items) RCS1017 @@ -1992,32 +1747,6 @@ foreach (var item in items) - - - RCS1019 @@ -2396,42 +2125,6 @@ if (f) - - - RCS1037 @@ -2602,19 +2295,6 @@ catch (Exception ex) - - - RCS1046 @@ -2722,21 +2402,6 @@ if (!f) - - - RCS1051 @@ -2754,22 +2419,6 @@ if (!f) - - - RCS1052 @@ -3472,21 +3121,6 @@ object x = queue.Peek();]]> - - - RCS1079 @@ -3671,28 +3305,6 @@ public string Foo - - - RCS1091 @@ -3784,27 +3396,6 @@ namespace Foo - - - RCS1097 @@ -3997,23 +3588,6 @@ else - - - RCS1105 @@ -5933,21 +5507,6 @@ int i = (x != null) ? x.Value.GetHashCode() : 0;]]> - - - RCS1208 @@ -6122,15 +5681,6 @@ x = "";]]> RCS1214 @@ -7175,20 +6725,6 @@ public class C - - - RCS1247 @@ -7256,25 +6792,6 @@ void M() - - - RCS1249 From 944f0fe3884947f12259774ff366406282f56922 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 30 Nov 2023 14:35:17 +0100 Subject: [PATCH 2/4] update --- .../AnalyzerOptionIsObsoleteAnalyzer.cs | 105 ------------------ .../CSharp/DiagnosticRules.Generated.cs | 4 +- src/Common/CSharp/CodeStyle/BodyStyle.cs | 10 +- .../CSharp/Extensions/CodeStyleExtensions.cs | 57 ---------- src/Common/LegacyConfigOptions.Generated.cs | 23 ---- .../AnalyzerOptionIsObsoleteAnalyzer.cs | 87 --------------- .../ROS002AnalyzerOptionIsObsoleteTests.cs | 42 ------- 7 files changed, 4 insertions(+), 324 deletions(-) delete mode 100644 src/Analyzers/CSharp/Analysis/AnalyzerOptionIsObsoleteAnalyzer.cs delete mode 100644 src/Formatting.Analyzers/CSharp/AnalyzerOptionIsObsoleteAnalyzer.cs delete mode 100644 src/Tests/Analyzers.Tests/ROS002AnalyzerOptionIsObsoleteTests.cs 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/Analyzers/CSharp/DiagnosticRules.Generated.cs b/src/Analyzers/CSharp/DiagnosticRules.Generated.cs index 6ec8978546..1f89365233 100644 --- a/src/Analyzers/CSharp/DiagnosticRules.Generated.cs +++ b/src/Analyzers/CSharp/DiagnosticRules.Generated.cs @@ -2594,8 +2594,8 @@ public static partial class DiagnosticRules /// RCS1263 public static readonly DiagnosticDescriptor InvalidReferenceInDocumentationComment = DiagnosticDescriptorFactory.Create( id: DiagnosticIdentifiers.InvalidReferenceInDocumentationComment, - title: "Invalid reference in a documentation comment.", - messageFormat: "{0} '{1}' could not be found.", + title: "Invalid reference in a documentation comment", + messageFormat: "{0} '{1}' could not be found", category: DiagnosticCategories.Roslynator, defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true, diff --git a/src/Common/CSharp/CodeStyle/BodyStyle.cs b/src/Common/CSharp/CodeStyle/BodyStyle.cs index 41e66d61b3..dcc1118e68 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; } diff --git a/src/Common/CSharp/Extensions/CodeStyleExtensions.cs b/src/Common/CSharp/Extensions/CodeStyleExtensions.cs index d16661b50b..3af4a5d5f3 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; } @@ -465,12 +420,6 @@ public static ArrayCreationTypeStyle GetArrayCreationTypeStyle(this SyntaxNodeAn } } - if (context.IsEnabled(LegacyConfigOptions.UseImplicitlyTypedArrayWhenTypeIsObvious)) - return ArrayCreationTypeStyle.ImplicitWhenTypeIsObvious; - - if (context.IsEnabled(LegacyConfigOptions.UseImplicitlyTypedArray)) - return ArrayCreationTypeStyle.Implicit; - return ArrayCreationTypeStyle.None; } @@ -549,9 +498,6 @@ public static BodyStyle GetBodyStyle(this SyntaxNodeAnalysisContext context) return value; } - if (context.TryGetOptionAsBool(LegacyConfigOptions.RemoveEmptyLineBetweenClosingBraceAndSwitchSection, out value)) - return !value; - return null; } @@ -575,9 +521,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")); - } -} From 3a9dc1ba6178a9ca0d46c4661b32ec87d5700278 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 30 Nov 2023 18:03:05 +0100 Subject: [PATCH 3/4] update --- src/Common/CSharp/CodeStyle/BodyStyle.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Common/CSharp/CodeStyle/BodyStyle.cs b/src/Common/CSharp/CodeStyle/BodyStyle.cs index dcc1118e68..bb56d193bc 100644 --- a/src/Common/CSharp/CodeStyle/BodyStyle.cs +++ b/src/Common/CSharp/CodeStyle/BodyStyle.cs @@ -61,7 +61,7 @@ public static BodyStyle Create(SyntaxNodeAnalysisContext context) return new BodyStyle(option, useBlockBodyWhenDeclarationIsMultiLine, useBlockBodyWhenExpressionIsMultiline); } - internal enum BodyStyleOption + private enum BodyStyleOption { None, Block, From f684e7598f622219543924cb168527fcfee59bd3 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Tue, 5 Dec 2023 14:52:27 +0100 Subject: [PATCH 4/4] update --- .../CodeGeneration/CSharp/CodeGenerator.cs | 30 -------- .../Markdown/MarkdownGenerator.cs | 7 +- src/Tools/CodeGenerator/Program.cs | 4 -- src/Tools/Metadata/AnalyzerMetadata.cs | 6 -- .../Metadata/LegacyAnalyzerOptionKind.cs | 12 ---- .../Metadata/LegacyAnalyzerOptionMetadata.cs | 69 ------------------- src/Tools/Metadata/MetadataFile.cs | 59 ---------------- src/Tools/MetadataGenerator/Program.cs | 5 +- 8 files changed, 2 insertions(+), 190 deletions(-) delete mode 100644 src/Tools/Metadata/LegacyAnalyzerOptionKind.cs delete mode 100644 src/Tools/Metadata/LegacyAnalyzerOptionMetadata.cs diff --git a/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs b/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs index c0ba0723ff..b2b0e1d266 100644 --- a/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs +++ b/src/Tools/CodeGeneration/CSharp/CodeGenerator.cs @@ -76,36 +76,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) - .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 315d2f5a8f..8a75f65cfc 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 db4002e844..7a3d7177fb 100644 --- a/src/Tools/CodeGenerator/Program.cs +++ b/src/Tools/CodeGenerator/Program.cs @@ -86,10 +86,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 8af32e6d7a..d72d992468 100644 --- a/src/Tools/Metadata/AnalyzerMetadata.cs +++ b/src/Tools/Metadata/AnalyzerMetadata.cs @@ -42,12 +42,6 @@ public class AnalyzerMetadata public List Links { get; } = new(); - public List LegacyOptions { get; } = new(); - - public List LegacyOptionAnalyzers { get; } = new(); - - 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 c383c27e34..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; } = new(); - - [Obsolete("This property is obsolete", error: true)] - public bool IsObsolete { get; init; } - - public AnalyzerStatus Status { get; init; } - - public List Tags { get; } = new(); -} diff --git a/src/Tools/Metadata/MetadataFile.cs b/src/Tools/Metadata/MetadataFile.cs index c2b2a13e8e..97210a96be 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 f81f5f5ccf..cfd56bddc5 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))