Skip to content

fix(color): correct LCH hue range and HSLA alpha formatting - #3955

Open
pouyashahrdami wants to merge 1 commit into
faker-js:nextfrom
pouyashahrdami:fix/color-lch-hue-and-hsla-alpha
Open

fix(color): correct LCH hue range and HSLA alpha formatting#3955
pouyashahrdami wants to merge 1 commit into
faker-js:nextfrom
pouyashahrdami:fix/color-lch-hue-and-hsla-alpha

Conversation

@pouyashahrdami

@pouyashahrdami pouyashahrdami commented Jul 16, 2026

Copy link
Copy Markdown

Summary

  • LCH hue capped at 230 instead of 360: The lch() method used a loop to generate both chroma and hue with max: 230. Chroma's upper bound of 230 is correct (as documented), but hue is an angle in degrees and should range 0–360. This meant ~36% of the hue circle (blues, purples, magentas above 230°) could never be generated.

  • HSLA CSS alpha scaled incorrectly: The toCSS() helper passed the HSLA alpha value through toPercentage(), which multiplies by 100. An alpha of 0.75 was output as 75 instead of 0.75 in the CSS string. The JSDoc example shows the correct format (hsl(0deg 100% 50% / 0.5)) but the code produced hsl(0deg 100% 50% / 50). Compare with RGBA (line 127) which correctly passes alpha through as-is.

Test plan

  • Updated LCH decimal-format tests to assert per-component bounds (chroma ≤ 230, hue ≤ 360) instead of a blanket ≤ 230 loop
  • Updated seeded snapshots to reflect new LCH hue values
  • All 236 color module tests pass

@pouyashahrdami
pouyashahrdami requested a review from a team as a code owner July 16, 2026 23:48
@netlify

netlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deploy Preview for fakerjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2be752d
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/6a596e1cba837400083268a1
😎 Deploy Preview https://deploy-preview-3955.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

The LCH hue component was generated with max 230 (sharing the chroma
bound) instead of 360, cutting off ~36% of the hue circle. The HSLA CSS
output passed the alpha value through toPercentage(), producing e.g. 75
instead of 0.75.
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.85%. Comparing base (9ce88ce) to head (2be752d).
⚠️ Report is 4 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3955      +/-   ##
==========================================
- Coverage   98.91%   98.85%   -0.07%     
==========================================
  Files         923      923              
  Lines        3223     3221       -2     
  Branches      567      585      +18     
==========================================
- Hits         3188     3184       -4     
- Misses         31       33       +2     
  Partials        4        4              
Files with missing lines Coverage Δ
src/modules/color/module.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 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.

@ST-DDT
ST-DDT requested a review from Copilot July 17, 2026 06:27
@ST-DDT ST-DDT added c: bug Something isn't working p: 1-normal Nothing urgent s: pending triage Pending Triage m: color Something is referring to the color module labels Jul 17, 2026
@ST-DDT ST-DDT added this to the v10.x milestone Jul 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes two correctness issues in the color module’s formatting and value generation: it expands LCH hue generation to cover the full 0–360° range, and corrects HSLA CSS alpha output to remain a 0–1 value (rather than being incorrectly scaled to 0–100).

Changes:

  • Fix HSLA CSS formatting by outputting alpha as-is instead of converting it to a percentage.
  • Fix lch() generation to cap chroma at 230 while allowing hue up to 360 (instead of incorrectly capping both at 230).
  • Update LCH tests and seeded snapshots to reflect the corrected hue range.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/modules/color/module.ts Corrects HSLA CSS alpha formatting and fixes LCH hue generation bounds.
test/modules/color.spec.ts Updates LCH decimal-format assertions to validate per-component bounds (including hue ≤ 360).
test/modules/__snapshots__/color.spec.ts.snap Refreshes seeded LCH snapshots to reflect newly reachable hue values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

0.37454,
218.7,
168.4,
263.5,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder why hsla doesnt show up as changed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add test for hsla format.

@ST-DDT

ST-DDT commented Jul 17, 2026

Copy link
Copy Markdown
Member

This fixes two unrelated bugs in two unrelated methods. For ease of review+changelog, please only fix related bugs within the same PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: bug Something isn't working m: color Something is referring to the color module p: 1-normal Nothing urgent s: pending triage Pending Triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(color): LCH hue range capped at 230 instead of 360, HSLA alpha incorrectly scaled

3 participants