Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: warn about ambiguous properties/fields #107

Merged

Conversation

DeagleGross
Copy link
Collaborator

Original issue: DapperLib/Dapper#1993

added the rules:

  1. if properties of type have same normalized names -> DAP046 is reported:
    Properties have same name '{normalizedMemberName}' after normalization and can be conflated
    example:
public class Data
{
    public string First_Name { get; set; }
    public string FirstName { get; set; }
}
  1. if fields of type have same normalized names -> DAP047 is reported:
    Fields have same name '{normalizedMemberName}' after normalization and can be conflated
public class Data
{
    public string first_name;
    public string _firstName;
}

Note: I changed the locations calculations reported for properties.
For ElementMember representing public string Name { get; set; } property, calling member.GetLocation() will return Span, wrapping the whole property definition (including modifiers, getter and setter).

I thought that standard way of reporting errors is to link the diagnostic with the member name. For example (not related to Dapper) - duplicate property names of type:
image

So I decided to bring such a consistency to the diagnostics. Also fields are reported only on the names (not the full field definition). Let me know if that change should be reverted

Closes #65

@DeagleGross DeagleGross self-assigned this Dec 22, 2023
@DeagleGross DeagleGross merged commit 526745f into DapperLib:main Feb 17, 2024
1 check passed
@DeagleGross DeagleGross deleted the dmkorolev/ambiguous-properties branch February 17, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn about ambiguous properties/fields
1 participant