oxc-project/oxc · error · OxcDiagnostic
Unexpected erasing operation. This expression will always ev
Error message
Unexpected erasing operation. This expression will always evaluate to zero.
What it means
Oxlint rule `oxc/erasing-op` flags operations where one operand is zero so the whole expression always evaluates to zero, e.g. `x * 0` (modelled on clippy's `erasing_op`). The help text states this is most likely not the intended outcome and suggests removing the operation or assigning zero directly.
Source
Thrown at crates/oxc_linter/src/rules/oxc/erasing_op.rs:14
// Based on https://github.com/rust-lang/rust-clippy//blob/00e9372987755dece96561ef2eef0785c8742e55/clippy_lints/src/operators/erasing_op.rs
use oxc_ast::{
AstKind,
ast::{BinaryExpression, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_syntax::operator::BinaryOperator;
use crate::{AstNode, context::LintContext, rule::Rule};
fn erasing_op_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected erasing operation. This expression will always evaluate to zero.")
.with_help("This is most likely not the intended outcome. Consider removing the operation, or directly assigning zero to the variable")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct ErasingOp;
declare_oxc_lint!(
/// ### What it does
///
/// Checks for erasing operations, e.g., `x * 0`.
///
/// Based on https://rust-lang.github.io/rust-clippy/master/#/erasing_op
///
/// ### Why is this bad?
///
/// The whole expression can be replaced by zero. This is most likely not the intended outcome and should probably be corrected.
///View on GitHub (pinned to e1e7af627c)
Solutions
- Remove the multiplication or assign `0` directly
- If the zero is a bug in a constant, fix the constant
- If the zeroing is intentional, write `0` explicitly so the intent is obvious
Example fix
// before const scaled = price * 0; // always 0 // after const scaled = 0;
Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json — correctness rule (on in the default category set)
{
"rules": { "oxc/erasing-op": "error" }
}
// CLI: npx oxlint src/ Prevention
- Treat a 0 literal inside arithmetic as a smell until proven intentional
- Unit-test calculations with non-zero inputs so a zeroed constant fails the suite
- Define rates/factors as named constants reviewed separately from their use sites
When it happens
Trigger: `x * 0`, `total * 0` in an assignment, tax/discount math where a rate constant ended up as 0, calculations left half-finished after a refactor.
Common situations: A constant (rate, factor, weight) becomes 0 after a refactor and silently zeroes the result; placeholder math that was never finished; intentional but obscure zeroing that readers misinterpret.
Related errors
- Unexpected object literal comparison.
- Left-hand side of `&&` operator has no effect.
- Right-hand side of `&&` operator has no effect.
- Unexpected constant comparison
- Missing throw
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/9197081e18d0d645.
Report an issue: GitHub.