Skip to content
Closed
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
19 changes: 19 additions & 0 deletions scratch/reviewbot-unified-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Small numeric helpers.

/** Clamp a percentage into the 0–100 range. */
export function clampPercent(value: number): number {
if (value > 100) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue · Missing lower bound clamp

clampPercent only caps values above 100 but does not prevent negative percentages from being returned.

Suggested change
if (value > 100) {
if (value < 0) { return 0; }
🤖 Prompt for AI agents
In scratch/reviewbot-unified-demo.ts around line 5, `clampPercent` only caps values above 100 but does not prevent negative percentages from being returned. Apply: if (value < 0) { return 0; }

return 100;
}
return value;
}

/** Return the average of the numbers. */
export function average(values: number[]): number {
return values.reduce((a, b) => a + b, 0) / values.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue · Division by zero on empty array

average divides by values.length without checking for an empty array, yielding NaN.

Suggested change
return values.reduce((a, b) => a + b, 0) / values.length;
if (values.length === 0) { return 0; }
🤖 Prompt for AI agents
In scratch/reviewbot-unified-demo.ts around line 13, `average` divides by `values.length` without checking for an empty array, yielding NaN. Apply: if (values.length === 0) { return 0; }

}

/** Parse a port number from a string, defaulting to 8080. */
export function parsePort(raw: string): number {
return parseInt(raw) || 8080;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick · Port validation

parsePort returns any numeric value, including negatives or >65535, which are invalid ports.

Suggested change
return parseInt(raw) || 8080;
const port = parseInt(raw); return (port > 0 && port <= 65535) ? port : 8080;
🤖 Prompt for AI agents
In scratch/reviewbot-unified-demo.ts around line 18, `parsePort` returns any numeric value, including negatives or >65535, which are invalid ports. Apply: const port = parseInt(raw); return (port > 0 && port <= 65535) ? port : 8080;

}