SonarSource/sonar-dotnet

S6964: Issue is reported on the attribute instead of the property

Closed this issue · 0 comments

When a model property is annotated with any attribute the issue is reported on the attribute instead of the property which is confusing.

using System;
using Microsoft.AspNetCore.Mvc;

  public class Model
  {
      public int ValueProperty { get; set; }        // Noncompliant

      [Custom]                                      // Noncompliant
      public int ValuePropertyAnnotatedWithCustomAttribute { get; set; } // The issue should be raised here, and not on the attribute above.
  }

  public class DerivedFromController : Controller
  {
      [HttpPost] public IActionResult Create(Model model) => View(model);
  }
  
  public class CustomAttribute : Attribute { }