fix(format): fix table overflow when column count exceeds available width#576
fix(format): fix table overflow when column count exceeds available width#576
Conversation
…idth adjustToSum clips column widths using existing value thresholds, but when many columns have large headers and the screen is narrow, the minimum threshold times column count still exceeds the available width. Add a fallback to equal distribution (floor of 1 per column) when threshold clipping is insufficient. Also fix GreedyFrequencyStrategy remainder distribution to skip when remaining space is zero or negative (avoids subtracting width from a column when the initial allocation already exceeds available width). Fixes #575 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where tables with a large number of columns, such as Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a table formatting bug where a large number of columns could cause the output to overflow the screen width. The fix involves modifying adjustToSum to fall back to an equal distribution of column widths when the normal clipping mechanism fails, guaranteeing a minimum width of 1 for each column. A related change in width_strategy_greedy.go prevents negative remainders from being applied to column widths. The changes are accompanied by new test cases that cover these overflow scenarios. My review did not identify any issues with the proposed implementation.
Code Metrics Report📊 View detailed coverage report (available for 7 days)
Details | | main (88680c9) | #576 (fdae9e8) | +/- |
|---------------------|----------------|----------------|-------|
+ | Coverage | 70.8% | 70.8% | +0.0% |
| Files | 75 | 75 | 0 |
| Lines | 7007 | 7025 | +18 |
+ | Covered | 4967 | 4980 | +13 |
- | Code to Test Ratio | 1:1.3 | 1:1.3 | -0.1 |
| Code | 16274 | 16299 | +25 |
+ | Test | 21183 | 21212 | +29 |
- | Test Execution Time | 1m11s | 1m13s | +2s |Code coverage of files in pull request scope (90.1% → 89.2%)
Reported by octocov |
Summary
Fix table output overflowing screen width when column count is large (e.g.,
INFORMATION_SCHEMA.COLUMNSwith 20 columns). The root cause wasadjustToSumbeing unable to reduce column widths below the minimum unique header width threshold, leaving all columns at that floor even when their sum far exceeds the available width.Key Changes
adjustToSumwhen threshold clipping is insufficient. Each column gets at least width 1 to avoid zero-width columns that bypasstabwrap.Wrap. WhennumCols × 1 > limit, the 1-character overflow per column is unavoidable but minimal.remainder > 0check. Previously, whenapplyColumnFloorscaused total width to exceedavailableWidth, the negative remainder would subtract width from a column, creating a zero-width column that bypasses wrapping entirely.adjustToSumtest case for many-column overflow. AddINFORMATION_SCHEMA.COLUMNS-like test case toTestCalculateWidthwith total-width assertion that accounts for unavoidable overflow.Behavior at extreme widths
When
numCols × minColumnWidth + overhead > screenWidth(e.g., 20 columns at screenWidth=80), the table will overflow by at mostnumCols × minColumnWidth + overhead - screenWidthcharacters (1 char in the COLUMNS case). This is the minimum possible overflow — every column gets exactly 1 character of content width.Test Plan
make checkpassesTestAdjustToSum/many_columns_overflow_falls_back_to_equal_distributionverifies fallbackTestCalculateWidth/many_columns_like_INFORMATION_SCHEMA.COLUMNSverifies end-to-end at screenWidth=120Fixes #575