Skip to content

Conversation

CyrusNajmabadi
Copy link
Member

This has been annoying me that this Roslyn-Analyzers fixer doesn't work the moment you use primary constructors.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner July 7, 2025 19:41
@@ -25,7 +26,7 @@ namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers
[method: Obsolete("This exported object must be obtained through the MEF export provider.", error: true)]
public sealed class FixerWithFixAllFix() : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } = ImmutableArray.Create(DiagnosticIds.OverrideGetFixAllProviderRuleId);
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } = [DiagnosticIds.OverrideGetFixAllProviderRuleId];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just cleanup in this file.


namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers
{
public abstract class ApplyDiagnosticAnalyzerAttributeFix : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } = ImmutableArray.Create(DiagnosticIds.MissingDiagnosticAnalyzerAttributeRuleId);
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } = [DiagnosticIds.MissingDiagnosticAnalyzerAttributeRuleId];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just cleanup in this file.

using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers
{
public abstract class CompareSymbolsCorrectlyFix : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds { get; } =
ImmutableArray.Create(DiagnosticIds.CompareSymbolsCorrectlyRuleId);
[DiagnosticIds.CompareSymbolsCorrectlyRuleId];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just cleanup in this file.

using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers
{
public abstract class ConfigureGeneratedCodeAnalysisFix : CodeFixProvider
{
public override ImmutableArray<string> FixableDiagnosticIds { get; } = ImmutableArray.Create(ConfigureGeneratedCodeAnalysisAnalyzer.Rule.Id);
public override ImmutableArray<string> FixableDiagnosticIds { get; } = [ConfigureGeneratedCodeAnalysisAnalyzer.Rule.Id];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just cleanup in this file.

DiagnosticIds.DefineDiagnosticTitleCorrectlyRuleId,
DiagnosticIds.DefineDiagnosticMessageCorrectlyRuleId,
DiagnosticIds.DefineDiagnosticDescriptionCorrectlyRuleId,
];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just cleanup in this file.

using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers
{
public abstract class EnableConcurrentExecutionFix : CodeFixProvider
{
public override ImmutableArray<string> FixableDiagnosticIds { get; } = ImmutableArray.Create(EnableConcurrentExecutionAnalyzer.Rule.Id);
public override ImmutableArray<string> FixableDiagnosticIds { get; } = [EnableConcurrentExecutionAnalyzer.Rule.Id];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just cleanup in this file.

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers;
using Microsoft.CodeAnalysis.Shared.Extensions;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving off of duplicative extension to roslyn ones.

GenerateErrorArgument(generator, allowNamedArgument: document.Project.Language == LanguageNames.CSharp),
]);

obsoleteAttributeList = isPrimaryConstructorTypeDeclaration ? this.AddMethodTarget(obsoleteAttributeList) : obsoleteAttributeList;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the updated logic.

{
var source = $@"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched to raw strings and file scoped namespace.

[WindowsOnlyTheory]
[InlineData("System.Composition")]
[InlineData("System.ComponentModel.Composition")]
public async Task NotMarkedObsolete_PrimaryConstructor_CSharpAsync(string mefNamespace)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test for thsi scenario.

@@ -1,45 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicates of roslyn extensions. deleted.

@CyrusNajmabadi
Copy link
Member Author

@JoeRobich ptal.

@CyrusNajmabadi CyrusNajmabadi merged commit 011ffa7 into dotnet:main Jul 8, 2025
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the useObsoletePC branch July 8, 2025 05:01
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 8, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants