-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom-properties-alphabetical-order rule #104
Comments
I'm not sure if sorting custom properties is a safe operation and it won't break resulting CSS. |
@hudochenkov thanks for the quick reply. Do you happen to know any case where it can break? I just checked the csswg, it doesn't seem to mention anything about order being important. |
I don't have experience with custom properties, so I don't know of any cases when the order matters. |
I don't think the order is important — e.g. this :root {
--width: 40px;
--max-width: calc(50vw - var(--width));
} and this :root {
--max-width: calc(50vw - var(--width));
--width: 40px;
} does the exact same thing. Let's say one would have alphabetic sorting then Not sure I'd ever want my custom props sorted but maybe I'm just missing a good use case. |
I’m in the hope that they might compress better, just like why you’d want to sort regular properties. |
I have a use case where I'd really like to order custom declarations, and I'd like to order them by their value (with natural sorting). The use case is I have a file with all the z-indexes of the app defined as custom properties, and I'd like to have them in order to make it easy to see how they will stack. Example: /* stylelint-enable order/order */
:root {
--z-index-panel: 1;
--z-index-autocomplete: 2;
--z-index-tooltip: 3;
} |
+1 it's much cleaner in alphabetical order, right now have to do it manually. |
Looks like sorting custom properties wouldn't break CSS code logic, because they are properties. Unlike variables like in preprocessors. I'm open for a pull request to add new rule.
It could be based on For autofixing new option should be added to postcss-sorting (this plugin powers all order-related stylesheet transforms):
This rule won't add much value without autofix. |
It seems that there is no option to sort custom properties. Is it an intentional decision or it's planned?
The text was updated successfully, but these errors were encountered: