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 option in no-unsafe-negation to report ! a < b #12163

Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint Hacktoberfest Recommended issue for those participating in Hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules

Comments

@mdjermanovic
Copy link
Member

What rule do you want to change?

no-unsafe-negation

This rule disallows negating the left operand of Relational Operators.

The rule currently targets only in and instanceof.

<, >, <=, >= are also relational operators.

! a < b is equivalent to (a ? 0 : 1) < b (I think), which is rarely the intended meaning:

function min(a, b) {
    let m = a;
    if (! a < b) {
        m = b;
    }
    return m;
}

min(1, 2); // 2

Does this change cause the rule to produce more or fewer warnings?

More if the option is set to true. Default is false.

How will the change be implemented? (New option, new default behavior, etc.)?

New option.

Please provide some example code that this change will affect:

/*eslint no-unsafe-negation: "error"*/

if (! a < b) {}

while (! a > b) {}

foo = ! a <= b;

foo = ! a >= b;

What does the rule currently do for this code?

Nothing.

What will the rule do after it's changed?

4 errors

/*eslint no-unsafe-negation: ["error", { "enforceForOrderingRelations": true }]*/

if (! a < b) {} // error

while (! a > b) {} // error

foo = ! a <= b; // error

foo = ! a >= b; // error

Are you willing to submit a pull request to implement this change?

Yes.

@mdjermanovic mdjermanovic added enhancement This change enhances an existing feature of ESLint triage An ESLint team member will look at this issue soon rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Aug 25, 2019
@mdjermanovic mdjermanovic self-assigned this Sep 2, 2019
@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion and removed enhancement This change enhances an existing feature of ESLint labels Sep 30, 2019
@kaicataldo
Copy link
Member

This has now been accepted.

@kaicataldo kaicataldo added Hacktoberfest Recommended issue for those participating in Hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted The team would welcome a contribution from the community for this issue labels Oct 1, 2019
@samrae7
Copy link
Contributor

samrae7 commented Oct 11, 2019

@mdjermanovic do you still want to do the PR for this? If not I could take it on

@mdjermanovic
Copy link
Member Author

@samrae7 feel free to claim this. PR is welcome, thanks!

@samrae7
Copy link
Contributor

samrae7 commented Oct 12, 2019

@mdjermanovic thank you. I will work on it over the weekend

samrae7 added a commit to samrae7/eslint that referenced this issue Oct 13, 2019
samrae7 added a commit to samrae7/eslint that referenced this issue Oct 13, 2019
samrae7 added a commit to samrae7/eslint that referenced this issue Oct 13, 2019
@mdjermanovic mdjermanovic added enhancement This change enhances an existing feature of ESLint and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Oct 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.