Skip to content

[task] Consolidate formatNumber() duplicate implementations #2675

@github-actions

Description

@github-actions

Objective

Consolidate two similar number formatting functions into a single shared implementation.

Context

Related to #2668 (Duplicate or Near-Duplicate Functions)

Currently there are two implementations with 90% code overlap:

  • pkg/cli/logs.go:1843-1883 (41 lines) - More sophisticated precision handling
  • pkg/console/render.go:542-566 (25 lines) - Simpler thresholds

Both format integers as human-readable strings (K/M/B suffixes) but use different precision logic.

Approach

  1. Consolidate into pkg/console/render.go as FormatNumber(n int) string
  2. Use the more sophisticated version from logs.go (better precision thresholds)
  3. Update logs.go to import from the console package
  4. Remove duplicate implementation from logs.go
  5. Ensure consistent number formatting across the entire application

Files to Modify

  • Primary: pkg/console/render.go
    • Replace existing formatNumberForDisplay() (lines 542-566) with enhanced version from logs.go
    • Export as FormatNumber()
  • Update: pkg/cli/logs.go
    • Remove formatNumber() function (lines 1843-1883)
    • Import and use console.FormatNumber()
    • Update all call sites
  • Update: Test files for both packages

Acceptance Criteria

  • Single FormatNumber() function exists in pkg/console/render.go
  • Function uses the sophisticated precision handling from logs.go
  • Function correctly formats: 0, <1000, 1K-999K, 1M-999M, 1B+
  • logs.go imports and uses console.FormatNumber()
  • All existing tests pass
  • Unit tests verify formatting for edge cases (0, 999, 1000, 1500, 999999, 1000000, etc.)
  • 25-40 lines of duplicate code removed

Estimated Effort

1 hour

Priority

P1 - High Impact (Quick Win)
Related to #2668

AI generated by Plan Command for #2668

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions