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

Fix S3459 FP: Support @ref bindings in razor files / partial Blazor components #8538

Open
naefp opened this issue Jan 15, 2024 · 1 comment · May be fixed by #9567
Open

Fix S3459 FP: Support @ref bindings in razor files / partial Blazor components #8538

naefp opened this issue Jan 15, 2024 · 1 comment · May be fixed by #9567
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.

Comments

@naefp
Copy link

naefp commented Jan 15, 2024

Description

When declaring a private field in a razor.cs file, and bind it by ref in the related razor file, sonar marks it as not assigned. Sonar should check the related razor file for S3459 as well.

Repro steps

Create a Blazor component with two files:

MyBlazorComponent.razor

<Modal @ref="@_myModalRef">
</Modal>

MyBlazorComponent.razor.cs

public partial class MyBlazorComponent
{
  private Modal _myModalRef; // Sonar marks this field as not assigned
}

Expected behavior

Recognize that the field actually is being assigned by ref in razor file.

Actual behavior

Mark every occurrence as false positive, or disable rule csharpsquid:S3459 for **/*.razor.cs completely.

Probably not using code in separate *razor.cs file but declare the private field in the razor file itself. Did not test that.

Known workarounds

Please provide a description of any known workarounds.

Related information

  • C# 12
  • Rider 2023.3.2
  • .Net 8
  • SonarLint plugin 10.2.1.77304 connected to SonarCloud
  • Windows 11
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be. labels Jan 16, 2024
@zsolt-kolbay-sonarsource
Copy link
Contributor

Thank you for reporting this. Confirmed as False Positive.

@martin-strecker-sonarsource martin-strecker-sonarsource changed the title Fix S3459 FP: Unassigned members should be removed -> Does not recognize bindings from razor files / partial Blazor components Fix S3459 FP: Support @ref bindings in razor files / partial Blazor components Jun 4, 2024
@martin-strecker-sonarsource martin-strecker-sonarsource removed their assignment Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
3 participants