Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@3sRykaert
Copy link
Contributor

@3sRykaert 3sRykaert commented Apr 15, 2025

Allow to disable null mismatch diagnostics RMG089

Description

Code change for #1613 (only yet for RMG089)
Any feedback is already appreciated.

Fixes #1613

Checklist

  • The existing code style is followed
  • The commit message follows our guidelines
  • Performed a self-review of my code
  • Hard-to-understand areas of my code are commented
  • The documentation is updated (as applicable)
  • Unit tests are added/updated
  • Integration tests are added/updated (as applicable, especially if feature/bug depends on roslyn or framework version in use)

@3sRykaert
Copy link
Contributor Author

I'm still struggling with the unittest for RMG90 when setting SuppressNullMismatchDiagnostic to true, that test is failing cause the configation of the SuppressNullMismatchDiagnostic stays false, but I can't figure out why. Anyone able to help with this?

@latonz latonz added the enhancement New feature or request label Apr 19, 2025
@latonz
Copy link
Contributor

latonz commented Apr 20, 2025

I'm still struggling with the unittest for RMG90 when setting SuppressNullMismatchDiagnostic to true, that test is failing cause the configation of the SuppressNullMismatchDiagnostic stays false, but I can't figure out why. Anyone able to help with this?

You should be able to debug this by adding a conditional breakpoint in Riok.Mapperly.Diagnostics.DiagnosticCollection.ReportDiagnostic and setting the condition to the diagnostic id you want to debug (e.g. descriptor.Id == "RMG090"). With this breakpoint, you can debug the failing unit test. Once the breakpoint is hit, you can walk up the stack trace to identify why the diagnostic was reported.

@3sRykaert
Copy link
Contributor Author

3sRykaert commented Apr 20, 2025

I'm still struggling with the unittest for RMG90 when setting SuppressNullMismatchDiagnostic to true, that test is failing cause the configation of the SuppressNullMismatchDiagnostic stays false, but I can't figure out why. Anyone able to help with this?

You should be able to debug this by adding a conditional breakpoint in Riok.Mapperly.Diagnostics.DiagnosticCollection.ReportDiagnostic and setting the condition to the diagnostic id you want to debug (e.g. descriptor.Id == "RMG090"). With this breakpoint, you can debug the failing unit test. Once the breakpoint is hit, you can walk up the stack trace to identify why the diagnostic was reported.

Yes, I have already done that, but I find it too complex to find out why SuppressNullMismatchDiagnostic remains false here (although i specify it in the test as true)
image
I think it's cause in the unittest the TypeMappingConfiguration.Default is used (i believe this is the same as @kakone says here above)
image

@latonz
Copy link
Contributor

latonz commented Apr 21, 2025

The NullableTypeWithSuppressNullMismatchDiagnosticTrueShouldIgnoreWarningRMG090 test fails due to the following:

  • [MapProperty(\"IdA\", \"IdB\", SuppressNullMismatchDiagnostic = true)] ignores RMG089 for the mapping of the property IdA to IdB
  • The user-defined mapping B Map(A? source) also has a null mismatch. The RMG090 gets emitted for this mapping, but not for the property mapping IdA => IdB.

So RMG090 is always emitted on a type mapping but not on a member mapping. So I'm not sure whether it makes sense to suppress it via a member on the MapProperty attribute as it is not related to a member. Couldn't these RMG090 already be suppressed with a SuppressMessage attribute? Otherwise we would need to think about adding SuppressNullMismatchDiagnostic to the UserMapping attribute 🤔

Copy link
Contributor

@latonz latonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! 😊

@3sRykaert
Copy link
Contributor Author

The NullableTypeWithSuppressNullMismatchDiagnosticTrueShouldIgnoreWarningRMG090 test fails due to the following:

  • [MapProperty(\"IdA\", \"IdB\", SuppressNullMismatchDiagnostic = true)] ignores RMG089 for the mapping of the property IdA to IdB
  • The user-defined mapping B Map(A? source) also has a null mismatch. The RMG090 gets emitted for this mapping, but not for the property mapping IdA => IdB.

So RMG090 is always emitted on a type mapping but not on a member mapping. So I'm not sure whether it makes sense to suppress it via a member on the MapProperty attribute as it is not related to a member. Couldn't these RMG090 already be suppressed with a SuppressMessage attribute? Otherwise we would need to think about adding SuppressNullMismatchDiagnostic to the UserMapping attribute 🤔

I was just trying to do what was said in #1613 . So if I understand, correctly, this ain't possible with the MapProperty attribute for RMG090?

@3sRykaert 3sRykaert requested a review from latonz April 21, 2025 14:04
@latonz
Copy link
Contributor

latonz commented Apr 21, 2025

@3sRykaert When I wrote the issue, I didn't conduct a thorough analysis. In my opinion, it works for RMG090 when dealing with generated mappings, but not for user-defined mappings.

@3sRykaert
Copy link
Contributor Author

@latonz maybe we can then split up the issues in 2 separate ones:

  • one for RMG089 which can be this
  • and one for RM090 which is still todo

If you agree, I'll adjust the code to only keep RMG089 into account.

@3sRykaert 3sRykaert requested a review from kakone April 23, 2025 05:34
Copy link
Contributor Author

@3sRykaert 3sRykaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed as suggested

@latonz latonz changed the title 1613#Allow to disable null mismatch diagnostics RMG089 feat: Allow to disable null mismatch diagnostics RMG089 per member May 27, 2025
@latonz latonz merged commit 60ce8ef into riok:main May 27, 2025
19 checks passed
@3sRykaert 3sRykaert deleted the 1613 branch May 27, 2025 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to disable null mismatch diagnostics (RMG089 and RMG090) for specific members

4 participants