Skip to content

Codebase quality improvements: validation, type safety, DRY, and CLI enhancements#5

Open
levifig wants to merge 7 commits intonumman-ali:mainfrom
levifig:codebase-improvements
Open

Codebase quality improvements: validation, type safety, DRY, and CLI enhancements#5
levifig wants to merge 7 commits intonumman-ali:mainfrom
levifig:codebase-improvements

Conversation

@levifig
Copy link

@levifig levifig commented Dec 26, 2025

Note: This PR depends on #4 and should be merged after it.

Summary

A collection of code quality improvements addressing bugs, type safety, DRY violations, and CLI usability.

Changes

Bug Fixes

  • Year validation: Validate --year parameter to prevent crashes on invalid input (e.g., --year abc)
  • Schema validation: Add basic validation for stats-cache.json before parsing

Type Safety

  • Replace any types with Record<string, unknown> in collector
  • Add proper type narrowing for JSON parsing

Code Quality (DRY)

  • Consolidate 3 duplicate formatDateKey() functions into single source in utils/dates.ts

CLI Enhancements

  • Add --verbose / -V flag to show debug info (config path, session/message counts)
  • Add --output / -o flag to specify image save location (skips interactive prompt)
  • Improve error messages with better context

Testing

  • TypeScript compiles without errors
  • --help shows all new options
  • --year invalid shows helpful error
  • --verbose displays config path and stats summary
  • --output ~/test.png saves directly without prompting

- Add support for XDG-compliant ~/.config/claude path
- Check ~/.config/claude first, fall back to ~/.claude
- Add --config-dir/-c CLI option to override config path
- Remove unused xdg-basedir dependency
- Check for NaN from invalid input
- Enforce range: 2024 to current year
- Show helpful error message with valid range
- Add type guard isValidStatsCache()
- Validate parsed JSON before returning
- Throw descriptive error on invalid format
- Use explicit unknown type for JSON parsing
- Add type narrowing for timestamp validation
- Cast message and usage objects explicitly
- Improves type safety without changing behavior
- Remove duplicate from collector.ts
- Remove duplicate from stats.ts
- Import from utils/dates.ts (single source of truth)
- Export resolveClaudeDataPath() from collector
- Add -V/--verbose CLI option
- Show config directory path when verbose
- Show sessions/messages/projects summary when verbose
- Improve error message formatting
- Add -o/--output CLI option to specify save location
- Skip interactive prompt when --output is provided
- Improve error message formatting for save failures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant