S6: Explicit undefined passed to formatSI optional param #11

Open
opened 2026-06-05 10:22:13 +00:00 by sebse · 0 comments
Owner

Code Smell

File: web/components/ChartCard/TableViz.tsx:67

{vals.green != null ? formatSI(vals.green, undefined, 0) : --}

The second argument undefined is explicit where the parameter is already optional:

function formatSI(v: number, locale?: string, fractionDigits?: number): string;

Why it matters

Passing undefined explicitly where optional suffices is redundant. TypeScript will pass undefined for missing optional params anyway.

Suggestion

{vals.green != null ? formatSI(vals.green, 0) : --}

Or use default parameter: formatSI(vals.green, undefined, 0)formatSI(vals.green, 0). Note: this swaps locale and fractionDigits positions — the current call is already correct because locale is second param. Actually the fix is to remove the undefined:

formatSI(vals.green, undefined, 0)  // current
formatSI(vals.green, 0)             // wrong — 0 would be locale, not fractionDigits

This is minor and the current code is technically fine. The smell is semantic only.

## Code Smell **File:** `web/components/ChartCard/TableViz.tsx:67` ```tsx {vals.green != null ? formatSI(vals.green, undefined, 0) : --} ``` The second argument `undefined` is explicit where the parameter is already optional: ```ts function formatSI(v: number, locale?: string, fractionDigits?: number): string; ``` ### Why it matters Passing `undefined` explicitly where optional suffices is redundant. TypeScript will pass `undefined` for missing optional params anyway. ### Suggestion ```tsx {vals.green != null ? formatSI(vals.green, 0) : --} ``` Or use default parameter: `formatSI(vals.green, undefined, 0)` → `formatSI(vals.green, 0)`. Note: this swaps locale and fractionDigits positions — the current call is already correct because locale is second param. Actually the fix is to remove the undefined: ```tsx formatSI(vals.green, undefined, 0) // current formatSI(vals.green, 0) // wrong — 0 would be locale, not fractionDigits ``` This is minor and the current code is technically fine. The smell is semantic only.
sebse added the code-smell label 2026-06-05 10:22:13 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sebse/factorio-signal-exporter#11