Skip to content

Commit

Permalink
no-negation-in-equality-check: Ignore boolean type casting (#2379)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored Jun 14, 2024
1 parent fce6ce3 commit 37e00dd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
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.

0 comments on commit 37e00dd

Please sign in to comment.