fluentassertions / fluentassertions.analyzers

Analyzers based on the FluentAssertions best practices docs
https://www.fluentassertions.com/tips
MIT License
136 stars 21 forks source link

Allow disabling hint on specifically `Assert.NotNull` #373

Closed Alxandr closed 2 months ago

Alxandr commented 3 months ago

Description

Assert.NotNull from xunit has annotations that .NET. This method is thus not just to convert in the same vein as most other xunit assertions.

Complete minimal example reproducing the issue

var subject = GetThingOrNull();
Assert.NotNull(subject);
subject.Property.Should().HaveCount(5);

This is fine, but if I change the Assert.NotNull per fluent-assertions suggestion to subject.Should().NotBeNull(), I get a compiler-warning on the property access.

Meir017 commented 2 months ago

@Alxandr which IDE are you using? rider? I'm not seeing any special annotation in the unit library for the NotNull assertion. https://github.com/nunit/nunit/blob/6d6a424626ffc21cbb636016d6c804efe4bfbb3c/src/NUnitFramework/nunit.framework.legacy/Assert.Conditions.cs#L205

Alxandr commented 2 months ago

xunit - https://github.com/xunit/assert.xunit/blob/309647ac2fc29997937a22afaaeb0a73fb80d14b/NullAsserts.cs#L26

Meir017 commented 2 months ago

@Alxandr I think this is discussed here https://github.com/fluentassertions/fluentassertions/issues/1074 As I understand this will be supported in fluentassertions v7 - https://github.com/fluentassertions/fluentassertions/pull/2380

Alxandr commented 2 months ago

Yeah - it seems that v7 will get around the issue by cheating. I guess this is a reasonable compromise given that nullability doesn't really support the API of fluent assertions.

I still think being able to toggle of individual "upgrade" lints for flutentassertions would be a good feature to have - but may be less needed.

Meir017 commented 2 months ago

@Alxandr I forgot that this is already supported, see #376

Alxandr commented 2 months ago

Oh, nice :). Is this feature already released?

Meir017 commented 2 months ago

@Alxandr the configuration used the old name, just released https://github.com/fluentassertions/fluentassertions.analyzers/releases/tag/v0.33.0 that matches the new Configuration docs