Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ratchet unicorn/prefer-number-coercion to error#296

Merged
twschiller merged 1 commit into
mainfrom
ratchet-unicorn-prefer-number-coercion
Jun 22, 2026
Merged

Ratchet unicorn/prefer-number-coercion to error#296
twschiller merged 1 commit into
mainfrom
ratchet-unicorn-prefer-number-coercion

Conversation

@twschiller

Copy link
Copy Markdown
Contributor

Part of the #279 unicorn ratchet (follow-up to #295, now merged).

This is the "needs care — not semantically equivalent" candidate (parseInt/parseFloatNumber()), so each of the 15 sites was verified individually rather than batch-autofixed.

Converted to Number() (13 sites — provably equivalent)

All read a bare numeric token, so whole-string coercion matches the leading-numeric parse exactly:

  • countdown-timer-redact.ts (66/67/69/80) — \d-anchored colon/unit regex captures (\d{1,3}, [0-5]\d, \d+).
  • hidden-text-strip.ts:
    • the px-stripped capture (-?\d+(?:\.\d+)?).
    • duration token capture (\d*\.?\d+) (unit is a separate group).
    • matrix()/matrix3d() components (browser-normalized unitless numbers; Number handles scientific notation identically).
    • rgb channels + alpha, guarded non-empty (\d+(?:\.\d+)?) / ([\d.]+); the Number.isNaN guard right below makes Number()'s stricter rejection intentional.
  • text-walk-shadow.property.test.tsdataset.index, always set via String(i).

Kept parseFloat behind a scoped disable (2 sites — semantics load-bearing)

In hidden-text-strip.ts, parseFloat's "parse the leading number, ignore the rest" is the point:

  • hasNonzeroDuration reads computed transition-duration/animation-duration, which carry a unit suffix ("0.5s", "150ms"). Number("0.5s") is NaN → every non-zero duration would read as zero and silently disable the hidden-text duration check.
  • opacity-0 check reads computed opacity, which comes back "" when unset (notably under jsdom). Number("") === 0 would flag and redact every such element; parseFloat("") is NaN, so only a genuine 0 matches.

Each carries an inline comment + eslint-disable-next-line … -- <reason>.

Verification

  • bun run check clean (biome + tsc + eslint, exit 0); unicorn/prefer-number-coercion now error with 0 violations.
  • Full suite: 2059 tests pass (incl. the hidden-text-strip / countdown / shadow-walk property tests).

🤖 Generated with Claude Code

`Number()` replaces `parseInt(x, 10)` / `parseFloat(x)` at the 13 sites
where the input is a bare numeric token — `\d`-anchored regex captures
(timer colon/unit groups, the `px`-stripped length, duration tokens, rgb
channels and alpha) and a `String(i)` dataset index — so the whole-string
coercion is exactly equivalent.

Two sites in hidden-text-strip.ts keep `parseFloat` behind a scoped
disable, because its leading-numeric parse is load-bearing:
- `hasNonzeroDuration` reads computed `transition`/`animation-duration`,
  which carry a unit suffix (`"0.5s"`); `Number("0.5s")` is `NaN`, which
  would make every non-zero duration read as zero and disable the check.
- the `opacity-0` test reads computed `opacity`, which is `""` when unset
  (notably under jsdom); `Number("") === 0` would flag and redact every
  such element, whereas `parseFloat("")` is `NaN`.

Full suite (2059 tests) green; `bun run check` clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-browser-shield-demo-site Ready Ready Preview, Comment Jun 22, 2026 2:44pm

Request Review

@twschiller twschiller merged commit f361caa into main Jun 22, 2026
7 checks passed
@twschiller twschiller deleted the ratchet-unicorn-prefer-number-coercion branch June 22, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant