Skip to content

Commit

Permalink
AV1710: Add exception for User.UserName (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman committed Feb 6, 2024
1 parent 4772eff commit eca228d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ class Order
await VerifyGuidelineDiagnosticAsync(source);
}

[Fact]
internal async Task When_User_class_contains_UserName_property_it_must_be_skipped()
{
// Arrange
ParsedSourceCode source = new TypeSourceCodeBuilder()
.InGlobalScope(@"
class User
{
string UserName { get; set; }
}
")
.Build();

// Act and assert
await VerifyGuidelineDiagnosticAsync(source);
}

[Fact]
internal async Task When_event_name_contains_class_name_it_must_be_reported()
{
Expand Down Expand Up @@ -344,7 +361,7 @@ static Employee()
}

[Fact]
internal async Task When_class_contains_static_destructor_it_must_be_skipped()
internal async Task When_class_contains_destructor_it_must_be_skipped()
{
// Arrange
ParsedSourceCode source = new TypeSourceCodeBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ private static void AnalyzeMemberName([NotNull] string containingTypeName, Symbo
{
string memberName = context.Symbol.MemberNameWithoutExplicitInterfacePrefix();

if (memberName.Contains(containingTypeName))
if (memberName.Contains(containingTypeName) && !IsUserNameInUserType(containingTypeName, memberName))
{
var diagnostic = Diagnostic.Create(Rule, context.Symbol.Locations[0], context.Symbol.Kind, context.Symbol.Name, containingTypeName);
context.ReportDiagnostic(diagnostic);
}
}

private static bool IsUserNameInUserType([NotNull] string containingTypeName, [NotNull] string memberName)
{
return containingTypeName == "User" && memberName.ToLowerInvariant() == "username";
}
}
}

0 comments on commit eca228d

Please sign in to comment.