Skip to content

Commit

Permalink
S6964: Issue is reported on the attribute instead of the property (#9332
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mary-georgiou-sonarsource authored May 27, 2024
1 parent 5fb5a91 commit b76ac90
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Id": "S6964",
"Message": "Property used as input in a controller action should be nullable or annotated with the Required attribute to avoid under-posting.",
"Uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/Projects/ManuallyAddedNoncompliantIssues.CS/IntentionalFindings/S6964.cs#L9",
"Location": "Line 9 Position 13-51"
"Location": "Line 9 Position 24-37"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static void CheckInvalidProperties(INamedTypeSymbol parameterType, Sonar
.Where(x => !CanBeNull(x.Type) && !x.HasAnyAttribute(ValidationAttributes) && !x.IsRequired());
foreach (var property in invalidProperties)
{
context.ReportIssue(Rule, property.GetFirstSyntaxRef().GetLocation());
context.ReportIssue(Rule, property.GetFirstSyntaxRef().GetIdentifier()?.GetLocation());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class Model
{
public int ValueProperty { get; set; } // Noncompliant

[Custom] // Noncompliant repro for https://github.com/SonarSource/sonar-dotnet/issues/9282
public int ValuePropertyAnnotatedWithCustomAttribute { get; set; }
[Custom]
public int ValuePropertyAnnotatedWithCustomAttribute { get; set; } // Noncompliant

[JsonRequired] // Compliant - the property is annotated with JsonRequiredAttribute
public int AnotherValueProperty { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ClassNotUsedInRequests
public class ModelUsedInController
{
public int ValueProperty { get; set; } // Noncompliant {{Property used as input in a controller action should be nullable or annotated with the Required attribute to avoid under-posting.}}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^
public int? NullableValueProperty { get; set; }
[Required] public int RequiredValueProperty { get; set; }
[Range(0, 10)] public int ValuePropertyWithRangeValidation { get; set; } // Noncompliant
Expand Down

0 comments on commit b76ac90

Please sign in to comment.