Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rule: Avoid Comparison to Boolean #283

Open
elbrujohalcon opened this issue Feb 28, 2023 · 0 comments
Open

New rule: Avoid Comparison to Boolean #283

elbrujohalcon opened this issue Feb 28, 2023 · 0 comments
Labels
Milestone

Comments

@elbrujohalcon
Copy link
Member

Avoid Comparison to Boolean

Brief Description

A rule that disallows comparison to booleans.

Should be on by default?

YES

Reasoning

This is because these expressions evaluate to true or false, so you could get the same result by using either the variable directly or negating the variable.

Examples

-module bad.

-export [my_fun/2].

my_fun(P1, P2) ->
    case do:something(P1) == false orelse do:something(P2) == false of
        true -> "There is a false";
        false -> "All true"
    end.
-module good.

-export [my_fun/2].

my_fun(P1, P2) ->
    case (not do:something(P1)) orelse (not do:something(P2)) of
        true -> "There is a false";
        false -> "All true"
    end.

%% … or even …

my_fun(P1, P2) ->
    case do:something(P1) andalso do:something(P2) of
        true -> "All true";
        false -> "There is a false"
    end.

Origin (#281)

Inspired by the ComparisonToBoolean rule from Dogma.

@elbrujohalcon elbrujohalcon added this to the 3.0.0 milestone Feb 28, 2023
@paulo-ferraz-oliveira paulo-ferraz-oliveira changed the title Avoid Comparison to Boolean New rule: Avoid Comparison to Boolean Mar 1, 2023
@elbrujohalcon elbrujohalcon modified the milestones: 3.0.0, 3.1.0 Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant