Skip to content

Add a rule to prevent checking boolean explicit on true or false #2352

Open

Description

@HeikoAdams

We have so older projects where boolean values are checked like that

if (a == true)
{
....
}

...

if (b == false)
{
...
}

So it would be nice if there was a rule to prevent such useless code which IMHO makes sources harder to read.

Activity

  1. vweijsters commented on May 12, 2017

    @vweijsters
    Contributor

    I'm OK with this. It wouldn't be high on my list to implement, but if someone wants to take a shot at it, it should not be that hard to implement it (and the code fix).

  2. pdelvo commented on Aug 15, 2017

    @pdelvo
    Member

    Do we only want this if a is Boolean? What if a is a Nullable? What if there is an implicit conversion from the type of a to Boolean?

    Personally I would only do this if a is Boolean.

  3. sharwell commented on Aug 15, 2017

    @sharwell
    Member

    If a is nullable then the meaning of == changes. I agree that this is only suitable is a has type bool, or if there is an implicit conversion operator from a to bool (as opposed to a user-defined operator== for a with bool).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions