Skip to content

Commit c6eedee

Browse files
committed
Avoid passing properties to async void [RelayCommand] fixer
1 parent ce23265 commit c6eedee

File tree

2 files changed

+1
-15
lines changed

2 files changed

+1
-15
lines changed

src/CommunityToolkit.Mvvm.CodeFixers/AsyncVoidReturningRelayCommandMethodCodeFixer.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Composition;
77
using System.Threading;
88
using System.Threading.Tasks;
9-
using CommunityToolkit.Mvvm.SourceGenerators;
109
using Microsoft.CodeAnalysis;
1110
using Microsoft.CodeAnalysis.CodeActions;
1211
using Microsoft.CodeAnalysis.CodeFixes;
@@ -40,17 +39,10 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
4039
Diagnostic diagnostic = context.Diagnostics[0];
4140
TextSpan diagnosticSpan = context.Span;
4241

43-
// Retrieve the property passed by the analyzer
44-
if (diagnostic.Properties[AsyncVoidReturningRelayCommandMethodAnalyzer.MethodNameKey] is not string methodName)
45-
{
46-
return;
47-
}
48-
4942
SyntaxNode? root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
5043

5144
// Get the method declaration from the target diagnostic
52-
if (root!.FindNode(diagnosticSpan) is MethodDeclarationSyntax { Identifier.Text: string identifierName } methodDeclaration &&
53-
identifierName == methodName)
45+
if (root!.FindNode(diagnosticSpan) is MethodDeclarationSyntax methodDeclaration)
5446
{
5547
// Register the code fix to update the return type to be Task instead
5648
context.RegisterCodeFix(

src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Analyzers/AsyncVoidReturningRelayCommandMethodAnalyzer.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ namespace CommunityToolkit.Mvvm.SourceGenerators;
1717
[DiagnosticAnalyzer(LanguageNames.CSharp)]
1818
public sealed class AsyncVoidReturningRelayCommandMethodAnalyzer : DiagnosticAnalyzer
1919
{
20-
/// <summary>
21-
/// The key for the name of the target method to update.
22-
/// </summary>
23-
internal const string MethodNameKey = "MethodName";
24-
2520
/// <inheritdoc/>
2621
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(AsyncVoidReturningRelayCommandMethod);
2722

@@ -57,7 +52,6 @@ public override void Initialize(AnalysisContext context)
5752
context.ReportDiagnostic(Diagnostic.Create(
5853
AsyncVoidReturningRelayCommandMethod,
5954
context.Symbol.Locations.FirstOrDefault(),
60-
ImmutableDictionary.Create<string, string?>().Add(MethodNameKey, methodSymbol.Name),
6155
context.Symbol));
6256
}, SymbolKind.Method);
6357
});

0 commit comments

Comments
 (0)