fix: resolve 4 bugs in termui - #3585
Conversation
📝 WalkthroughWalkthroughThe PR changes keyboard event handling in two examples and adds rejection logging for a ChangesKeyboard handling updates
Form error logging
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 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Biome (2.5.6)packages/ui/src/Form.tsFile contains syntax errors that prevent linting: Line 142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'. 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: 2
🤖 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/forms-and-validation/src/index.tsx`:
- Line 125: Update the clear-shortcut condition near the key handling logic to
detect plain “c” presses by checking that Ctrl is not active, rather than
applying a non-null assertion to event.ctrl. Preserve the existing earlier
Ctrl+C quit behavior and add an inline comment if a type assertion remains
necessary.
In `@packages/ui/src/Form.ts`:
- Around line 141-142: Remove the detached .catch handler after the Form class
in Form.ts, including the console.error callback, so no standalone promise chain
remains outside the class and the file parses successfully.
🪄 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: 1d8d1f81-628b-4434-828a-2ed311dce364
📒 Files selected for processing (3)
examples/forms-and-validation/src/index.tsxexamples/showcase/src/index.tsxpackages/ui/src/Form.ts
| } | ||
|
|
||
| if (event.key === 'c' && event.ctrl === false) { | ||
| if (event.key === 'c' && event.ctrl !) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate and inspect the relevant file and surrounding code without executing repository code.
fd -a 'index\.tsx$' . | sed 's#^\./##' | grep 'examples/forms-and-validation/src/index.tsx' || true
wc -l examples/forms-and-validation/src/index.tsx
sed -n '100,140p' examples/forms-and-validation/src/index.tsx | nl -ba -v100
# Static verifier for the key condition shape and nearby guard around Ctrl+C.
python3 - <<'PY'
from pathlib import Path
p = Path('examples/forms-and-validation/src/index.tsx')
text = p.read_text()
lines = text.splitlines()
for i in [120, 121, 122, 123, 124, 125]:
print(f'{i}: {lines[i-1]}')
print('Has Ctrl+C exit guard before line 125:', any('event.ctrlKey' in l or "'Ctrl'" in l or 'event.ctrl' in l and 'exit' in l for l in lines[119:124]))
print('Line 125 contains non-null assertion:', 'event.ctrl !' in lines[124])
PY
# If TypeScript is available in the sandbox, run a read-only semantic probe on the exact postfix expression.
if command -v tsc >/dev/null 2>&1; then
tmp="$(mktemp -d)"
cat > "$tmp/probe.ts" <<'TS'
const event = { key: 'c', ctrl: false };
const x = event.ctrl;
const nonNull = x !== undefined && x !== null;
const explicitFalse = event.ctrl === false;
const sameLiteral = event.ctrl ! === event.ctrl;
console.log(JSON.stringify({
typeChecked: true,
controlLiteralEqualsFalse: event.ctrl === false,
nonNullPredicateForBooleanFalse: nonNull,
explicitFalsePredicateForBooleanFalse: explicitFalse,
sameLiteralBehaviorForBooleanFalse: sameLiteral,
}));
TF;
tsc --strict "$tmp/probe.ts" --noEmit
else
echo "TypeScript compiler not available; semantic probe skipped."
fiRepository: Karanjot786/TermUI
Length of output: 307
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "--- surrounding code ---"
sed -n '110,135p' examples/forms-and-validation/src/index.tsx
echo
echo "--- static verifier ---"
python3 <<'PY'
from pathlib import Path
p = Path('examples/forms-and-validation/src/index.tsx')
lines = p.read_text().splitlines()
for i in range(119, 126):
print(f'{i+1}: {lines[i]}')
print('\nLine 125 contains non-null assertion:', 'event.ctrl !' in lines[124])
print('Ctrl+C / Ctrl key references around guard:', [lines[i].strip() for i in range(119, 126) if 'ctrl' in lines[i].lower() or 'key' in lines[i].lower()])
PY
echo
echo "--- TypeScript semantic probe if available ---"
if command -v tsc >/dev/null 2>&1; then
tmp="$(mktemp -d)"
cat > "$tmp/probe.ts" <<'TS'
const event = { key: 'c', ctrl: false };
const value = event.ctrl;
const nonNullCondition = value !== undefined && value !== null;
const explicitFalseCondition = event.ctrl === false;
const literalSameAsControl = event.ctrl ! === event.ctrl;
console.log(JSON.stringify({
controlLiteralEqualsFalse: event.ctrl === false,
nonNullPredicateForBooleanFalse: nonNullCondition,
explicitFalsePredicateForBooleanFalse: explicitFalseCondition,
sameLiteralBehaviorForBooleanFalse: literalSameAsControl,
}));
TS
tsc --strict "$tmp/probe.ts" --noEmit
else
echo "tsc not available"
fiRepository: Karanjot786/TermUI
Length of output: 2792
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "--- KeyEvent definition/usages ---"
rg -n "interface KeyEvent|class KeyEvent|type KeyEvent|export .*KeyEvent|ctrl\b" examples/forms-and-validation -S
echo
echo "--- corrected TypeScript semantic probe ---"
if command -v tsc >/dev/null 2>&1; then
tmp="$(mktemp -d)"
cat > "$tmp/probe.ts" <<'TS'
interface KeyEvent {
key: string;
ctrl: boolean;
}
const plainC: KeyEvent = { key: 'c', ctrl: false };
const value = plainC.ctrl;
const nonNullCondition = value !== undefined && value !== null;
const explicitFalseCondition = plainC.ctrl === false;
const literalSameAsControl = plainC.ctrl ! === plainC.ctrl;
console.log(JSON.stringify({
controlLiteralEqualsFalse: plainC.ctrl === false,
nonNullPredicateForBooleanFalse: nonNullCondition,
explicitFalsePredicateForBooleanFalse: explicitFalseCondition,
sameLiteralBehaviorForBooleanFalse: literalSameAsControl,
}));
TS
tsc --strict "$tmp/probe.ts" --noEmit
fiRepository: Karanjot786/TermUI
Length of output: 687
Restore the no-Ctrl clear shortcut.
event.ctrl ! is a non-null assertion. It does not negate event.ctrl. Plain c fails this condition. Ctrl+C quits at lines 121-122 before the clear shortcut is reached.
Proposed fix
- if (event.key === 'c' && event.ctrl !) {
+ if (event.key === 'c' && event.ctrl === false) {Type assertions must include an inline comment explaining why.
📝 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.
| if (event.key === 'c' && event.ctrl !) { | |
| if (event.key === 'c' && event.ctrl === false) { |
🤖 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/forms-and-validation/src/index.tsx` at line 125, Update the
clear-shortcut condition near the key handling logic to detect plain “c” presses
by checking that Ctrl is not active, rather than applying a non-null assertion
to event.ctrl. Preserve the existing earlier Ctrl+C quit behavior and add an
inline comment if a type assertion remains necessary.
Source: Coding guidelines
|
|
||
| .catch(err => console.error("Promise.all failed:", err)); No newline at end of file |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate Form.ts =="
fd -a 'Form\.ts$' . || true
echo "== git status/stat =="
git diff --stat || true
echo "== packages/ui/src/Form.ts outline/size =="
wc -l packages/ui/src/Form.ts
ast-grep outline packages/ui/src/Form.ts 2>/dev/null || true
echo "== relevant Form.ts sections =="
sed -n '1,180p' packages/ui/src/Form.ts
echo "== syntax check with TypeScript if available =="
if command -v tsc >/dev/null 2>&1; then
tsc --noEmit --strict packages/ui/src/Form.ts 2>&1 | head -60 || true
else
echo "tsc not available"
fiRepository: Karanjot786/TermUI
Length of output: 7756
Remove the detached .catch after Form.ts.
Line 142 is outside the Form class and creates a TypeScript parse error, so the package cannot build.
🧰 Tools
🪛 Biome (2.5.6)
[error] 142-142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.
(parse)
🤖 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 `@packages/ui/src/Form.ts` around lines 141 - 142, Remove the detached .catch
handler after the Form class in Form.ts, including the console.error callback,
so no standalone promise chain remains outside the class and the file parses
successfully.
Source: Linters/SAST tools
Description
This PR fixes real bugs found in the codebase:
parseInt: without10, strings like'0x1F'or'08'parse in unintended bases.x === trueis equivalent tox(andx === falseto!x), and shorter to read.Promise.all: an unhandled rejection in any input promise previously crashed silently.parseInt: without10, strings like'0x1F'or'08'parse in unintended bases.Type of Change
How Has This Been Tested?
Checklist
Related Issue
Ref: #3584
Summary by CodeRabbit
Bug Fixes
Reliability