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

no-negation-in-equality-check: Ignore boolean type casting #2379

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions rules/no-negation-in-equality-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ const create = context => ({
BinaryExpression(binaryExpression) {
const {operator, left} = binaryExpression;

if (
!isEqualityCheck(binaryExpression)
|| !isNegatedExpression(left)
) {
if (!(
isEqualityCheck(binaryExpression)
&& isNegatedExpression(left)
&& !isNegatedExpression(left.argument)
)) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion test/no-negation-in-equality-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ test.snapshot({
'!foo instanceof bar',
'+foo === bar',
'!(foo === bar)',
'!!foo === bar',
'!!!foo === bar',
// We are not checking right side
'foo === !bar',
],
Expand Down Expand Up @@ -45,6 +47,5 @@ test.snapshot({
foo
!/* comment */[a, b].join('') === c
`,
'!!foo === bar',
],
});
19 changes: 0 additions & 19 deletions test/snapshots/no-negation-in-equality-check.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,3 @@ Generated by [AVA](https://avajs.dev).
1 | foo␊
2 | ;/* comment */[a, b].join('') !== c␊
`

## invalid(11): !!foo === bar

> Input

`␊
1 | !!foo === bar␊
`

> Error 1/1

`␊
> 1 | !!foo === bar␊
| ^ Negated expression in not allowed in equality check.␊
--------------------------------------------------------------------------------␊
Suggestion 1/1: Switch to '!==' check.␊
1 | !foo !== bar␊
`
Binary file modified test/snapshots/no-negation-in-equality-check.mjs.snap
Binary file not shown.