{"record":{"id":"9197081e18d0d645","repo":"oxc-project/oxc","slug":"unexpected-erasing-operation-this-expression-will","errorCode":null,"errorMessage":"Unexpected erasing operation. This expression will always evaluate to zero.","messagePattern":"Unexpected erasing operation\\. This expression will always evaluate to zero\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/oxc/erasing_op.rs","lineNumber":14,"sourceCode":"// Based on https://github.com/rust-lang/rust-clippy//blob/00e9372987755dece96561ef2eef0785c8742e55/clippy_lints/src/operators/erasing_op.rs\nuse oxc_ast::{\n    AstKind,\n    ast::{BinaryExpression, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_syntax::operator::BinaryOperator;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn erasing_op_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected erasing operation. This expression will always evaluate to zero.\")\n        .with_help(\"This is most likely not the intended outcome. Consider removing the operation, or directly assigning zero to the variable\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct ErasingOp;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Checks for erasing operations, e.g., `x * 0`.\n    ///\n    /// Based on https://rust-lang.github.io/rust-clippy/master/#/erasing_op\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The whole expression can be replaced by zero. This is most likely not the intended outcome and should probably be corrected.\n    ///","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/erasing_op.rs#L1-L32","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst scaled = price * 0; // always 0\n\n// after\nconst scaled = 0;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — correctness rule (on in the default category set)\n{\n  \"rules\": { \"oxc/erasing-op\": \"error\" }\n}\n// CLI: npx oxlint src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["oxlint","oxc","arithmetic","logic-bug","javascript","static-analysis"],"backgroundTag":"multiply-by-zero","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}