postcss / postcss-calc

PostCSS plugin to reduce calc()
MIT License
215 stars 33 forks source link

Calc returns 0px, but expected to be 0 with no units #92

Closed hawckins closed 1 year ago

hawckins commented 5 years ago

We have a stylelint "length-zero-no-unit":true enabled so 0 values should not have units associated to it. But calc is returning 0 with units for example calc(2px * 0); is returning as 0px but if zero we need just 0 not 0px. Is there any option which I can enable to get this?

alexander-akait commented 5 years ago

How it is related to postcss-calc?

alexander-akait commented 5 years ago

Also length-zero-no-unit is ignored calc in new version of stylelint, because it was bug, please update stylelint

tannerdolby commented 1 year ago

From my understanding, unitless zero lengths inside calc() are not valid as 0 cannot be treated as a valid <length> and the expected behavior of calc(10px * 0) should evaluate to 0px. In terms of parsers, someone could write parsing logic to force a unitless zero length to be spit out e.g. 0 instead of 0px but most browsers will consider calc(0) invalid so I don't think that's a very good idea just to avoid a stylelint rule.

ludofischer commented 1 year ago

I take it that this was never a cssnano issue but rather a mistaken rule in an (old) stylelint release, so we can close it.