Skip to content

P1B: Refactor (packages/ui/src/theme/color.ts): Complex binary expression - #183

Open
TiffanyLiu2029 wants to merge 2 commits into
CMU-313:mainfrom
TiffanyLiu2029:refactor-color-range-check
Open

P1B: Refactor (packages/ui/src/theme/color.ts): Complex binary expression#183
TiffanyLiu2029 wants to merge 2 commits into
CMU-313:mainfrom
TiffanyLiu2029:refactor-color-range-check

Conversation

@TiffanyLiu2029

@TiffanyLiu2029 TiffanyLiu2029 commented Sep 8, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #180

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR refactors the complex binary expression in fitOklch in packages/ui/src/theme/color.ts.

Previously, the code checked whether all three RGB values were between 0 and 1 using one long conditional expression. I split these checks into redInRange, greenInRange, and blueInRange variables and then check those variables together. This keeps the same behavior while making the condition easier to read and removing the targeted Qlty smell.

I also added tests for fitOklch to verify that an in-gamut color remains unchanged and that an out-of-gamut color has its chroma reduced.

How did you verify your code works?

I ran the tests for the UI package and confirmed that both new tests pass.

bun test src/theme/color.test.ts

Result:

  • 2 passed
  • 0 failed

I also ran coverage and confirmed that the changed portion of fitOklch is executed by the tests.

Qlty also no longer reports the targeted complex binary expression at the original line 120.

Screenshots / recordings

Before Qlty:

Screenshot 2026-09-07 at 10 48 39 PM

After Qlty:

Screenshot 2026-09-07 at 10 51 06 PM

Targeted lint for the changed file:

Screenshot 2026-09-07 at 11 24 57 PM

Test and coverage results:

Screenshot 2026-09-07 at 11 20 31 PM

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@TiffanyLiu2029 TiffanyLiu2029 changed the title packages/ui/src/theme/color.ts P1B: Refactor (packages/ui/src/theme/color.ts): Complex binary expression Sep 8, 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.

P1B: Refactor (packages/ui/src/theme/color.ts:120): Complex binary expression

1 participant