Skip to content

fix(color): return a stable name for colors with aliases - #1218

Open
ChandraChaan wants to merge 2 commits into
gdamore:mainfrom
ChandraChaan:fix/color-name-alias-order
Open

ChandraChaan wants to merge 2 commits into
gdamore:mainfrom
ChandraChaan:fix/color-name-alias-order

Conversation

@ChandraChaan

@ChandraChaan ChandraChaan commented Nov 3, 2026 •

Copy link
Copy Markdown

Color.Name() (and so String()) loops over the Names map and returns the first match. Go randomises map iteration, and seven colors have two names (gray/grey, darkgray/darkgrey, darkslategray/darkslategrey, dimgray/dimgrey, lightgray/lightgrey, lightslategray/lightslategrey, slategray/slategrey), so the same color can print as "gray" or "grey" from one call or run to the next.

This picks the alphabetically first matching name, so those colors always come back with the "gray" spelling.

I added TestColorNameAliases, which checks Name() and String() for all seven colors 200 times each.

Verified in CI on my fork, since I did not run Go locally:

Summary by CodeRabbit

  • Bug Fixes
    • Color names are now consistent when multiple names represent the same color, with the alphabetically first matching name selected. CSS fallback behavior is unchanged.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Color.Name now returns the alphabetically first name when multiple names match a color. Tests verify consistent names for gray-family aliases through Name() and String().

Changes: Color name selection

Layer / File(s) Summary
Select and verify alias names
color/color.go, color/color_test.go
Color.Name scans matching names and selects the alphabetically first. Tests check the expected gray-family names through Name() and String() over 200 iterations per color.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: Minimal · up to a126b

The change provides deterministic color names for aliases without an identified merge-blocking risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(color): return a stable name for colors with aliases" matches the main change. Color.Name now returns the alphabetically first matching name when several names map to the same color, in…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(color): return a stable name for colors with aliases" matches the main change. Color.Name now returns the alphabetically first matching name when several names map to the same color, instead of depending on map iteration order. The added TestColorNameAliases checks that the gray/grey aliases return a consistent canonical name from Name() and String(). The title is specific, concise, and uses a conventional type prefix.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/c/security/file-access-before-action-c.yml

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c9adbb80-bc35-4761-98cb-e5790cda18ec
Commits

Reviewing files that changed from the base of the PR and between d3a071c and a126b6b.

Files selected for processing: 2
  • color/color.go
  • color/color_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@ossenthusiast

Copy link
Copy Markdown

@gdamore gdamore left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good. I wonder if we should not just build this as a map for the reverse lookup -- although the reality is that I would not expect this interface to be heavily used.

@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.04%. Comparing base (d3a071c) to head (a126b6b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1218   +/-   ##
=======================================
  Coverage   92.04%   92.04%           
=======================================
  Files          49       49           
  Lines        6145     6148    +3     
=======================================
+ Hits         5656     5659    +3     
  Misses        472      472           
  Partials       17       17           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ChandraChaan

Copy link
Copy Markdown
Author

Thanks for the review. A reverse map would make Name() a lookup, but it would have to be built at init time and kept in sync with Names, and I agree Name() is unlikely to be called often. I'd keep the small scan with the alphabetical tiebreak here, but I'm happy to change it if you prefer the map.

@ChandraChaan

Copy link
Copy Markdown
Author

Hi @gdamore, a gentle ping on this one: it's approved and all checks pass. Is it good to merge with the scan as is, or would you like me to switch Name() to the reverse map first? Happy to do either.

This branch has not been deployed

No deployments
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.

3 participants