From 2dc75ae837a085d79e894da23374167c05da89f6 Mon Sep 17 00:00:00 2001 From: togami Date: Mon, 30 Sep 2024 23:05:10 +0900 Subject: [PATCH 1/2] chore: return &str instead of String --- .../lint/suspicious/no_shorthand_property_overrides.rs | 10 ++++------ crates/biome_css_analyze/src/utils.rs | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/crates/biome_css_analyze/src/lint/suspicious/no_shorthand_property_overrides.rs b/crates/biome_css_analyze/src/lint/suspicious/no_shorthand_property_overrides.rs index 8e0987022551..699ec6c81345 100644 --- a/crates/biome_css_analyze/src/lint/suspicious/no_shorthand_property_overrides.rs +++ b/crates/biome_css_analyze/src/lint/suspicious/no_shorthand_property_overrides.rs @@ -7,12 +7,12 @@ use biome_console::markup; use biome_css_syntax::{AnyCssDeclarationName, CssGenericProperty, CssLanguage, CssSyntaxKind}; use biome_rowan::{AstNode, Language, SyntaxNode, TextRange, WalkEvent}; -fn remove_vendor_prefix(prop: &str, prefix: &str) -> String { +fn remove_vendor_prefix<'a>(prop: &'a str, prefix: &'a str) -> &'a str { if let Some(prop) = prop.strip_prefix(prefix) { - return prop.to_string(); + return prop; } - prop.to_string() + prop } fn get_override_props(property: &str) -> Vec<&str> { @@ -118,9 +118,7 @@ impl Visitor for NoDeclarationBlockShorthandPropertyOverridesVisitor { remove_vendor_prefix(&prior_prop.lowercase, &prior_prop_prefix); if prop_prefix == prior_prop_prefix - && override_props - .binary_search(&unprefixed_prior_prop.as_str()) - .is_ok() + && override_props.binary_search(&unprefixed_prior_prop).is_ok() { ctx.match_query( NoDeclarationBlockShorthandPropertyOverridesQuery { diff --git a/crates/biome_css_analyze/src/utils.rs b/crates/biome_css_analyze/src/utils.rs index 9c73f0a94541..ecf9ab0ec0bb 100644 --- a/crates/biome_css_analyze/src/utils.rs +++ b/crates/biome_css_analyze/src/utils.rs @@ -122,13 +122,13 @@ pub fn is_custom_function(value: &str) -> bool { } // Returns the vendor prefix extracted from an input string. -pub fn vender_prefix(prop: &str) -> String { +pub fn vender_prefix(prop: &str) -> &str { for prefix in VENDOR_PREFIXES.iter() { if prop.starts_with(prefix) { - return (*prefix).to_string(); + return prefix; } } - String::new() + "" } pub fn is_pseudo_elements(prop: &str) -> bool { @@ -138,7 +138,7 @@ pub fn is_pseudo_elements(prop: &str) -> bool { || OTHER_PSEUDO_ELEMENTS.contains(&prop) } -/// Check if the input string is custom selector +/// Check if the input string is custom selector /// See https://drafts.csswg.org/css-extensions/#custom-selectors for more details pub fn is_custom_selector(prop: &str) -> bool { prop.starts_with("--") From b99d9adc44391e3546e87476e075da56002e8b6e Mon Sep 17 00:00:00 2001 From: togami Date: Tue, 1 Oct 2024 00:46:42 +0900 Subject: [PATCH 2/2] chore: clippy --- .../src/lint/suspicious/no_shorthand_property_overrides.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/biome_css_analyze/src/lint/suspicious/no_shorthand_property_overrides.rs b/crates/biome_css_analyze/src/lint/suspicious/no_shorthand_property_overrides.rs index 699ec6c81345..b4c0d4252b77 100644 --- a/crates/biome_css_analyze/src/lint/suspicious/no_shorthand_property_overrides.rs +++ b/crates/biome_css_analyze/src/lint/suspicious/no_shorthand_property_overrides.rs @@ -109,13 +109,13 @@ impl Visitor for NoDeclarationBlockShorthandPropertyOverridesVisitor { let prop_lowercase = prop.to_lowercase(); let prop_prefix = vender_prefix(&prop_lowercase); - let unprefixed_prop = remove_vendor_prefix(&prop_lowercase, &prop_prefix); - let override_props = get_override_props(&unprefixed_prop); + let unprefixed_prop = remove_vendor_prefix(&prop_lowercase, prop_prefix); + let override_props = get_override_props(unprefixed_prop); self.prior_props_in_block.iter().for_each(|prior_prop| { let prior_prop_prefix = vender_prefix(&prior_prop.lowercase); let unprefixed_prior_prop = - remove_vendor_prefix(&prior_prop.lowercase, &prior_prop_prefix); + remove_vendor_prefix(&prior_prop.lowercase, prior_prop_prefix); if prop_prefix == prior_prop_prefix && override_props.binary_search(&unprefixed_prior_prop).is_ok()