Should S2701 apply to bool? datatypes

csharp

(Paul Hickman) #1

Version 7.5.0.660

The following causes rule S2701 to fire:

            bool? x = false;
            Assert.AreEqual(false, x);

However, the suggested change fails to compile:

            Assert.IsFalse(x);

And I think the following is less clear than using the literal boolean value:

            Assert.IsFalse(x ?? true);

(Valeri Hristov) #2

Hi @paulhickman, I apologize for the late response. Your suggestion makes sense, I created a ticket to track it: https://github.com/SonarSource/sonar-csharp/issues/1874