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 | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

file="examples/forms-and-validation/src/index.tsx"

if rg -nP "event\.key === 'c' && event\.ctrl\s*!" "$file"; then
  echo "Incorrect postfix assertion remains"
  exit 1
fi

rg -nF "event.key === 'c' && !event.ctrl" "$file"

Repository: Karanjot786/TermUI

Length of output: 245


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

file="examples/forms-and-validation/src/index.tsx"
sed -n '100,140p' "$file" | cat -n

echo "--- TypeScript parser behavior for event.ctrl ! vs !event.ctrl ---"
node - <<'JS'
const exprs = ["event.ctrl !", "!event.ctrl"];
for (const expr of exprs) {
  try {
    const ast = parser = new Function("");
  } catch { }
}
console.log("Node is not needed; use TypeScript parser semantics:", {
  "event.ctrl !": "postfix non-null assertion expression equals event.ctrl",
  "!event.ctrl": "logical not of event.ctrl"
});
JS

# Use a read-only behavior probe that parses representative TypeScript snippets without running repo code.
node - <<'JS'
const ts = require.resolve('typescript');
const tsx = require(ts);
const samples = [
  { code: "if (x && event.ctrl !) {}", title: "event.ctrl !" },
  { code: "if (x && !event.ctrl) {}", title: "!event.ctrl" },
];
for (const {code, title} of samples) {
  const sf = tsx.createSourceFile('probe.ts', code, tsx.ScriptTarget.Latest, true, tsx.ScriptKind.TS);
  const cond = sf.statements[0].expression;
  console.log(title, {
    leftOperator: cond.operator,
    right: cond.right.getText(sf),
    rightOperator: cond.right.operator,
    rightArgumentsLength: cond.right.arguments?.length || 0
  });
}
JS

Repository: Karanjot786/TermUI

Length of output: 2792


Use prefix negation for event.ctrl.

event.ctrl ! is a postfix non-null assertion, so it still only checks whether Control is pressed. Use !event.ctrl to open the confirmation modal on plain c while keeping Ctrl+C handled by the quit branch.

Proposed fix
-        if (event.key === 'c' && event.ctrl !) {
+        if (event.key === 'c' && !event.ctrl) {
📝 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) {
🤖 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
condition in the keyboard event handler to use prefix negation for event.ctrl,
so the confirmation modal opens for plain “c” while Ctrl+C remains handled by
the quit branch.

Source: Coding guidelines

this.modal.show();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/weather/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async function fetchWeather() {
}
}

setInterval(fetchWeather, 5000);
clearInterval(window.__interval); window.__interval = setInterval(fetchWeather, 5000);
fetchWeather();

// Gauge does not expose a public setColor() method, so dynamic color
Expand Down
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);
const sortedB = [...b].sort();
Comment on lines +185 to 186

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

rg -n -C 5 '_valuesEqual|sort\(' packages/ui/src/TreeSelect.ts

while IFS= read -r tsconfig; do
  npx tsc --noEmit --pretty false -p "$tsconfig"
done < <(fd -HI '^tsconfig(\..*)?\.json$' .)

Repository: Karanjot786/TermUI

Length of output: 947


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'List TS config files:\n'
fd -HI '^tsconfig(\..*)?\.json$' . || true

printf '\nTreeSelect excerpt:\n'
sed -n '160,195p' packages/ui/src/TreeSelect.ts

printf '\nCheck TypeScript availability:\n'
npm exec -- tsc -v || true

printf '\nPackages UI tsconfig references:\n'
find . -path '*packages/ui*' -name 'tsconfig*.json' -print -exec sed -n '1,220p' {} \;

printf '\nRun TypeScript check for packages/ui/src/TreeSelect.ts with available config:\n'
for tsconfig in $(fd -HI '^tsconfig(\..*)?\.json$' .); do
  echo "--- $tsconfig ---"
  npx tsc --noEmit --pretty false -p "$tsconfig" 2>&1 | awk '/packages\/ui\/src\/TreeSelect\.ts/ || /TS2362/ || /Found [0-9]+ error/'
done

Repository: Karanjot786/TermUI

Length of output: 4472


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '--- packages/ui/tsconfig.json ---\n'
cat packages/ui/tsconfig.json

printf '\n--- packages/ui/tsconfig.typecheck.json ---\n'
cat packages/ui/tsconfig.typecheck.json

printf '\n--- packages/ui/src/tsconfig related files ---\n'
fd -HI '^tsconfig(\..*)?\.json$' packages/ui/src || true

printf '\n--- Check all TS config files for TS2362/Node errors involving TreeSelect.ts ---\n'
for tsconfig in $(fd -HI '^tsconfig(\..*)?\.json$' .); do
  echo "### $tsconfig"
  output="$(npx tsc --noEmit --pretty false -p "$tsconfig" 2>&1 || true)"
  if printf '%s\n' "$output" | grep -E 'packages/ui/src/TreeSelect\.ts|TS2362|Found [0-9]+ error' >/dev/null 2>&1; then
    printf '%s\n' "$output" | grep -E 'packages/ui/src/TreeSelect\.ts|TS2362|Found [0-9]+ error' -C 2 || true
  else
    echo "no TreeSelect TS2362 errors reported"
  fi
done

Repository: Karanjot786/TermUI

Length of output: 247


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- packages/ui/tsconfig.json ---'
cat packages/ui/tsconfig.json

printf '\n--- packages/ui/tsconfig.typecheck.json ---\n'
cat packages/ui/tsconfig.typecheck.json

printf '%s\n' '--- packages/ui/src/tsconfig related files ---'
fd -HI '^tsconfig(\..*)?\.json$' packages/ui/src || true

printf '\n--- Check all TS config files for TS2362/Node errors involving TreeSelect.ts ---\n'
for tsconfig in $(fd -HI '^tsconfig(\..*)?\.json$' .); do
  printf '%s\n' "### $tsconfig"
  output="$(npx tsc --noEmit --pretty false -p "$tsconfig" 2>&1 || true)"
  if printf '%s\n' "$output" | grep -E 'packages/ui/src/TreeSelect\.ts|TS2362|Found [0-9]+ error' >/dev/null 2>&1; then
    printf '%s\n' "$output" | grep -E 'packages/ui/src/TreeSelect\.ts|TS2362|Found [0-9]+ error' -C 2 || true
  else
    printf '%s\n' "no TreeSelect TS2362 errors reported"
  fi
done

Repository: Karanjot786/TermUI

Length of output: 10719


Use one typed comparator for both sorted arrays.

_valuesEqual sorts each array independently before comparing it. Use the same comparator for sortedA and sortedB so equal string permutations do not compare as different. A local typed comparator also avoids string subtraction in strict TypeScript.

Proposed fix
-    const sortedA = [...a].sort((a, b) => a - b);
-    const sortedB = [...b].sort();
+    const compareValues = (left: string, right: string): number => {
+        const leftNumber = Number(left);
+        const rightNumber = Number(right);
+        if (Number.isFinite(leftNumber) && Number.isFinite(rightNumber)) {
+            return leftNumber - rightNumber;
+        }
+        return left.localeCompare(right);
+    };
+    const sortedA = [...a].sort(compareValues);
+    const sortedB = [...b].sort(compareValues);
📝 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
const sortedA = [...a].sort((a, b) => a - b);
const sortedB = [...b].sort();
const compareValues = (left: string, right: string): number => {
const leftNumber = Number(left);
const rightNumber = Number(right);
if (Number.isFinite(leftNumber) && Number.isFinite(rightNumber)) {
return leftNumber - rightNumber;
}
return left.localeCompare(right);
};
const sortedA = [...a].sort(compareValues);
const sortedB = [...b].sort(compareValues);
🧰 Tools
🪛 GitHub Actions: CI / 0_build-and-test.txt

[error] 185-185: TypeScript errors TS2362 and TS2363: the operands of an arithmetic operation are not typed as any, number, bigint, or an enum. The @termuijs/ui DTS build failed during 'tsup' / 'bun run build' with exit code 1.

🪛 GitHub Actions: CI / build-and-test

[error] 185-185: TypeScript error TS2362: The left-hand side of an arithmetic operation must be a number-compatible type.


[error] 185-185: TypeScript error TS2363: The right-hand side of an arithmetic operation must be a number-compatible type.

🤖 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` around lines 185 - 186, Update _valuesEqual so
sortedA and sortedB both use the same local typed comparator suitable for the
array element type; remove numeric subtraction and the comparator-less sort,
ensuring equal string permutations are ordered identically before comparison.

Source: Coding guidelines

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