diff --git a/rules/no-negation-in-equality-check.js b/rules/no-negation-in-equality-check.js index 9bcdbb8115..dd5df5aa57 100644 --- a/rules/no-negation-in-equality-check.js +++ b/rules/no-negation-in-equality-check.js @@ -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; } diff --git a/test/no-negation-in-equality-check.mjs b/test/no-negation-in-equality-check.mjs index 70d0e58025..d63621db93 100644 --- a/test/no-negation-in-equality-check.mjs +++ b/test/no-negation-in-equality-check.mjs @@ -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', ], @@ -45,6 +47,5 @@ test.snapshot({ foo !/* comment */[a, b].join('') === c `, - '!!foo === bar', ], }); diff --git a/test/snapshots/no-negation-in-equality-check.mjs.md b/test/snapshots/no-negation-in-equality-check.mjs.md index 6888103721..3b58274050 100644 --- a/test/snapshots/no-negation-in-equality-check.mjs.md +++ b/test/snapshots/no-negation-in-equality-check.mjs.md @@ -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␊ - ` diff --git a/test/snapshots/no-negation-in-equality-check.mjs.snap b/test/snapshots/no-negation-in-equality-check.mjs.snap index 9df853b5dd..27ceae7007 100644 Binary files a/test/snapshots/no-negation-in-equality-check.mjs.snap and b/test/snapshots/no-negation-in-equality-check.mjs.snap differ