Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/forms-and-validation/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class FormsExampleApp extends Widget {
return false; // Quit
}

if (event.key === 'c' && event.ctrl === false) {
if (event.key === 'c' && event.ctrl !) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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."
fi

Repository: 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"
fi

Repository: 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
fi

Repository: 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.

Suggested change
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

this.modal.show();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/showcase/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ShowcaseApp extends Widget {
if (event.key === 'q' || (event.ctrl && event.key === 'c')) return false;

// Tab switching: 1-5
const num = parseInt(event.key);
const num = parseInt(event.key, 10);
if (num >= 1 && num <= 5) {
this.switchTab(num - 1);
return true;
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,5 @@ export class Form extends Widget {
}
}
}

.catch(err => console.error("Promise.all failed:", err));
Comment on lines +141 to +142

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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"
fi

Repository: 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

Loading