feat: port bad-char-at-comparison, bad-object-literal-comparison, number-arg-out-of-range#1533
feat: port bad-char-at-comparison, bad-object-literal-comparison, number-arg-out-of-range#1533bartlomieju wants to merge 2 commits into
Conversation
…er-arg-out-of-range
Second batch of oxc-correctness oxlint ports, all purely syntactic:
- bad-char-at-comparison: flags comparing the result of `String.prototype
.charAt()` against a string whose length is not 1 (can never match).
- bad-object-literal-comparison: flags `x === {}` / `x !== []` and friends;
an empty object/array literal is a fresh reference, so the comparison is
always false (or always true for inequality).
- number-arg-out-of-range: flags out-of-range radix/precision arguments to
`toString`/`toFixed`/`toExponential`/`toPrecision`, which throw at runtime.
Tests are ported from each oxc rule's fixtures. All three are tagged
recommended (oxc category: correctness); same on-by-default decision as the
rest of the batch. Docs added in denoland/docs#3378.
|
Verdict: needs changes — Correctness — blocking (number-arg-out-of-range)
So the rule flags valid Deno code. Your own "invalid" fixtures are actually valid in Deno:
Since this is tagged bad-char-at-comparison — minor (false negative) bad-object-literal-comparison — logic (flag only empty Housekeeping: Blocker: correct the toFixed/toExponential/toPrecision ranges to the V8/ES2018 limits (0–100 / 1–100) + fix the fixtures, then rebase. Consider the UTF-16 tweak for bad-char-at-comparison. |
Second batch of oxc-correctness oxlint ports (the comparison family), following
erasing-opin #1521. All three are purely syntactic, withtests ported from the upstream oxc fixtures.
String.prototype.charAt()against a string whose length is not 1.charAtreturns a single UTF-16 code unit, so the comparison can never be true.
x === {},x !== []and similar.An empty object/array literal is a fresh reference that is never equal to
anything, so the comparison is always false (or always true for inequality).
Only empty literals are flagged;
x === { a: 1 }is left alone.toString(2–36),toFixed/toExponential(0–20), andtoPrecision(1–21). Out-of-range values throw a
RangeErrorat runtime. Handles bothx.toString(64)andx["toExponential"](22).Docs for these (and the rest of the bucket) are in denoland/docs#3378.
All three are tagged
recommended, matching oxc'scorrectnessclassification.As with #1521, this is the same on-by-default question — happy to drop the tag
and land them opt-in first if you prefer.