fix: resolve 4 bugs in termui - #3478
Conversation
📝 WalkthroughWalkthroughThe changes fix four small correctness issues: overlapping AI streaming intervals, floating-point rounding in todo percentages and switch positions, and decimal parsing for widget-gallery tab keys. ChangesCorrectness fixes
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/todo-app/src/index.ts`:
- Line 107: Update the percentage calculation at the pct assignment to scale
Number.EPSILON correctly: add it to value before multiplying by 100, or use an
equivalent epsilon scaled to the percentage value, so values such as 0.285 round
to 29.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c6e51e2a-7efc-4847-87c5-9333cd712bb9
📒 Files selected for processing (4)
examples/ai-streaming/src/index.tsxexamples/todo-app/src/index.tsexamples/widget-gallery/src/index.tspackages/ui/src/Switch.ts
| const filled = Math.round(barWidth * value); | ||
|
|
||
| const pct = Math.round(value * 100); | ||
| const pct = Math.round(value * 100 + Number.EPSILON); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
node <<'NODE'
const value = 0.285;
const current = Math.round(value * 100 + Number.EPSILON);
const fixed = Math.round((value + Number.EPSILON) * 100);
if (current !== 28 || fixed !== 29) process.exit(1);
console.log({ current, fixed });
NODERepository: Karanjot786/TermUI
Length of output: 183
Scale the epsilon before rounding the percentage.
value = 0.285 can round to 28 with the current code instead of the expected 29. Add the epsilon before multiplying, or apply a scaled epsilon after multiplication.
Proposed fix
- const pct = Math.round(value * 100 + Number.EPSILON);
+ const pct = Math.round((value + Number.EPSILON) * 100);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const pct = Math.round(value * 100 + Number.EPSILON); | |
| const pct = Math.round((value + Number.EPSILON) * 100); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@examples/todo-app/src/index.ts` at line 107, Update the percentage
calculation at the pct assignment to scale Number.EPSILON correctly: add it to
value before multiplying by 100, or use an equivalent epsilon scaled to the
percentage value, so values such as 0.285 round to 29.
Description
This PR fixes real bugs found in the codebase:
Number.EPSILONtoMath.round: prevents floating-point drift (e.g.1.005 * 100rounding to 100 instead of 101).Number.EPSILONtoMath.round: prevents floating-point drift (e.g.1.005 * 100rounding to 100 instead of 101).parseInt: without10, strings like'0x1F'or'08'parse in unintended bases.Type of Change
How Has This Been Tested?
Checklist
Related Issue
Ref: #3477
Summary by CodeRabbit