SonarSource/sonar-dotnet

Fix S6967 FP: Raises when model has no validation attributes

Opened this issue · 0 comments

Description

Rule S6967 is firing for a model with no validation attributes.

Repro steps

Simplified example:

[Controller]
public class MyController : ControllerBase
{
    [HttpPost]
    public async Task<IActionResult> CheckYourAnswers(CheckYourAnswersViewModel model)
    {
       // view is readonly
        return RedirectToAction("Confirmation");
    }
}

public class CheckYourAnswersViewModel
{
    public string Property1 { get; set; } = string.Empty;
    public AnotherViewModel Property2 { get; set; }
}

public class AnotherViewModel
{
    public string Property1 { get; set; }
}

Expected behaviour

Rule S6967 says:
| The rule will not raise issues if the model, or the model members, are not decorated with validation attributes

As neither model class has validation attributes the rule is not triggered.

Actual behaviour

S6967 is triggered.

Related information

.NET 8.0
SonarCloud extension for Azure DevOps v1.41.0