Fix S6964 FP: Should not raise for reference properties in nullable context #9284
Labels
Area: C#
C# rules related issues.
Sprint: Hardening
Fix FPs/FNs/improvements
Type: False Positive
Rule IS triggered when it shouldn't be.
Milestone
Description
The rule S6964 should not be active for model properties in a nullable aware context (where nullable reference types are enabled). This is because of:
Source: https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.mvcoptions.suppressimplicitrequiredattributefornonnullablereferencetypes
Even if a project sets this property to true, the rule should not be reported in my opinion. Because then it was an explicit decision made by the developer (e.g. because the project uses a different validation framework like FluentValidation).
Repro steps
string
) and use it in a POST controller method.Required
attribute manually.Expected behavior
Rule should not be reported.
Actual behavior
Rule is reported.
Known workarounds
I had to create a new quality profile in SonarCloud to disable the rule completely.
Related information
SonarCloudPrepare@1
task)SonarCloudAnalyze@1
task)windows-latest
build agent on Azure DevOpsThe text was updated successfully, but these errors were encountered: