Skip to content

refactor: consolidate style helpers, Go idioms, remove dead code (#87 #88 #89)#91

Merged
yimsk merged 12 commits intodevelopfrom
feat/issue-87
Jan 3, 2026
Merged

refactor: consolidate style helpers, Go idioms, remove dead code (#87 #88 #89)#91
yimsk merged 12 commits intodevelopfrom
feat/issue-87

Conversation

@yimsk
Copy link
Copy Markdown
Contributor

@yimsk yimsk commented Jan 3, 2026

Summary

  • Extract ViewportState helper to eliminate viewport initialization boilerplate across 5 views
  • Add 25 style helper functions to internal/ui/theme.go (TitleStyle, SelectedStyle, BoxStyle, etc.)
  • Replace 154 inline style definitions with unified ui.XxxStyle() calls
  • Apply Go 1.21+/1.22+ idioms: max(), min(), cmp.Or(), slices.Collect(), range-over-int
  • Remove dead code: unused width/height fields, wrapper functions, orphaned helpers
  • Add comprehensive tests for all style helpers (25 new tests)

Changes

  • 43 files changed (+638 / -585 lines)
  • internal/ui/theme.go: 25 new style helpers with tests
  • internal/view/: ViewportState extraction, style consolidation
  • internal/render/: Remove redundant style wrappers
  • custom/: Update renders to use ui.XxxStyle() directly

Testing

  • task lint
  • task test
  • task build

Closes #87, #88, #89

yimsk added 12 commits January 3, 2026 13:44
#88 #89)

- Add ViewportState type to eliminate duplicated viewport init pattern (6 views)
- Add TitleStyle, SelectedStyle, TableHeaderStyle to theme.go
- Remove unnecessary getCloudWatchLogsClient wrapper in log-streams
- service_browser: use TableHeaderStyle() and SelectedStyle()
- use max()/min() builtins instead of if statements
- use range over int for loop modernization
- Add 6 new theme helpers: SectionStyle, HighlightStyle, BoldSuccessStyle,
  BoldDangerStyle, BoldWarningStyle, BoldPendingStyle
- Apply helpers across 8 view files for consistency
- Fix hardcoded #ff0000 color in exec_with_header.go
- Use max()/min() builtins in dashboard_view_panels.go
- Use range-over-int in dashboard_view.go and dashboard_view_panels.go
- Remove unused width/height fields from 5 view structs
- Apply DimStyle() across 11 locations
- Apply SuccessStyle/WarningStyle/DangerStyle where applicable
- Update tests to match field removal
@claude
Copy link
Copy Markdown

claude Bot commented Jan 3, 2026

Code Review: PR #91 - Refactor: Consolidate Style Helpers, Go Idioms, Remove Dead Code

Summary

This is an excellent refactoring PR that significantly improves code quality, maintainability, and consistency. The changes are well-structured, thoroughly tested, and demonstrate strong software engineering practices.


✅ Strengths

1. Code Quality & Best Practices

  • Style Consolidation: Extracting 25 style helpers into internal/ui/theme.go eliminates significant duplication and creates a single source of truth for UI styling
  • ViewportState Helper: The new helper eliminates repetitive viewport initialization boilerplate across 5+ views - excellent DRY principle application
  • String Utilities: New TruncateString() and TruncateOrPadString() helpers in internal/view/strings.go consolidate common string operations
  • Go 1.21+/1.22+ Idioms: Proper use of modern Go features like cmp.Or() for default values, max()/min() for bounds checking, and range-over-int where appropriate
  • Consistent Naming: Style functions follow clear naming conventions (XxxStyle(), BoldXxxStyle())

2. Dead Code Removal

  • Removed unused wrapper functions in internal/render/render.go (SuccessStyle, WarningStyle, DangerStyle, DimStyle were just forwarding to ui package)
  • Cleaned up unused fields and orphaned helpers
  • Removed redundant getCloudWatchLogsClient() wrapper

3. Test Coverage ⭐

  • Comprehensive testing: 25 new tests added for all style helper functions
  • All existing tests updated to use new ui.XxxStyle() pattern
  • The PR description confirms task lint, task test, and task build all pass ✅

4. Migration Consistency

  • Systematic migration across 43 files from inline styles to unified helpers
  • Consistent import pattern: adding internal/ui where needed
  • All custom renderers updated to use ui.XxxStyle() instead of render.XxxStyle()

🔍 Potential Issues & Suggestions

Minor Issues (Optional Improvements)

1. Potential Performance Consideration
Style objects are created on every call rather than cached. In hot rendering loops, this could add allocation pressure. Consider caching styles (similar to how DefaultDetailStyles() caches in internal/render/detail.go:42-43) if profiling shows this as a bottleneck.

However, since lipgloss.Style is lightweight and this passes existing performance tests, this optimization may not be necessary.

2. Test Coverage - Could Be More Thorough
Tests only verify that styles produce non-empty output, but don't verify the actual styling properties (bold, foreground color, etc.). Consider adding property assertions in future iterations.

That said, since lipgloss styles are primarily visual and the existing smoke tests verify basic functionality, this is acceptable.

3. ViewportState Naming
Minor stylistic inconsistency: the new helper uses abbreviated field name vp ViewportState while other similar state uses fuller names like headerPanel. Low impact.


🔒 Security Assessment

No security concerns identified.

  • Changes are purely refactoring/organizational
  • No new external inputs, credential handling, or network operations
  • Dead code removal actually reduces attack surface slightly

⚡ Performance Considerations

Overall: Neutral to Positive

  • ✅ Dead code removal reduces binary size and cognitive overhead
  • ✅ Consolidated helpers may enable better compiler optimization
  • ⚠️ Style object allocation on every call (see issue インストール方法の用意 #1 above) - monitor if needed
  • ✅ ViewportState helper doesn't change performance characteristics

📊 Test Coverage

Excellent

  • 25 new tests for style helpers (100% coverage of new functions)
  • 7 test files modified to use new patterns
  • Existing tests updated and passing

🎯 Recommendations

Required: None

This PR is ready to merge as-is.

Optional Improvements (Future PRs):

  1. Cache style objects if profiling shows allocation pressure in rendering hot paths
  2. Enhance test assertions to verify style properties (bold, colors) rather than just non-empty output
  3. Document theme customization in theme.go

Final Verdict

LGTM 🚀 - Approve with enthusiasm

This PR demonstrates:

  • Strong understanding of Go idioms and best practices
  • Excellent refactoring discipline (consolidate, test, migrate systematically)
  • Attention to detail (43 files changed with consistency)
  • Proper testing (25 new tests)
  • Clear documentation (excellent PR description)

The code is cleaner, more maintainable, and adheres to DRY principles. The migration from inline styles to consolidated helpers will make future UI changes much easier. The adoption of modern Go idioms demonstrates keeping the codebase current.

Changes close issues #87, #88, #89 as stated.

Great work! 👏

@yimsk yimsk merged commit 9b9097c into develop Jan 3, 2026
5 checks passed
@yimsk yimsk deleted the feat/issue-87 branch January 3, 2026 17:28
@yimsk yimsk mentioned this pull request Jan 3, 2026
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