ThisIsManta / stylus-supremacy

A Node.js script that helps formatting Stylus files.
https://thisismanta.github.io/stylus-supremacy
MIT License
88 stars 9 forks source link

insertColons option: "preserve" mode for accessing nested variables #79

Closed qnp closed 3 years ago

qnp commented 3 years ago

Greetings,

In the light of this Stylus issue https://github.com/stylus/stylus/issues/2357, accessing a nested variable can be ambiguous without colon, e.g.

color $colors.primary

is considered as a CSS selector, while:

color: $colors.primary

is considered as a CSS property.

However, stylus supremacy insertColons option is a Boolean so only offers a toggle mode: with or without colons. In all our codebase we don't want to use colons, but only in the case when accessing nested variables.

Stylus supremacy insertColons should provide a "preserve" mode which does not affect at all the way the developer used colons or not. That is, insertColons as a String with three possible values: "preserve", "always", "none".

I've looked into the code but I am not quite sure how to do it so I cannot make a PR for that.

Please tell me what do you think about this proposition.

ThisIsManta commented 3 years ago

I understand the problem, but can you give me some context of color $colors.primary being a selector and property respectively?

qnp commented 3 years ago

There is no such case when color $colors.primary is used as a selector. It would be weird.

However Stylus itself does compile it as a selector, because he cannot discriminate between a nested variable access and a selector (see the above linked issue and its following comments).

When we format our stylus code, we use stylus supremacy insertColons: false option so all our declarations are free of colons. Hence, all instances of color: $colors.primary (or similar) are transformed to color $colors.primary, and then Stylus compilation fails partially or has unexpected behavior as it consider them as selectors.

qnp commented 3 years ago

@ThisIsManta any update on this Issue ? If you provide me with few guidance on the source code & project architecture, I can handle a PR for that.

qnp commented 3 years ago

I have done a PR #82 to cover the needs

ThisIsManta commented 3 years ago

Thanks for the PR, but I have to reject it as I came up with different solution. See my explanation at https://github.com/ThisIsManta/stylus-supremacy/pull/82#issuecomment-770354561