Skip to content

Commit 37e00dd

Browse files
authored
no-negation-in-equality-check: Ignore boolean type casting (#2379)
1 parent fce6ce3 commit 37e00dd

4 files changed

+7
-24
lines changed

rules/no-negation-in-equality-check.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ const create = context => ({
3131
BinaryExpression(binaryExpression) {
3232
const {operator, left} = binaryExpression;
3333

34-
if (
35-
!isEqualityCheck(binaryExpression)
36-
|| !isNegatedExpression(left)
37-
) {
34+
if (!(
35+
isEqualityCheck(binaryExpression)
36+
&& isNegatedExpression(left)
37+
&& !isNegatedExpression(left.argument)
38+
)) {
3839
return;
3940
}
4041

test/no-negation-in-equality-check.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ test.snapshot({
88
'!foo instanceof bar',
99
'+foo === bar',
1010
'!(foo === bar)',
11+
'!!foo === bar',
12+
'!!!foo === bar',
1113
// We are not checking right side
1214
'foo === !bar',
1315
],
@@ -45,6 +47,5 @@ test.snapshot({
4547
foo
4648
!/* comment */[a, b].join('') === c
4749
`,
48-
'!!foo === bar',
4950
],
5051
});

test/snapshots/no-negation-in-equality-check.mjs.md

-19
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,3 @@ Generated by [AVA](https://avajs.dev).
247247
1 | foo␊
248248
2 | ;/* comment */[a, b].join('') !== c␊
249249
`
250-
251-
## invalid(11): !!foo === bar
252-
253-
> Input
254-
255-
`␊
256-
1 | !!foo === bar␊
257-
`
258-
259-
> Error 1/1
260-
261-
`␊
262-
> 1 | !!foo === bar␊
263-
| ^ Negated expression in not allowed in equality check.␊
264-
265-
--------------------------------------------------------------------------------␊
266-
Suggestion 1/1: Switch to '!==' check.␊
267-
1 | !foo !== bar␊
268-
`
Binary file not shown.

0 commit comments

Comments
 (0)