Fix sign spacing for channel values in CSS relative color syntax#19286
Closed
LeSingh1 wants to merge 2 commits into
Closed
Fix sign spacing for channel values in CSS relative color syntax#19286LeSingh1 wants to merge 2 commits into
LeSingh1 wants to merge 2 commits into
Conversation
In the CSS relative color syntax (e.g. `oklch(from red l c +130)`), a leading `+`/`-` on a channel value is a sign rather than a math operator. Printing a space after it (`+ 130`) changes the value, since the sign makes the channel relative instead of absolute. Detect relative color function groups (those starting with `from`) and keep the sign attached to the number.
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18320
In the CSS relative color syntax, a leading
+or-on a channel value is a sign, not a math operator. Prettier was inserting a space after it, which changes the meaning of the value because the sign makes the channel adjustment relative instead of absolute.Before this change:
was printed as:
The
+ 130and+130are not equivalent here, so the output was producing different CSS than the input.The comma-separated value group printer now detects relative color function groups (the ones that start with the
fromkeyword insidergb,hsl,hwb,lab,lch,oklab,oklch, orcolor) and keeps a sign that is directly attached to a number attached, instead of treating it as a binary operator. A+/-that is separated from the number by whitespace, or one that appears insidecalc(), is left untouched, so genuine math is still spaced normally.I added a fixture under
tests/format/css/color/relative-color-syntax.csscovering each relative color function plus acalc()channel to confirm normal math spacing is preserved. The existing legacycolor()adjuster snapshots are unchanged.