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

Rule proposal: Forbid !foo === bar #1421

Closed
fisker opened this issue Jul 14, 2021 · 8 comments · Fixed by #2353
Closed

Rule proposal: Forbid !foo === bar #1421

fisker opened this issue Jul 14, 2021 · 8 comments · Fixed by #2353

Comments

@fisker
Copy link
Collaborator

fisker commented Jul 14, 2021

I'm not sure what name it should be, this is a common mistake, espeically when doing quick debugging. Personally I've done this several times.

We have this syntax forbidden in Prettier codebase, with no-restricted-syntax rule, because I made a mistake once there.

Fail

if (!foo === bar);
if (!foo !== bar);
// Don't have to be in `if`
const isEqual = !foo === bar;

Pass

if (!(foo === bar));
// I guess we should allow this, it's type-casting
if (!!foo === bar);
@sindresorhus
Copy link
Owner

no-negation-in-equality-check ?

@sindresorhus
Copy link
Owner

This looks similar to https://eslint.org/docs/rules/no-unsafe-negation Maybe that rule could support this too?

@fisker
Copy link
Collaborator Author

fisker commented Jul 14, 2021

That rule not checking this case, but I can make a proposal there.

@fisker
Copy link
Collaborator Author

fisker commented Jul 16, 2021

Forgot to mention here, issue on ESLint codebase eslint/eslint#14802, and seems they are going accept.

@fregante
Copy link
Collaborator

fregante commented Nov 2, 2021

no-mixed-operators can already do this, if configured correctly.

@fisker

This comment was marked as outdated.

@fisker

This comment was marked as duplicate.

@fisker
Copy link
Collaborator Author

fisker commented May 11, 2024

Accepted as no-negation-in-equality-check.

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

Successfully merging a pull request may close this issue.

3 participants