Convert any equality check with -0
to the more precise Object.is
.
Details on on StackOverflow.
Apply with the Grit CLI
grit apply convert_negative_zero_equality_check_to_object_is
Basic example
BEFORE
if (x == -0 || x !== -0) { foo(); }
AFTER
if (Object.is(x, -0) || !Object.is(x, -0)) { foo(); }
Converts an if condition
BEFORE
if (x == -0) { foo(); } else { foo(); }
AFTER
if (Object.is(x, -0)) { foo(); } else { foo(); }
Converts a while condition
BEFORE
while (x == -0) { foo(); }
AFTER
while (Object.is(x, -0)) { foo(); }
Converts a for condition
BEFORE
for (let x = 6; x != -0; x--) { foo(); }
AFTER
for (let x = 6; !Object.is(x, -0); x--) { foo(); }
Converts complex conditions
BEFORE
if (x == -0 && y != -0) { foo(); }
AFTER
if (Object.is(x, -0) && !Object.is(y, -0)) { foo(); }