oxc/erasing-op

Disallow operations with 0 that erase the other operand

fixable

x * 0, x & 0 and 0 / x are zero for any ordinary number x. The other operand does nothing, so the 0 is probably a typo or a leftover from debugging.

The rule reports * and & with a literal 0 on either side, and / with a literal 0 on the left. Dividing by zero, as in x / 0, isn't reported.

--fix-dangerously replaces the whole expression with 0. That drops the other operand, including any function call in it.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"oxc/erasing-op" = "error" # or "warn"

Examples#

example.js3 problems
const tax = price * 0;
const masked = flags & 0;
const ratio = 0 / total;
example.jsNo problems
const tax = price * 0.2;
const masked = flags & 1;
const ratio = used / total;