Skip to content

numericErasingOperations

Reports operations that always result in zero, such as multiplication by zero.

✅ This rule is included in the ts logicalStrict presets.

This rule reports operations that always result in zero, regardless of the other operand.

These “erasing” operations typically indicate a logic error where the developer may have intended a different operation. The entire expression can be replaced with 0 directly.

const value = x * 0;
const value = 0 * x;
const value = x & 0;
const value = 0 / x;

This rule is not configurable.

If you are intentionally using these operations for their side effects or as a stylistic choice to indicate the result should be zero, you may want to disable this rule. However, in most cases, directly using 0 is clearer.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.