noUnsafeNegation (since v0.7.0)
This rule is recommended by Rome.
Disallow using unsafe negation.
Examples
Invalid
!1 in [1,2]; error[js/noUnsafeNegation]: The negation operator is used unsafely on the left side of this binary expression.
┌─ js/noUnsafeNegation.js:1:1
│
1 │ !1 in [1,2];
│ ^^^^^^^^^^^
Suggested fix: Wrap the expression with a parenthesis
| @@ -1 +1 @@
0 | - !1 in [1,2];
0 | + !(1 in [1,2]);
/**test*/!/** test*/1 instanceof [1,2]; error[js/noUnsafeNegation]: The negation operator is used unsafely on the left side of this binary expression.
┌─ js/noUnsafeNegation.js:1:10
│
1 │ /**test*/!/** test*/1 instanceof [1,2];
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Suggested fix: Wrap the expression with a parenthesis
| @@ -1 +1 @@
0 | - /**test*/!/** test*/1 instanceof [1,2];
0 | + /**test*/!/** test*/(1 instanceof [1,2]);
Valid
-1 in [1,2];
~1 in [1,2];
typeof 1 in [1,2];
void 1 in [1,2];
delete 1 in [1,2];
+1 instanceof [1,2];