feat(erasing-op): add erasing-op rule#1521
Open
bartlomieju wants to merge 1 commit into
Open
Conversation
Ports oxlint's oxc/erasing-op (itself based on Clippy's erasing_op) to a native Rust rule. Flags binary operations that always evaluate to zero: `x * 0`, `0 * x`, `x & 0`, `0 & x`, and `0 / x` (but not `0 / 0`, which is NaN, nor `x / 0`). Parenthesized zeros are unwrapped. Tagged `recommended` (oxc category: correctness), so it would be on by default -- flagging for maintainer sign-off.
This was referenced Jun 30, 2026
Member
Author
|
Verdict: LGTM on the logic — needs the RECOMMENDED sign-off you flagged + a rebase. Not auto-merging (new rule). Faithful port of oxc/Clippy Correctness — verified
Minor / faithful-to-reference edges (non-blocking)
Perf: trivial — one Housekeeping: Logic is solid and well-tested. Blockers are just the tagging decision + rebase (+ docs). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports oxlint's
oxc/erasing-oprule (itself based on Clippy'serasing_op)to a native Rust rule. It flags binary operations whose result is always
zero, which is almost always a mistake rather than intent:
x * 0and0 * xx & 0and0 & x0 / xIt deliberately does not flag
0 / 0(evaluates toNaN) orx / 0(
Infinity/NaN), since neither is zero. Parenthesized zeros such asx * (0)are unwrapped and still flagged.The rule reuses the existing
Handler/bin_exprvisitor and reports thewhole binary expression. Tests are ported from the oxc rule's own pass/fail
fixtures, plus a few extra valid cases that lock the operator scope (
+,-,|are not erasing) and the0 / 0/x / 0carve-outs.This is the first of the oxc-correctness oxlint ports tracked in the lint
roadmap. One open decision for a maintainer: it is tagged
recommended(oxc classifies it as
correctness), which makes it on-by-default for everydeno lintuser. Happy to drop therecommendedtag if you would ratherland it opt-in first.
Reference: https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/oxc/erasing_op.rs