-
-
Notifications
You must be signed in to change notification settings - Fork 494
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
feat(biome_css_analyze): add rule useSortedProperties
#4063
base: main
Are you sure you want to change the base?
Conversation
useSortedProperties
useSortedProperties
useSortedProperties
CodSpeed Performance ReportMerging #4063 will degrade performances by 19.89%Comparing Summary
Benchmarks breakdown
|
Thank you @simon-paris for the contribution. I will look into this rule this week. As a very early feedback, this rule should be made an assist (apologies for the lack of documentation, I will try to fix that ASAP). Here's an example of assist: https://github.com/biomejs/biome/blob/main/crates/biome_json_analyze/src/assists/source/use_sorted_keys.rs |
@@ -3436,6 +3436,10 @@ pub struct Nursery { | |||
#[serde(skip_serializing_if = "Option::is_none")] | |||
pub use_sorted_classes: | |||
Option<RuleFixConfiguration<biome_js_analyze::options::UseSortedClasses>>, | |||
#[doc = "Enforce ordering of CSS properties."] | |||
#[serde(skip_serializing_if = "Option::is_none")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know sorting alphabetically may have issues (example) but I'd really appreciate having an option for it. For me it's much more useful than the "recess-order" configuration. Would it be difficult to add support for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a "recess-order"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The grouped order that stylelint-config-recess-order
uses by default, and the one this PR was based on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd appreciate having an option, too.
It looks like stylelint-config-recess-order
was chosen because it's the most popular shared config. However, the Stylelint order plugin has a dedicated rule for alphabetically sorting, and that may not have been taken into account. It's difficult to compare its popularity with those of the shared configs, as they have their own npm download stats.
The dedicated rule is used in 2.1k public configs, so a lot of people prefer to sort alphabetically. Probably because there are 600+ properties, with more added all the time, so it's hard to maintain meaningful categories for all these.
Summary
Related: #3 (comment), #3167
This implements CSS declaration and rule sorting from the
stylelint-order
plugin. It sorts properties (and nested rules) in a consistent order, e.g:The property order comes from the most popular preset config:
stylelint-config-recess-order
.This is the equivalent stylelint config:
The sort order is this: (ties stay in the same relative order)
a. Custom properties
b. The "composes" property
c. Properties
e. Nested rules and at-rules
f. Other
a. By the order defined in PROPERTY_ORDER
a. By the order defined in VENDOR_PREFIXES
b. Properties with no vendor prefix
Some possible issues:
LazyLock<HashMap>
to implement some lookup tables for this rule. Not sure if that's a good method, I'm new to rust.Test Plan
Unit tests are included.