Skip to content

Commit

Permalink
Merge pull request dotnet#57883 from sharwell/code-cleanup
Browse files Browse the repository at this point in the history
Merge FixIdDefinition with the same name
  • Loading branch information
sharwell authored Nov 22, 2021
2 parents c519459 + 92ef829 commit d1a34b0
Show file tree
Hide file tree
Showing 18 changed files with 265 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@ internal partial class CSharpCodeCleanUpFixer
[LocalizedName(typeof(CSharpFeaturesResources), nameof(CSharpFeaturesResources.Apply_implicit_explicit_type_preferences))]
public static readonly FixIdDefinition? UseExplicitTypeDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.AddQualificationDiagnosticId)]
[Name(IDEDiagnosticIds.AddQualificationDiagnosticId)]
[Order(After = IDEDiagnosticIds.UseObjectInitializerDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(CSharpFeaturesResources), nameof(CSharpFeaturesResources.Apply_this_qualification_preferences))]
public static readonly FixIdDefinition? AddQualificationDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.RemoveQualificationDiagnosticId)]
[Name(IDEDiagnosticIds.RemoveQualificationDiagnosticId)]
[Order(After = IDEDiagnosticIds.UseObjectInitializerDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(CSharpFeaturesResources), nameof(CSharpFeaturesResources.Apply_this_qualification_preferences))]
public static readonly FixIdDefinition? RemoveQualificationDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.PreferBuiltInOrFrameworkTypeDiagnosticId)]
[Name(IDEDiagnosticIds.PreferBuiltInOrFrameworkTypeDiagnosticId)]
Expand All @@ -68,42 +50,6 @@ internal partial class CSharpCodeCleanUpFixer
[LocalizedName(typeof(CSharpFeaturesResources), nameof(CSharpFeaturesResources.Add_remove_braces_for_single_line_control_statements))]
public static readonly FixIdDefinition? AddBracesDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.AddAccessibilityModifiersDiagnosticId)]
[Name(IDEDiagnosticIds.AddAccessibilityModifiersDiagnosticId)]
[Order(After = IDEDiagnosticIds.AddBracesDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(AnalyzersResources), nameof(AnalyzersResources.Add_accessibility_modifiers))]
public static readonly FixIdDefinition? AddAccessibilityModifiersDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.OrderModifiersDiagnosticId)]
[Name(IDEDiagnosticIds.OrderModifiersDiagnosticId)]
[Order(After = IDEDiagnosticIds.AddAccessibilityModifiersDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(CSharpFeaturesResources), nameof(CSharpFeaturesResources.Sort_accessibility_modifiers))]
public static readonly FixIdDefinition? OrderModifiersDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.MakeFieldReadonlyDiagnosticId)]
[Name(IDEDiagnosticIds.MakeFieldReadonlyDiagnosticId)]
[Order(After = IDEDiagnosticIds.AddQualificationDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(CSharpFeaturesResources), nameof(CSharpFeaturesResources.Make_private_field_readonly_when_possible))]
public static readonly FixIdDefinition? MakeFieldReadonlyDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.RemoveUnnecessaryCastDiagnosticId)]
[Name(IDEDiagnosticIds.RemoveUnnecessaryCastDiagnosticId)]
[Order(After = IDEDiagnosticIds.MakeFieldReadonlyDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(FeaturesResources), nameof(FeaturesResources.Remove_unnecessary_casts))]
public static readonly FixIdDefinition? RemoveUnnecessaryCastDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.UseExpressionBodyForConstructorsDiagnosticId)]
[Name(IDEDiagnosticIds.UseExpressionBodyForConstructorsDiagnosticId)]
Expand Down Expand Up @@ -193,62 +139,5 @@ internal partial class CSharpCodeCleanUpFixer
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(FeaturesResources), nameof(FeaturesResources.Remove_unused_variables))]
public static readonly FixIdDefinition? CS0219;

[Export]
[FixId(IDEDiagnosticIds.UseObjectInitializerDiagnosticId)]
[Name(IDEDiagnosticIds.UseObjectInitializerDiagnosticId)]
[Order(After = IDEDiagnosticIds.PreferBuiltInOrFrameworkTypeDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(FeaturesResources), nameof(FeaturesResources.Apply_object_collection_initialization_preferences))]
public static readonly FixIdDefinition? UseObjectInitializerDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.UseCollectionInitializerDiagnosticId)]
[Name(IDEDiagnosticIds.UseCollectionInitializerDiagnosticId)]
[Order(After = IDEDiagnosticIds.PreferBuiltInOrFrameworkTypeDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(FeaturesResources), nameof(FeaturesResources.Apply_object_collection_initialization_preferences))]
public static readonly FixIdDefinition? UseCollectionInitializerDiagnosticId;

[Export]
[FixId(FormatDocumentFixId)]
[Name(FormatDocumentFixId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[ExportMetadata("EnableByDefault", true)]
[LocalizedName(typeof(ServicesVSResources), nameof(ServicesVSResources.Format_document))]
public static readonly FixIdDefinition? FormatDocument;

[Export]
[FixId(RemoveUnusedImportsFixId)]
[Name(RemoveUnusedImportsFixId)]
[Order(After = FormatDocumentFixId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[ExportMetadata("EnableByDefault", true)]
[LocalizedName(typeof(CSharpVSResources), nameof(CSharpVSResources.Remove_unnecessary_usings))]
public static readonly FixIdDefinition? RemoveUnusedImports;

[Export]
[FixId(SortImportsFixId)]
[Name(SortImportsFixId)]
[Order(After = RemoveUnusedImportsFixId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[ExportMetadata("EnableByDefault", true)]
[LocalizedName(typeof(CSharpVSResources), nameof(CSharpVSResources.Sort_usings))]
public static readonly FixIdDefinition? SortImports;

[Export]
[FixId(IDEDiagnosticIds.FileHeaderMismatch)]
[Name(IDEDiagnosticIds.FileHeaderMismatch)]
[Order(After = SortImportsFixId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[ExportMetadata("EnableByDefault", true)]
[LocalizedName(typeof(FeaturesResources), nameof(FeaturesResources.Apply_file_header_preferences))]
public static readonly FixIdDefinition? FileHeaderMismatch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.CodeCleanup
/// </summary>
internal abstract class AbstractCodeCleanUpFixer : ICodeCleanUpFixer
{
protected const string FormatDocumentFixId = nameof(FormatDocumentFixId);
protected const string RemoveUnusedImportsFixId = nameof(RemoveUnusedImportsFixId);
protected const string SortImportsFixId = nameof(SortImportsFixId);
protected internal const string FormatDocumentFixId = nameof(FormatDocumentFixId);
protected internal const string RemoveUnusedImportsFixId = nameof(RemoveUnusedImportsFixId);
protected internal const string SortImportsFixId = nameof(SortImportsFixId);

private readonly IThreadingContext _threadingContext;
private readonly VisualStudioWorkspaceImpl _workspace;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.VisualStudio.Language.CodeCleanUp;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.CodeCleanup
{
internal sealed class CommonCodeCleanUpFixerDiagnosticIds
{
[Export]
[FixId(IDEDiagnosticIds.AddQualificationDiagnosticId)]
[Name(IDEDiagnosticIds.AddQualificationDiagnosticId)]
[Order(After = IDEDiagnosticIds.UseObjectInitializerDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(AnalyzersResources), nameof(AnalyzersResources.Add_this_or_Me_qualification))]
public static readonly FixIdDefinition? AddQualificationDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.RemoveQualificationDiagnosticId)]
[Name(IDEDiagnosticIds.RemoveQualificationDiagnosticId)]
[Order(After = IDEDiagnosticIds.UseObjectInitializerDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(AnalyzersResources), nameof(AnalyzersResources.Add_this_or_Me_qualification))]
public static readonly FixIdDefinition? RemoveQualificationDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.AddAccessibilityModifiersDiagnosticId)]
[Name(IDEDiagnosticIds.AddAccessibilityModifiersDiagnosticId)]
[Order(After = IDEDiagnosticIds.AddBracesDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(AnalyzersResources), nameof(AnalyzersResources.Add_accessibility_modifiers))]
public static readonly FixIdDefinition? AddAccessibilityModifiersDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.OrderModifiersDiagnosticId)]
[Name(IDEDiagnosticIds.OrderModifiersDiagnosticId)]
[Order(After = IDEDiagnosticIds.AddAccessibilityModifiersDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(AnalyzersResources), nameof(AnalyzersResources.Order_modifiers))]
public static readonly FixIdDefinition? OrderModifiersDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.MakeFieldReadonlyDiagnosticId)]
[Name(IDEDiagnosticIds.MakeFieldReadonlyDiagnosticId)]
[Order(After = IDEDiagnosticIds.AddQualificationDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(AnalyzersResources), nameof(AnalyzersResources.Make_field_readonly))]
public static readonly FixIdDefinition? MakeFieldReadonlyDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.RemoveUnnecessaryCastDiagnosticId)]
[Name(IDEDiagnosticIds.RemoveUnnecessaryCastDiagnosticId)]
[Order(After = IDEDiagnosticIds.MakeFieldReadonlyDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(FeaturesResources), nameof(FeaturesResources.Remove_unnecessary_casts))]
public static readonly FixIdDefinition? RemoveUnnecessaryCastDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.UseObjectInitializerDiagnosticId)]
[Name(IDEDiagnosticIds.UseObjectInitializerDiagnosticId)]
[Order(After = IDEDiagnosticIds.PreferBuiltInOrFrameworkTypeDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(FeaturesResources), nameof(FeaturesResources.Apply_object_collection_initialization_preferences))]
public static readonly FixIdDefinition? UseObjectInitializerDiagnosticId;

[Export]
[FixId(IDEDiagnosticIds.UseCollectionInitializerDiagnosticId)]
[Name(IDEDiagnosticIds.UseCollectionInitializerDiagnosticId)]
[Order(After = IDEDiagnosticIds.PreferBuiltInOrFrameworkTypeDiagnosticId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[LocalizedName(typeof(FeaturesResources), nameof(FeaturesResources.Apply_object_collection_initialization_preferences))]
public static readonly FixIdDefinition? UseCollectionInitializerDiagnosticId;

[Export]
[FixId(AbstractCodeCleanUpFixer.FormatDocumentFixId)]
[Name(AbstractCodeCleanUpFixer.FormatDocumentFixId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[ExportMetadata("EnableByDefault", true)]
[LocalizedName(typeof(ServicesVSResources), nameof(ServicesVSResources.Format_document))]
public static readonly FixIdDefinition? FormatDocument;

[Export]
[FixId(AbstractCodeCleanUpFixer.RemoveUnusedImportsFixId)]
[Name(AbstractCodeCleanUpFixer.RemoveUnusedImportsFixId)]
[Order(After = AbstractCodeCleanUpFixer.FormatDocumentFixId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[ExportMetadata("EnableByDefault", true)]
[LocalizedName(typeof(ServicesVSResources), nameof(ServicesVSResources.Remove_unnecessary_usings))]
public static readonly FixIdDefinition? RemoveUnusedImports;

[Export]
[FixId(AbstractCodeCleanUpFixer.SortImportsFixId)]
[Name(AbstractCodeCleanUpFixer.SortImportsFixId)]
[Order(After = AbstractCodeCleanUpFixer.RemoveUnusedImportsFixId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[ExportMetadata("EnableByDefault", true)]
[LocalizedName(typeof(ServicesVSResources), nameof(ServicesVSResources.Sort_usings))]
public static readonly FixIdDefinition? SortImports;

[Export]
[FixId(IDEDiagnosticIds.FileHeaderMismatch)]
[Name(IDEDiagnosticIds.FileHeaderMismatch)]
[Order(After = AbstractCodeCleanUpFixer.SortImportsFixId)]
[ConfigurationKey("unused")]
[HelpLink("https://www.microsoft.com")]
[ExportMetadata("EnableByDefault", true)]
[LocalizedName(typeof(FeaturesResources), nameof(FeaturesResources.Apply_file_header_preferences))]
public static readonly FixIdDefinition? FileHeaderMismatch;
}
}
6 changes: 6 additions & 0 deletions src/VisualStudio/Core/Def/ServicesVSResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1887,4 +1887,10 @@ Additional information: {1}</value>
<value>Stack Trace {0}</value>
<comment>Header for numbered stack trace view tabs</comment>
</data>
<data name="Remove_unnecessary_usings" xml:space="preserve">
<value>Remove unnecessary usings</value>
</data>
<data name="Sort_usings" xml:space="preserve">
<value>Sort usings</value>
</data>
</root>
10 changes: 10 additions & 0 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/VisualStudio/Core/Def/xlf/ServicesVSResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d1a34b0

Please sign in to comment.