Skip to content

unsafeNegations

Reports negating the left operand of in or instanceof relations.

✅ This rule is included in the ts javascript presets.

Negating the left-hand side of in or instanceof changes the meaning due to operator precedence. Use !(left in right) or !(left instanceof Right) to negate the relation as intended.

AE53 <((sp ansty="le--0:#C792EA;--1:#8844">A53key<) sp ansty="le--0:#7FDBCA;--1:#096E">7253 object)< {d ivclassNa="meec-li">5<3}d ivclassNa="meec-li">dAE53 <((sp ansty="le--0:#C792EA;--1:#8844">A53object<) sp ansty="le--0:#C792EA;--1:#8844">AEinstance5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Construct53)< {d ivclassNa="meec-li">5<3}d ivclassNa="meec-li">dAE53 <((sp ansty="le--0:#C792EA;--1:#8844">A53key<) sp ansty="le--0:#7FDBCA;--1:#096E">7253 object)< {d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
443F<53 ( spans="tyle--0:#C792EA;--1:#88">4<4AE! spans="tyle--0:#D6DEEB;--1:#40">3F53(6E<72in spans="tyle--0:#D6DEEB;--1:#40">3F53 object<)) {divclass="Nameec-">3c443F<53 ( spans="tyle--0:#C792EA;--1:#88">4<4AE! spans="tyle--0:#D6DEEB;--1:#40">3F53(obj44AEinstan31111Constru3F53<)) {divclass="Nameec-">3c443F53 (6E<72in spans="tyle--0:#D6DEEB;--1:#40">3F53 objec3443F53 (obj44AEinstan31111Constru3F5<3) {divclass="Nameec-">3< {>

This rule is not configurable.

If your codebase never negates in or instanceof relations, this rule may provide limited value. However, keeping it enabled prevents subtle precedence mistakes that change control-flow conditions.