Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RelayCommand generates code that violates CA1708 #1045

Open
1 of 4 tasks
michaelmairegger opened this issue Jan 20, 2025 · 0 comments
Open
1 of 4 tasks

RelayCommand generates code that violates CA1708 #1045

michaelmairegger opened this issue Jan 20, 2025 · 0 comments
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior

Comments

@michaelmairegger
Copy link

michaelmairegger commented Jan 20, 2025

Describe the bug

RelayCommand generates code that violates CA1708

private global::CommunityToolkit.Mvvm.Input.AsyncRelayCommand? editCommand;
public global::CommunityToolkit.Mvvm.Input.IAsyncRelayCommand EditCommand => editCommand ??= new global::CommunityToolkit.Mvvm.Input.AsyncRelayCommand(new global::System.Func<global::System.Threading.Tasks.Task>(EditAsync), CanEdit);

but should be:

private global::CommunityToolkit.Mvvm.Input.AsyncRelayCommand? _editCommand;
public global::CommunityToolkit.Mvvm.Input.IAsyncRelayCommand EditCommand => _editCommand ??= new global::CommunityToolkit.Mvvm.Input.AsyncRelayCommand(new global::System.Func<global::System.Threading.Tasks.Task>(EditAsync), CanEdit);

Regression

No response

Steps to reproduce

Set latest-recommended on project

The error happens on net9 onwards since analysislevel_9_recommended.global has the rule

# CA1708: Identifiers should differ by more than case
dotnet_diagnostic.CA1708.severity = warning
[RelayCommand(CanExecute = nameof(CanEdit))]
private async Task EditAsync() {}

Expected behavior

Generated code be like suggested in CA1708 description:

private global::CommunityToolkit.Mvvm.Input.AsyncRelayCommand? _editCommand;
public global::CommunityToolkit.Mvvm.Input.IAsyncRelayCommand EditCommand => _editCommand ??= new global::CommunityToolkit.Mvvm.Input.AsyncRelayCommand(new global::System.Func<global::System.Threading.Tasks.Task>(EditAsync), CanEdit);

Screenshots

No response

IDE and version

Rider

IDE version

No response

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.4.0

Additional context

No response

Help us help you

Yes, but only if others can assist

@michaelmairegger michaelmairegger added the bug 🐛 An unexpected issue that highlights incorrect behavior label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior
Projects
None yet
Development

No branches or pull requests

1 participant