Generator.Equals icon indicating copy to clipboard operation
Generator.Equals copied to clipboard

Add diagnostics in case any property is marked with a Generator.Equals-related attribute, but the containing type is not marked [Equatable]

Open fabianoliver opened this issue 7 months ago • 8 comments

First of all, thanks for this amazing project! It has snuck its way into many projects of mine.

As a small suggestion, it might be really helpful if it'd be possible to add diagnostics when any property is annotated with a Generator.Equals-related attribute, but the containing type is not properly marked. For example

record Test([property: UnorderedEquality] IReadOnlyCollection<int> stuff)

This looks deceptively correct to the coffee-deprived brain, and in fact "someone" may have just accidentally wasted an hour debugging an issue that just boiled down to this oversight.

The code above currently doesn't generate any warnings or errors. It'd be quite nice to get a diagnostics warning in such cases saying that the type should be marked with [Equatable].

fabianoliver avatar May 29 '25 13:05 fabianoliver

This is an excellent suggestion. An analyzer should support something like an opt-out mechanism where all non-primitive fields are explicitly marked with a specific attribute to control their comparison behavior.

NikiforovAll avatar Sep 17 '25 05:09 NikiforovAll

Added Analyzer for this scenario: https://github.com/NikiforovAll/Generator.Equals.Analyzers

cc: @fabianoliver

NikiforovAll avatar Sep 17 '25 18:09 NikiforovAll

@diegofrata, could you please consider adding this package to your repo?

NikiforovAll avatar Sep 18 '25 09:09 NikiforovAll

yeah, that would be nice feature to have

sergey-tihon avatar Sep 18 '25 17:09 sergey-tihon

@NikiforovAll what's the proposed integration here? Add this as dependency or just have it built into this package?

diegofrata avatar Sep 23 '25 07:09 diegofrata

I'd like to suggest adding an analyzer as a separate package to this GitHub repo. My analyzer implementation could serve as a foundation or reference point for this addition.

NikiforovAll avatar Sep 23 '25 09:09 NikiforovAll

@NikiforovAll that's what I thought! I might try to rip your code into Generator.Equals if that's okay with you. Would you mind adding a LICENCE.md file to your repo (I suggest MIT), so that I can bring your code in?

diegofrata avatar Sep 23 '25 11:09 diegofrata

FYI

@diegofrata updated the license file.

NikiforovAll avatar Sep 23 '25 11:09 NikiforovAll