AvaloniaUI / avalonia-dotnet-templates

Avalonia Templates for `dotnet new`
MIT License
514 stars 89 forks source link

ViewLocator causes warning CA1725 #269

Closed philipp-naused closed 1 week ago

philipp-naused commented 1 month ago

Describe the bug

The template (as well as all code examples I can find) for the default ViewLocator implements ITemplate.Build with this signature:

Control? Build(object? data)

but the interface has a different parameter name:

Control? Build(object? param)

This causes warning CA1725: Parameter names should match base declaration

Depending on your code analysis settings, this can cause the build to fail.

To Reproduce

  1. Create a project from the avalonia.mvvm template.
  2. Add these properties to the project:
    <EnableNETAnalyzers>True</EnableNETAnalyzers>
    <AnalysisLevel>8.0-recommended</AnalysisLevel>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  3. build the project

The build fails with:

ViewLocator.cs(11,39): error CA1725: In member Control? ViewLocator.Build(object? data), change parameter name data to param in order to match the identifier as it has been declared in Control? ITemplate<object?, Control?>.
Build(object? param) (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1725)

Avalonia Templates version

11.0.10.1

Avalonia version

11.1.3

Additional context

No response

maxkatz6 commented 1 month ago

Argument name should be adjusted in this repository.

philipp-naused commented 1 month ago

This doesn't just affect the template repo: https://github.com/search?q=org%3AAvaloniaUI+%22Control%3F+Build%28object%3F+data%29%22&type=code

maxkatz6 commented 1 month ago

@philipp-naused it's only important here, as templates is what developers will get when they create a new project. We can eventually update naming in other samples, sure.

And we definitely can't change name of the ITemplate.Build argument, as it will cause way more such warnings, just in other direction.