csscomb / csscomb.js

CSS coding style formatter
http://csscomb.com/
MIT License
3.29k stars 457 forks source link

Messing up RGBA in color shorthand #612

Open henriquebs12 opened 5 years ago

henriquebs12 commented 5 years ago

CSSComb doesn't recognize the RGBA format in hexadecimals. When using "color-shorthand": true, it will transform

#0000004d into #0004d

messing up the color itself.

jdalton commented 5 years ago

Thanks for the heads up @henriquebs12!

Would you be interested in attempting a PR fix for it? The bit to patch would likely be this.

henriquebs12 commented 5 years ago

I can't right now but I found some interesting notes.

CSSComb tries to detect the 6 bit hex format, and if so, it picks the first hex color of each RGB channel, making $1$1$2$2$3$3 into $1$2$3.

I found that the 8 bit hex format (with alfa) does accept a shorthand as well, but it's a little bit strict, because the last 2 hex are the alpha channel, and they must be the same in order to be shorhanded, which reduces drastically the number of possibilities. But it can be done as well, making

$1$1$2$2$3$3$A$A into $1$2$3$A.

The goal here is to add a new rule. If it is already in 3 or 4 bit, you skip it.

If it is 6 bit, treat the shorhand version as $1$2$3, and if it 8 bit, treat it like $1$2$3$A.

Hope it is helpful. https://stackoverflow.com/questions/7015302/css-hexadecimal-rgba

jdalton commented 5 years ago

@henriquebs12

Hope it is helpful.

Yes, very much so. Thank you!

henriquebs12 commented 5 years ago

Can you also please check my previous issue? Thanks.

https://github.com/csscomb/csscomb.js/issues/610