From e9b330191095ad9ab1f24b590b4edca46fe7b0fb Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sat, 1 Feb 2025 17:55:26 -0500 Subject: [PATCH] fix(css): fix css lint/assist registry codegen --- .../src/analyzer/assist/actions.rs | 26 +++++++++++++++++-- crates/biome_css_analyze/src/registry.rs | 1 + .../@biomejs/backend-jsonrpc/src/workspace.ts | 4 +++ .../@biomejs/biome/configuration_schema.json | 7 +++++ xtask/codegen/src/generate_analyzer.rs | 3 +-- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/biome_configuration/src/analyzer/assist/actions.rs b/crates/biome_configuration/src/analyzer/assist/actions.rs index bad4f1812f25..08da0f94a2b5 100644 --- a/crates/biome_configuration/src/analyzer/assist/actions.rs +++ b/crates/biome_configuration/src/analyzer/assist/actions.rs @@ -131,11 +131,19 @@ pub struct Source { #[serde(skip_serializing_if = "Option::is_none")] pub use_sorted_keys: Option>, + #[doc = "Enforce ordering of CSS properties and nested rules."] + #[serde(skip_serializing_if = "Option::is_none")] + pub use_sorted_properties: + Option>, } impl Source { const GROUP_NAME: &'static str = "source"; - pub(crate) const GROUP_RULES: &'static [&'static str] = - &["organizeImports", "useSortedAttributes", "useSortedKeys"]; + pub(crate) const GROUP_RULES: &'static [&'static str] = &[ + "organizeImports", + "useSortedAttributes", + "useSortedKeys", + "useSortedProperties", + ]; const RECOMMENDED_RULES_AS_FILTERS: &'static [RuleFilter<'static>] = &[RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[0])]; pub(crate) fn recommended_rules_as_filters() -> &'static [RuleFilter<'static>] { @@ -165,6 +173,11 @@ impl Source { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[2])); } } + if let Some(rule) = self.use_sorted_properties.as_ref() { + if rule.is_enabled() { + index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[3])); + } + } index_set } pub(crate) fn get_disabled_rules(&self) -> FxHashSet> { @@ -184,6 +197,11 @@ impl Source { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[2])); } } + if let Some(rule) = self.use_sorted_properties.as_ref() { + if rule.is_disabled() { + index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[3])); + } + } index_set } #[doc = r" Checks if, given a rule name, matches one of the rules contained in this category"] @@ -217,6 +235,10 @@ impl Source { .use_sorted_keys .as_ref() .map(|conf| (conf.level(), conf.get_options())), + "useSortedProperties" => self + .use_sorted_properties + .as_ref() + .map(|conf| (conf.level(), conf.get_options())), _ => None, } } diff --git a/crates/biome_css_analyze/src/registry.rs b/crates/biome_css_analyze/src/registry.rs index 126c58e9c9a8..26b12e197b1f 100644 --- a/crates/biome_css_analyze/src/registry.rs +++ b/crates/biome_css_analyze/src/registry.rs @@ -5,5 +5,6 @@ use biome_analyze::RegistryVisitor; use biome_css_syntax::CssLanguage; pub fn visit_registry>(registry: &mut V) { + registry.record_category::(); registry.record_category::(); } diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index 02f19f6a4fdd..a2ae255f5fe1 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -831,6 +831,10 @@ export interface Source { * Sorts the keys of a JSON object in natural order */ useSortedKeys?: RuleAssistConfiguration_for_Null; + /** + * Enforce ordering of CSS properties and nested rules. + */ + useSortedProperties?: RuleAssistConfiguration_for_Null; } export type QuoteStyle = "double" | "single"; /** diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index dfb963708635..b24c21fc1658 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -3916,6 +3916,13 @@ { "$ref": "#/definitions/RuleAssistConfiguration_for_Null" }, { "type": "null" } ] + }, + "useSortedProperties": { + "description": "Enforce ordering of CSS properties and nested rules.", + "anyOf": [ + { "$ref": "#/definitions/RuleAssistConfiguration_for_Null" }, + { "type": "null" } + ] } }, "additionalProperties": false diff --git a/xtask/codegen/src/generate_analyzer.rs b/xtask/codegen/src/generate_analyzer.rs index 28893ef3103a..54de9228bbfc 100644 --- a/xtask/codegen/src/generate_analyzer.rs +++ b/xtask/codegen/src/generate_analyzer.rs @@ -48,8 +48,7 @@ fn generate_css_analyzer() -> Result<()> { let mut analyzers = BTreeMap::new(); generate_category("lint", &mut analyzers, &base_path)?; - let mut assist = BTreeMap::new(); - generate_category("assist", &mut assist, &base_path)?; + generate_category("assist", &mut analyzers, &base_path)?; generate_options(&base_path)?; update_css_registry_builder(analyzers)