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/calculator/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function safeEval(expr: string): string {
if (tokens.length === 0) return '0';

// Handle initial negative number
if (tokens[0] === '-' && tokens.length > 1 && !isNaN(Number(tokens[1]))) {
if (tokens[0] === '-' && tokens.length > 1 && !Number.isNaN(Number(tokens[1]))) {
tokens.splice(0, 2, '-' + tokens[1]);
}

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

Fix the invalid .catch expression before merging.

Promise.all is awaited at Line 83, but .catch starts as a separate statement at Lines 141-142. This is invalid TypeScript, and Biome reports a parse error.

Attach the handler directly to the promise or wrap Line 83 in try/catch. On rejection, reset _isValidating and call markDirty() before returning; otherwise Lines 92 and 97 are skipped and the form can remain stuck in validation.

🧰 Tools
🪛 Biome (2.5.6)

[error] 142-142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.

(parse)

🪛 GitHub Actions: CI / 0_build-and-test.txt

[error] 142-142: The @termuijs/ui build failed during tsup/esbuild: unexpected '.' at .catch(err => console.error("Promise.all failed:", err));. TypeScript also reported malformed syntax (TS1128, TS1005, and TS2304).

🪛 GitHub Actions: CI / build-and-test

[error] 142-142: @termuijs/ui build failed during tsup/esbuild: unexpected '.' at '.catch(err => console.error("Promise.all failed:", err));'. TypeScript also reports syntax errors (TS1128, TS1005, TS2304).

🤖 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, Fix the validation flow
around the awaited Promise.all and the trailing catch expression: attach
rejection handling directly to the promise or wrap the await in try/catch. On
rejection, reset _isValidating, call markDirty(), and return so the form cannot
remain stuck when validation fails.

Source: Linters/SAST tools

2 changes: 1 addition & 1 deletion packages/ui/src/TreeSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function _pathsEqual(a: number[], b: number[]): boolean {

function _valuesEqual(a: string[], b: string[]): boolean {
if (a.length !== b.length) return false;
const sortedA = [...a].sort();
const sortedA = [...a].sort((a, b) => a - b);

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

rg -n -C 5 '_valuesEqual|sortedA|sortedB|node\.value|selectedValues' \
  packages/ui/src/TreeSelect.ts packages/ui/src/TreeSelect.test.ts

fd -H 'tsconfig*.json' . --exec rg -n '"strict"\s*:\s*true' {}

Repository: Karanjot786/TermUI

Length of output: 7492


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "## package.json scripts / dependencies relevant to type checking"
python3 - <<'PY'
import json
from pathlib import Path
for p in [Path('package.json'), Path('packages/ui/package.json')]:
    if p.exists():
        data=json.loads(p.read_text())
        print(f"--- {p} ---")
        print(json.dumps({'scripts': data.get('scripts'), 'devDependencies': data.get('devDependencies'), 'dependencies': data.get('dependencies')}, indent=2, sort_keys=True))
PY

echo
echo "## TreeSelect root/root helpers"
sed -n '1,180p' packages/ui/src/TreeSelect.ts | cat -n

echo
echo "## TreeSelect tests around value content"
sed -n '1,130p' packages/ui/src/TreeSelect.test.ts | cat -n

echo
echo "## TypeScript availability and strict parameter subtraction check"
node - <<'JS'
try {
  require.resolve('typescript');
  console.log('typescript available');
} catch {
  console.log('typescript unavailable');
}
JS

Repository: Karanjot786/TermUI

Length of output: 12989


Use the same comparator for both value arrays.

_valuesEqual accepts arbitrary string[], and a - b is invalid in strict TypeScript. The same concern appears for the selectedValues contract, which is not limited to numeric strings. Use one string sort comparator for both arrays and handle non-numeric values consistently.


\

🤖 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/TreeSelect.ts` at line 185, Update _valuesEqual to use a
shared string comparator when sorting both value arrays, including
selectedValues, instead of numeric subtraction. Ensure arbitrary string values
are compared consistently and remain valid under strict TypeScript.

Source: Coding guidelines

const sortedB = [...b].sort();
for (let i = 0; i < sortedA.length; i++) {
if (sortedA[i] !== sortedB[i]) return false;
Expand Down
Loading