From ed4c58d5b882635d9471baebb8b04ae9c86be817 Mon Sep 17 00:00:00 2001 From: Justinas Delinda <8914032+minht11@users.noreply.github.com> Date: Sat, 21 Sep 2024 20:15:07 +0300 Subject: [PATCH 1/4] to_lowercase -> to_lowercase_cow --- Cargo.lock | 3 ++ crates/biome_css_analyze/Cargo.toml | 1 + .../src/lint/a11y/use_generic_font_names.rs | 4 +- ...no_invalid_direction_in_linear_gradient.rs | 12 +++--- .../lint/correctness/no_unknown_property.rs | 12 +++--- .../src/lint/correctness/no_unknown_unit.rs | 27 ++++++------ .../lint/nursery/no_unknown_pseudo_class.rs | 14 ++++--- .../lint/nursery/no_unknown_pseudo_element.rs | 3 +- .../no_duplicate_at_import_rules.rs | 3 +- .../suspicious/no_duplicate_font_names.rs | 4 +- crates/biome_css_analyze/src/utils.rs | 9 ++-- crates/biome_graphql_analyze/Cargo.toml | 1 + .../src/lint/nursery/no_duplicated_fields.rs | 3 +- crates/biome_grit_patterns/Cargo.toml | 1 + .../src/grit_built_in_functions.rs | 5 ++- .../src/lint/a11y/no_redundant_alt.rs | 3 +- .../src/lint/a11y/no_svg_without_title.rs | 9 ++-- .../lint/a11y/use_key_with_click_events.rs | 10 +++-- .../src/lint/a11y/use_media_caption.rs | 3 +- .../src/lint/suspicious/use_valid_typeof.rs | 3 +- crates/biome_string_case/src/lib.rs | 42 +++++++++++++++++++ 21 files changed, 124 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12037a38198f..9e1235ccc7ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,6 +267,7 @@ dependencies = [ "biome_deserialize_macros", "biome_diagnostics", "biome_rowan", + "biome_string_case", "biome_suppression", "biome_test_utils", "insta", @@ -505,6 +506,7 @@ dependencies = [ "biome_graphql_parser", "biome_graphql_syntax", "biome_rowan", + "biome_string_case", "biome_suppression", "biome_test_utils", "insta", @@ -635,6 +637,7 @@ dependencies = [ "biome_js_syntax", "biome_parser", "biome_rowan", + "biome_string_case", "biome_test_utils", "grit-pattern-matcher", "grit-util", diff --git a/crates/biome_css_analyze/Cargo.toml b/crates/biome_css_analyze/Cargo.toml index bdf81834bb8f..b00bb6bace9f 100644 --- a/crates/biome_css_analyze/Cargo.toml +++ b/crates/biome_css_analyze/Cargo.toml @@ -21,6 +21,7 @@ biome_deserialize = { workspace = true } biome_deserialize_macros = { workspace = true } biome_diagnostics = { workspace = true } biome_rowan = { workspace = true } +biome_string_case = { workspace = true } biome_suppression = { workspace = true } regex = { workspace = true } rustc-hash = { workspace = true } diff --git a/crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs b/crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs index a5aa7851c7d1..c14e5728e124 100644 --- a/crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs +++ b/crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs @@ -7,6 +7,7 @@ use biome_css_syntax::{ CssGenericComponentValueList, CssGenericProperty, CssSyntaxKind, }; use biome_rowan::{AstNode, SyntaxNodeCast, TextRange}; +use biome_string_case::StrExtension; use crate::utils::{ find_font_family, is_css_variable, is_font_family_keyword, is_system_family_name_keyword, @@ -76,7 +77,8 @@ impl Rule for UseGenericFontNames { fn run(ctx: &RuleContext) -> Option { let node = ctx.query(); - let property_name = node.name().ok()?.text().to_lowercase(); + let property_name = node.name().ok()?.text(); + let property_name = property_name.to_lowercase_cow(); // Ignore `@font-face`. See more detail: https://drafts.csswg.org/css-fonts/#font-face-rule if is_in_font_face_at_rule(node) { diff --git a/crates/biome_css_analyze/src/lint/correctness/no_invalid_direction_in_linear_gradient.rs b/crates/biome_css_analyze/src/lint/correctness/no_invalid_direction_in_linear_gradient.rs index 104ce1c10e8b..b2566346ef03 100644 --- a/crates/biome_css_analyze/src/lint/correctness/no_invalid_direction_in_linear_gradient.rs +++ b/crates/biome_css_analyze/src/lint/correctness/no_invalid_direction_in_linear_gradient.rs @@ -5,6 +5,7 @@ use biome_console::markup; use biome_css_syntax::{CssFunction, CssParameter}; use biome_rowan::AstNode; use biome_rowan::AstSeparatedList; +use biome_string_case::StrExtension; use regex::Regex; use std::sync::LazyLock; @@ -82,7 +83,7 @@ impl Rule for NoInvalidDirectionInLinearGradient { "-o-linear-gradient", "-ms-linear-gradient", ]; - if !linear_gradient_property.contains(&node_name.to_lowercase().as_str()) { + if !linear_gradient_property.contains(&node_name.to_lowercase_cow().as_ref()) { return None; } let css_parameter = node.items(); @@ -101,10 +102,11 @@ impl Rule for NoInvalidDirectionInLinearGradient { } } let direction_property = ["top", "left", "bottom", "right"]; - if !direction_property - .iter() - .any(|&keyword| first_css_parameter_text.to_lowercase().contains(keyword)) - { + if !direction_property.iter().any(|&keyword| { + first_css_parameter_text + .to_lowercase_cow() + .contains(keyword) + }) { return None; } let has_prefix = vendor_prefixed(&node_name); diff --git a/crates/biome_css_analyze/src/lint/correctness/no_unknown_property.rs b/crates/biome_css_analyze/src/lint/correctness/no_unknown_property.rs index 7fc88fb9d9b7..b10bf3322460 100644 --- a/crates/biome_css_analyze/src/lint/correctness/no_unknown_property.rs +++ b/crates/biome_css_analyze/src/lint/correctness/no_unknown_property.rs @@ -4,6 +4,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::CssGenericProperty; use biome_rowan::{AstNode, TextRange}; +use biome_string_case::StrExtension; use crate::utils::{is_known_properties, vendor_prefixed}; @@ -72,13 +73,14 @@ impl Rule for NoUnknownProperty { fn run(ctx: &RuleContext) -> Option { let node = ctx.query(); - let property_name = node.name().ok()?.text().to_lowercase(); - if !property_name.starts_with("--") + let property_name = node.name().ok()?.text(); + let property_name_lower = property_name.to_lowercase_cow(); + if !property_name_lower.starts_with("--") // Ignore `composes` property. // See https://github.com/css-modules/css-modules/blob/master/docs/composition.md for more details. - && property_name != "composes" - && !is_known_properties(&property_name) - && !vendor_prefixed(&property_name) + && property_name_lower != "composes" + && !is_known_properties(&property_name_lower) + && !vendor_prefixed(&property_name_lower) { return Some(node.name().ok()?.range()); } diff --git a/crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs b/crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs index 40851868c4d0..4b77a77a93be 100644 --- a/crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs +++ b/crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs @@ -6,6 +6,7 @@ use biome_css_syntax::{ AnyCssDimension, CssFunction, CssGenericProperty, CssQueryFeaturePlain, CssSyntaxKind, }; use biome_rowan::{SyntaxNodeCast, TextRange}; +use biome_string_case::StrExtension; const RESOLUTION_MEDIA_FEATURE_NAMES: [&str; 3] = ["resolution", "min-resolution", "max-resolution"]; @@ -103,14 +104,14 @@ impl Rule for NoUnknownUnit { for ancestor in dimension.unit_token().ok()?.ancestors() { match ancestor.kind() { CssSyntaxKind::CSS_FUNCTION => { - let function_name = ancestor + let function_name_token = ancestor .cast::()? .name() .ok()? .value_token() - .ok()? - .text_trimmed() - .to_lowercase(); + .ok()?; + let function_name = + function_name_token.text_trimmed().to_lowercase_cow(); if function_name.ends_with("image-set") { allow_x = true; @@ -118,15 +119,15 @@ impl Rule for NoUnknownUnit { } } CssSyntaxKind::CSS_GENERIC_PROPERTY => { - let property_name = ancestor + let property_name_token = ancestor .cast::()? .name() .ok()? .as_css_identifier()? .value_token() - .ok()? - .text_trimmed() - .to_lowercase(); + .ok()?; + let property_name = + property_name_token.text_trimmed().to_lowercase_cow(); if property_name == "image-resolution" { allow_x = true; @@ -134,16 +135,16 @@ impl Rule for NoUnknownUnit { } } CssSyntaxKind::CSS_QUERY_FEATURE_PLAIN => { - let feature_name = ancestor + let feature_name_token = ancestor .cast::()? .name() .ok()? .value_token() - .ok()? - .text_trimmed() - .to_lowercase(); + .ok()?; + let feature_name = + feature_name_token.text_trimmed().to_lowercase_cow(); - if RESOLUTION_MEDIA_FEATURE_NAMES.contains(&feature_name.as_str()) { + if RESOLUTION_MEDIA_FEATURE_NAMES.contains(&feature_name.as_ref()) { allow_x = true; break; } diff --git a/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_class.rs b/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_class.rs index b64dbd368398..97afe026a788 100644 --- a/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_class.rs +++ b/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_class.rs @@ -14,6 +14,7 @@ use biome_css_syntax::{ CssPseudoClassFunctionValueList, CssPseudoClassIdentifier, CssPseudoElementSelector, }; use biome_rowan::{declare_node_union, AstNode, TextRange}; +use biome_string_case::StrExtension; declare_lint_rule! { /// Disallow unknown pseudo-class selectors. @@ -168,17 +169,18 @@ impl Rule for NoUnknownPseudoClass { } }; - let lower_name = name.to_lowercase(); + let lower_name = name.to_lowercase_cow(); + let lower_name = lower_name.as_ref(); let is_valid_class = match pseudo_type { - PseudoClassType::PagePseudoClass => is_page_pseudo_class(&lower_name), + PseudoClassType::PagePseudoClass => is_page_pseudo_class(lower_name), PseudoClassType::WebkitScrollbarPseudoClass => { - WEBKIT_SCROLLBAR_PSEUDO_CLASSES.contains(&lower_name.as_str()) + WEBKIT_SCROLLBAR_PSEUDO_CLASSES.contains(&lower_name) } PseudoClassType::Other => { - is_custom_selector(&lower_name) - || vendor_prefixed(&lower_name) - || is_known_pseudo_class(&lower_name) + is_custom_selector(lower_name) + || vendor_prefixed(lower_name) + || is_known_pseudo_class(lower_name) } }; diff --git a/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_element.rs b/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_element.rs index 6d0ebf099d37..da853c7cb345 100644 --- a/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_element.rs +++ b/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_element.rs @@ -4,6 +4,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::{AnyCssPseudoElement, CssPseudoElementSelector}; use biome_rowan::AstNode; +use biome_string_case::StrExtension; use crate::utils::{is_pseudo_elements, vender_prefix}; @@ -79,7 +80,7 @@ impl Rule for NoUnknownPseudoElement { }; if !vender_prefix(pseudo_element_name.as_str()).is_empty() - || is_pseudo_elements(pseudo_element_name.to_lowercase().as_str()) + || is_pseudo_elements(pseudo_element_name.to_lowercase_cow().as_ref()) { return None; } diff --git a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs index e4dee52faa25..22576dab02ea 100644 --- a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs +++ b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs @@ -6,6 +6,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::{AnyCssAtRule, AnyCssRule, CssImportAtRule, CssRuleList}; use biome_rowan::AstNode; +use biome_string_case::StrExtension; declare_lint_rule! { /// Disallow duplicate `@import` rules. @@ -71,7 +72,7 @@ impl Rule for NoDuplicateAtImportRules { .url() .ok()? .text() - .to_lowercase() + .to_lowercase_cow() .replace("url(", "") .replace(')', "") .replace('"', "'"); diff --git a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_font_names.rs b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_font_names.rs index 2447e14a08fd..d805f4a320b8 100644 --- a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_font_names.rs +++ b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_font_names.rs @@ -6,6 +6,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::{AnyCssGenericComponentValue, AnyCssValue, CssGenericProperty}; use biome_rowan::{AstNode, TextRange}; +use biome_string_case::StrExtension; use crate::utils::{find_font_family, is_font_family_keyword}; @@ -64,7 +65,8 @@ impl Rule for NoDuplicateFontNames { fn run(ctx: &RuleContext) -> Option { let node = ctx.query(); - let property_name = node.name().ok()?.text().to_lowercase(); + let property_name = node.name().ok()?.text(); + let property_name = property_name.to_lowercase_cow(); let is_font_family = property_name == "font-family"; let is_font = property_name == "font"; diff --git a/crates/biome_css_analyze/src/utils.rs b/crates/biome_css_analyze/src/utils.rs index df274dc12ba9..97e78ed8d855 100644 --- a/crates/biome_css_analyze/src/utils.rs +++ b/crates/biome_css_analyze/src/utils.rs @@ -15,6 +15,7 @@ use crate::keywords::{ }; use biome_css_syntax::{AnyCssGenericComponentValue, AnyCssValue, CssGenericComponentValueList}; use biome_rowan::{AstNode, SyntaxNodeCast}; +use biome_string_case::StrExtension; pub fn is_font_family_keyword(value: &str) -> bool { BASIC_KEYWORDS.contains(&value) || FONT_FAMILY_KEYWORDS.contains(&value) @@ -38,7 +39,7 @@ pub fn is_font_shorthand_keyword(value: &str) -> bool { } pub fn is_css_variable(value: &str) -> bool { - value.to_lowercase().starts_with("var(") + value.to_lowercase_cow().starts_with("var(") } /// Get the font-families within a `font` shorthand property value. @@ -110,7 +111,7 @@ pub fn find_font_family(value: CssGenericComponentValueList) -> Vec /// Check if the value is a known CSS value function. pub fn is_function_keyword(value: &str) -> bool { FUNCTION_KEYWORDS - .binary_search(&value.to_lowercase().as_str()) + .binary_search(&value.to_lowercase_cow().as_ref()) .is_ok() } @@ -178,8 +179,8 @@ pub fn vendor_prefixed(props: &str) -> bool { /// Check if the input string is a media feature name. pub fn is_media_feature_name(prop: &str) -> bool { - let input = prop.to_lowercase(); - let count = MEDIA_FEATURE_NAMES.binary_search(&input.as_str()); + let input = prop.to_lowercase_cow(); + let count = MEDIA_FEATURE_NAMES.binary_search(&input.as_ref()); if count.is_ok() { return true; } diff --git a/crates/biome_graphql_analyze/Cargo.toml b/crates/biome_graphql_analyze/Cargo.toml index da8861b64b89..4e8bef66a6bb 100644 --- a/crates/biome_graphql_analyze/Cargo.toml +++ b/crates/biome_graphql_analyze/Cargo.toml @@ -18,6 +18,7 @@ biome_deserialize_macros = { workspace = true } biome_diagnostics = { workspace = true } biome_graphql_syntax = { workspace = true } biome_rowan = { workspace = true } +biome_string_case = { workspace = true } biome_suppression = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } diff --git a/crates/biome_graphql_analyze/src/lint/nursery/no_duplicated_fields.rs b/crates/biome_graphql_analyze/src/lint/nursery/no_duplicated_fields.rs index c06c1d318dd3..277c197a6925 100644 --- a/crates/biome_graphql_analyze/src/lint/nursery/no_duplicated_fields.rs +++ b/crates/biome_graphql_analyze/src/lint/nursery/no_duplicated_fields.rs @@ -9,6 +9,7 @@ use biome_graphql_syntax::{ GraphqlVariableDefinitions, }; use biome_rowan::{AstNode, TextRange}; +use biome_string_case::StrExtension; declare_lint_rule! { /// No duplicated fields in GraphQL operations. @@ -78,7 +79,7 @@ impl Rule for NoDuplicatedFields { name, } = state; let field_type = field_type.as_str(); - let lowercased_field_type = field_type.to_lowercase(); + let lowercased_field_type = field_type.to_lowercase_cow(); Some( RuleDiagnostic::new( rule_category!(), diff --git a/crates/biome_grit_patterns/Cargo.toml b/crates/biome_grit_patterns/Cargo.toml index 9938a2bb80ea..b2a8c303c2c9 100644 --- a/crates/biome_grit_patterns/Cargo.toml +++ b/crates/biome_grit_patterns/Cargo.toml @@ -21,6 +21,7 @@ biome_js_parser = { workspace = true } biome_js_syntax = { workspace = true } biome_parser = { workspace = true } biome_rowan = { workspace = true } +biome_string_case = { workspace = true } grit-pattern-matcher = { version = "0.3" } grit-util = { version = "0.3" } im = { version = "15.1.0" } diff --git a/crates/biome_grit_patterns/src/grit_built_in_functions.rs b/crates/biome_grit_patterns/src/grit_built_in_functions.rs index 108c356f5118..ff4bbd4f4620 100644 --- a/crates/biome_grit_patterns/src/grit_built_in_functions.rs +++ b/crates/biome_grit_patterns/src/grit_built_in_functions.rs @@ -3,6 +3,7 @@ use crate::{ grit_resolved_pattern::GritResolvedPattern, }; use anyhow::{anyhow, bail, Result}; +use biome_string_case::StrExtension; use grit_pattern_matcher::{ binding::Binding, constant::Constant, @@ -234,7 +235,9 @@ fn lowercase_fn<'a>( }; let string = arg1.text(&state.files, context.language())?; - Ok(ResolvedPattern::from_string(string.to_lowercase())) + Ok(ResolvedPattern::from_string( + string.to_lowercase_cow().to_string(), + )) } fn random_fn<'a>( diff --git a/crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs b/crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs index 3260e115e9ab..647ec1c70faa 100644 --- a/crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs +++ b/crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs @@ -6,6 +6,7 @@ use biome_js_syntax::{ AnyJsExpression, AnyJsLiteralExpression, AnyJsTemplateElement, AnyJsxAttributeValue, }; use biome_rowan::AstNode; +use biome_string_case::StrExtension; declare_lint_rule! { /// Enforce `img` alt prop does not contain the word "image", "picture", or "photo". @@ -144,5 +145,5 @@ const REDUNDANT_WORDS: [&str; 3] = ["image", "photo", "picture"]; fn is_redundant_alt(alt: &str) -> bool { REDUNDANT_WORDS .into_iter() - .any(|word| alt.split_whitespace().any(|x| x.to_lowercase() == word)) + .any(|word| alt.split_whitespace().any(|x| x.to_lowercase_cow() == word)) } diff --git a/crates/biome_js_analyze/src/lint/a11y/no_svg_without_title.rs b/crates/biome_js_analyze/src/lint/a11y/no_svg_without_title.rs index 42d8fd881d01..9ecca2ef9a7c 100644 --- a/crates/biome_js_analyze/src/lint/a11y/no_svg_without_title.rs +++ b/crates/biome_js_analyze/src/lint/a11y/no_svg_without_title.rs @@ -1,7 +1,10 @@ +use std::borrow::Cow; + use biome_analyze::{context::RuleContext, declare_lint_rule, Ast, Rule, RuleDiagnostic}; use biome_console::markup; use biome_js_syntax::{jsx_ext::AnyJsxElement, JsxAttribute, JsxChildList, JsxElement}; use biome_rowan::{AstNode, AstNodeList}; +use biome_string_case::StrExtension; declare_lint_rule! { /// Enforces the usage of the `title` element for the `svg` element. @@ -149,8 +152,8 @@ impl Rule for NoSvgWithoutTitle { return Some(()); }; - match role_attribute_text.to_lowercase().as_str() { - "img" => { + match role_attribute_text.to_lowercase_cow() { + Cow::Borrowed("img") => { let [aria_label, aria_labelledby] = node .attributes() .find_by_names(["aria-label", "aria-labelledby"]); @@ -163,7 +166,7 @@ impl Rule for NoSvgWithoutTitle { Some(()) } // if role attribute is empty, the svg element should have title element - "" => Some(()), + Cow::Borrowed("") => Some(()), _ => None, } } diff --git a/crates/biome_js_analyze/src/lint/a11y/use_key_with_click_events.rs b/crates/biome_js_analyze/src/lint/a11y/use_key_with_click_events.rs index cc7dc4605d76..a890a69117d8 100644 --- a/crates/biome_js_analyze/src/lint/a11y/use_key_with_click_events.rs +++ b/crates/biome_js_analyze/src/lint/a11y/use_key_with_click_events.rs @@ -1,9 +1,12 @@ +use std::borrow::Cow; + use biome_analyze::{ context::RuleContext, declare_lint_rule, Ast, Rule, RuleDiagnostic, RuleSource, }; use biome_console::markup; use biome_js_syntax::{jsx_ext::AnyJsxElement, AnyJsxAttribute, AnyJsxElementName}; use biome_rowan::AstNode; +use biome_string_case::StrExtension; declare_lint_rule! { /// Enforce onClick is accompanied by at least one of the following: `onKeyUp`, `onKeyDown`, `onKeyPress`. @@ -74,13 +77,14 @@ impl Rule for UseKeyWithClickEvents { match element.name() { Ok(AnyJsxElementName::JsxName(name)) => { - let element_name = name.value_token().ok()?.text_trimmed().to_lowercase(); + let name_token = name.value_token().ok()?; + let element_name = name_token.text_trimmed().to_lowercase_cow(); // Don't handle interactive roles // TODO Support aria roles https://github.com/rome/tools/issues/3640 if matches!( - element_name.as_str(), - "button" | "checkbox" | "combobox" | "a" | "input" + element_name, + Cow::Borrowed("button" | "checkbox" | "combobox" | "a" | "input") ) { return None; } diff --git a/crates/biome_js_analyze/src/lint/a11y/use_media_caption.rs b/crates/biome_js_analyze/src/lint/a11y/use_media_caption.rs index 210ad5a9c39a..0dd07da7176f 100644 --- a/crates/biome_js_analyze/src/lint/a11y/use_media_caption.rs +++ b/crates/biome_js_analyze/src/lint/a11y/use_media_caption.rs @@ -4,6 +4,7 @@ use biome_console::markup; use biome_js_syntax::jsx_ext::AnyJsxElement; use biome_js_syntax::{AnyJsxChild, JsxElement, TextRange}; use biome_rowan::AstNode; +use biome_string_case::StrExtension; declare_lint_rule! { /// Enforces that `audio` and `video` elements must have a `track` for captions. @@ -86,7 +87,7 @@ impl Rule for UseMediaCaption { .as_jsx_string()? .inner_string_text() .ok()? - .to_lowercase() + .to_lowercase_cow() == "captions"; Some(has_track && has_valid_kind) diff --git a/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs b/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs index 48ad42a1959c..efd5222d90af 100644 --- a/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs +++ b/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs @@ -9,6 +9,7 @@ use biome_js_syntax::{ JsBinaryOperator, JsUnaryOperator, TextRange, }; use biome_rowan::{AstNode, BatchMutationExt}; +use biome_string_case::StrExtension; use crate::JsRuleAction; @@ -179,7 +180,7 @@ impl Rule for UseValidTypeof { let suggestion = ident.name().ok().and_then(|name| { let value = name.value_token().ok()?; - let to_lower = value.text_trimmed().to_lowercase(); + let to_lower = value.text_trimmed().to_lowercase_cow(); let as_type = JsTypeName::from_str(&to_lower)?; Some((id.clone(), as_type)) diff --git a/crates/biome_string_case/src/lib.rs b/crates/biome_string_case/src/lib.rs index 9b2ebd90a12e..62133761ce9a 100644 --- a/crates/biome_string_case/src/lib.rs +++ b/crates/biome_string_case/src/lib.rs @@ -420,6 +420,10 @@ pub trait StrExtension: ToOwned { /// is that this functions returns ```Cow``` and does not allocate /// if the string is already in lowercase. fn to_ascii_lowercase_cow(&self) -> std::borrow::Cow; + /// Returns the same value as String::to_lowercase. The only difference + /// is that this functions returns ```Cow``` and does not allocate + /// if the string is already in lowercase. + fn to_lowercase_cow(&self) -> std::borrow::Cow; } impl StrExtension for str { @@ -432,6 +436,16 @@ impl StrExtension for str { Cow::Borrowed(self) } } + + fn to_lowercase_cow(&self) -> Cow { + let has_uppercase = self.chars().any(char::is_uppercase); + if has_uppercase { + #[allow(clippy::disallowed_methods)] + Cow::Owned(self.to_lowercase()) + } else { + Cow::Borrowed(self) + } + } } impl StrExtension for std::ffi::OsStr { @@ -447,6 +461,10 @@ impl StrExtension for std::ffi::OsStr { Cow::Borrowed(self) } } + + fn to_lowercase_cow(&self) -> Cow { + panic!("OsStr is not supported") + } } impl StrExtension for [u8] { @@ -458,6 +476,11 @@ impl StrExtension for [u8] { Cow::Borrowed(self) } } + + fn to_lowercase_cow(&self) -> Cow { + // u8 is always ASCII + Self::to_ascii_lowercase_cow(self) + } } #[cfg(test)] @@ -878,4 +901,23 @@ mod tests { Cow::Borrowed(_) )); } + + #[test] + fn to_lowercase_cow() { + assert_eq!("test", "Test".to_lowercase_cow()); + assert_eq!(b"test", b"Test".to_lowercase_cow().as_ref()); + + assert_eq!("test", "teSt".to_lowercase_cow()); + assert_eq!("te😀st", "te😀St".to_lowercase_cow()); + assert_eq!(b"test", b"teSt".to_lowercase_cow().as_ref()); + + assert!(matches!("test".to_lowercase_cow(), Cow::Borrowed(_))); + + assert_eq!("ėest", "Ėest".to_lowercase_cow()); + + assert_eq!("tešt", "teŠt".to_lowercase_cow()); + assert_eq!("te😀st", "te😀St".to_lowercase_cow()); + + assert!(matches!("tešt".to_lowercase_cow(), Cow::Borrowed(_))); + } } From df730d411c32b1cb6dcdea7f697f8e9ae3bca5f5 Mon Sep 17 00:00:00 2001 From: Justinas Delinda <8914032+minht11@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:27:48 +0300 Subject: [PATCH 2/4] Migrate remaining cases --- Cargo.lock | 1 + clippy.toml | 3 ++- .../suspicious/no_duplicate_at_import_rules.rs | 6 ++++-- .../no_duplicate_selectors_keyframe_block.rs | 7 +++++-- .../suspicious/no_shorthand_property_overrides.rs | 1 + crates/biome_css_analyze/src/utils.rs | 3 ++- .../src/utils/component_value_list.rs | 7 +++++-- .../lint/correctness/no_string_case_mismatch.rs | 15 +++++++++------ .../src/lint/suspicious/use_valid_typeof.rs | 6 +++--- xtask/coverage/Cargo.toml | 1 + xtask/coverage/src/lib.rs | 3 ++- xtask/coverage/src/ts/ts_microsoft.rs | 7 +++++-- 12 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9e1235ccc7ca..e4c70390a542 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4543,6 +4543,7 @@ dependencies = [ "biome_js_syntax", "biome_parser", "biome_rowan", + "biome_string_case", "colored", "indicatif", "once_cell", diff --git a/clippy.toml b/clippy.toml index 808d19248487..4efa2c76ffa0 100644 --- a/clippy.toml +++ b/clippy.toml @@ -2,5 +2,6 @@ allow-dbg-in-tests = true disallowed-methods = [ { path = "str::to_ascii_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrExtension::to_ascii_lowercase_cow` instead." }, - { path = "std::ffi::OsStr::to_ascii_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrExtension::to_ascii_lowercase_cow` instead." } + { path = "std::ffi::OsStr::to_ascii_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrExtension::to_ascii_lowercase_cow` instead." }, + { path = "str::to_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrExtension::to_lowercase_cow` instead." }, ] \ No newline at end of file diff --git a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs index 22576dab02ea..6fd09dacf5f8 100644 --- a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs +++ b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs @@ -86,7 +86,9 @@ impl Rule for NoDuplicateAtImportRules { for media in import_rule.media() { match media { Ok(media) => { - if !media_query_set.insert(media.text().to_lowercase()) { + if !media_query_set + .insert(media.text().to_lowercase_cow().into()) + { return Some(import_rule); } } @@ -98,7 +100,7 @@ impl Rule for NoDuplicateAtImportRules { for media in import_rule.media() { match media { Ok(media) => { - media_set.insert(media.text().to_lowercase()); + media_set.insert(media.text().to_lowercase_cow().into()); } _ => return None, } diff --git a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_selectors_keyframe_block.rs b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_selectors_keyframe_block.rs index 66328d75dad8..3f3f4154e3ca 100644 --- a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_selectors_keyframe_block.rs +++ b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_selectors_keyframe_block.rs @@ -6,6 +6,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::{AnyCssKeyframesItem, AnyCssKeyframesSelector, CssKeyframesBlock}; use biome_rowan::AstNode; +use biome_string_case::StrExtension; declare_lint_rule! { /// Disallow duplicate selectors within keyframe blocks. @@ -53,12 +54,14 @@ impl Rule for NoDuplicateSelectorsKeyframeBlock { fn run(ctx: &RuleContext) -> Option { let node = ctx.query(); - let mut selector_list = HashSet::new(); + let mut selector_list: HashSet = HashSet::new(); for keyframe_item in node.items() { match keyframe_item { AnyCssKeyframesItem::CssKeyframesItem(item) => { let keyframe_selector = item.selectors().into_iter().next()?.ok()?; - if !selector_list.insert(keyframe_selector.text().to_lowercase()) { + if !selector_list + .insert(keyframe_selector.text().to_lowercase_cow().to_string()) + { return Some(keyframe_selector); } } 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 f015e5e73c77..8e0987022551 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 @@ -105,6 +105,7 @@ impl Visitor for NoDeclarationBlockShorthandPropertyOverridesVisitor { .and_then(|property_node| property_node.name().ok()) { let prop = prop_node.text(); + #[allow(clippy::disallowed_methods)] let prop_lowercase = prop.to_lowercase(); let prop_prefix = vender_prefix(&prop_lowercase); diff --git a/crates/biome_css_analyze/src/utils.rs b/crates/biome_css_analyze/src/utils.rs index 97e78ed8d855..dec0f12fca66 100644 --- a/crates/biome_css_analyze/src/utils.rs +++ b/crates/biome_css_analyze/src/utils.rs @@ -46,7 +46,8 @@ pub fn is_css_variable(value: &str) -> bool { pub fn find_font_family(value: CssGenericComponentValueList) -> Vec { let mut font_families: Vec = Vec::new(); for v in value { - let lower_case_value = v.text().to_lowercase(); + let value = v.text(); + let lower_case_value = value.to_lowercase_cow(); // Ignore CSS variables if is_css_variable(&lower_case_value) { diff --git a/crates/biome_css_formatter/src/utils/component_value_list.rs b/crates/biome_css_formatter/src/utils/component_value_list.rs index c2f7b448222d..381dbe89b639 100644 --- a/crates/biome_css_formatter/src/utils/component_value_list.rs +++ b/crates/biome_css_formatter/src/utils/component_value_list.rs @@ -2,6 +2,7 @@ use crate::comments::CssComments; use biome_css_syntax::{CssGenericDelimiter, CssGenericProperty, CssLanguage, CssSyntaxKind}; use biome_formatter::{write, CstFormatContext}; use biome_formatter::{FormatOptions, FormatResult}; +use biome_string_case::StrExtension; use crate::prelude::*; use crate::CssFormatter; @@ -177,9 +178,11 @@ where .and_then(|parent| parent.name().ok()) .and_then(|name| { name.as_css_identifier() - .map(|name| name.text().to_lowercase()) + .and_then(|identifier| identifier.value_token().ok()) }) - .map_or(false, |name| { + .map_or(false, |token| { + let name = token.text().to_lowercase_cow(); + name.starts_with("grid-template") || name == "grid" }); diff --git a/crates/biome_js_analyze/src/lint/correctness/no_string_case_mismatch.rs b/crates/biome_js_analyze/src/lint/correctness/no_string_case_mismatch.rs index 74299e5e3d8f..b5c912965922 100644 --- a/crates/biome_js_analyze/src/lint/correctness/no_string_case_mismatch.rs +++ b/crates/biome_js_analyze/src/lint/correctness/no_string_case_mismatch.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use biome_analyze::context::RuleContext; use biome_analyze::{ declare_lint_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic, RuleSource, @@ -6,6 +8,7 @@ use biome_console::markup; use biome_js_factory::make; use biome_js_syntax::*; use biome_rowan::{declare_node_union, AstNode, AstSeparatedList, BatchMutationExt}; +use biome_string_case::StrExtension; use crate::JsRuleAction; @@ -91,9 +94,9 @@ impl Rule for NoStringCaseMismatch { fn action(ctx: &RuleContext, state: &Self::State) -> Option { let mut mutation = ctx.root().begin(); - let expected_value = state - .expected_case - .convert(state.literal.as_static_value()?.text()); + let static_value = state.literal.as_static_value()?; + + let expected_value = state.expected_case.convert(static_value.text()); mutation.replace_node( state.literal.clone(), AnyJsExpression::AnyJsLiteralExpression( @@ -196,10 +199,10 @@ impl StringCase { None } - fn convert(&self, s: &str) -> String { + fn convert<'a>(&self, s: &'a str) -> Cow<'a, str> { match self { - StringCase::Upper => s.to_uppercase(), - StringCase::Lower => s.to_lowercase(), + StringCase::Upper => Cow::Owned(s.to_uppercase()), + StringCase::Lower => s.to_lowercase_cow(), } } diff --git a/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs b/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs index efd5222d90af..c30d822c7765 100644 --- a/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs +++ b/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs @@ -129,16 +129,16 @@ impl Rule for UseValidTypeof { .text_trimmed() .trim_start_matches(['"', '\'']) .trim_end_matches(['"', '\'']) - .to_lowercase(); + .to_lowercase_cow(); if JsTypeName::from_str(&literal).is_some() { return None; } // Try to fix the casing of the literal eg. "String" -> "string" - let suggestion = literal.to_lowercase(); + let suggestion = literal.to_lowercase_cow(); return Some(( - TypeofError::InvalidLiteral(range, literal), + TypeofError::InvalidLiteral(range, literal.to_string()), JsTypeName::from_str(&suggestion).map(|type_name| (lit.clone(), type_name)), )); } diff --git a/xtask/coverage/Cargo.toml b/xtask/coverage/Cargo.toml index ec302d4ecb9e..d066a202b05e 100644 --- a/xtask/coverage/Cargo.toml +++ b/xtask/coverage/Cargo.toml @@ -14,6 +14,7 @@ biome_js_semantic = { workspace = true } biome_js_syntax = { workspace = true } biome_parser = { workspace = true } biome_rowan = { workspace = true } +biome_string_case = { workspace = true } colored = "2.1.0" indicatif = { version = "0.17.8", features = ["improved_unicode"] } once_cell = "1.20.0" diff --git a/xtask/coverage/src/lib.rs b/xtask/coverage/src/lib.rs index 156b270313f9..43d9f149bebd 100644 --- a/xtask/coverage/src/lib.rs +++ b/xtask/coverage/src/lib.rs @@ -17,6 +17,7 @@ use crate::reporters::{ }; use crate::runner::{run_test_suite, TestRunContext, TestSuite}; use biome_parser::diagnostic::ParseDiagnostic; +use biome_string_case::StrExtension; use jsx::jsx_babel::BabelJsxTestSuite; use serde::{Deserialize, Serialize}; use std::any::Any; @@ -165,7 +166,7 @@ const ALL_JSX_SUITES: &str = "jsx"; const ALL_SYMBOLS_SUITES: &str = "symbols"; fn get_test_suites(suites: Option<&str>) -> Vec> { - let suites = suites.unwrap_or("*").to_lowercase(); + let suites = suites.unwrap_or("*").to_lowercase_cow(); let mut ids: Vec<_> = suites.split(',').collect(); let mut suites: Vec> = vec![]; diff --git a/xtask/coverage/src/ts/ts_microsoft.rs b/xtask/coverage/src/ts/ts_microsoft.rs index 09a3e46bc319..8e9f185a0f1b 100644 --- a/xtask/coverage/src/ts/ts_microsoft.rs +++ b/xtask/coverage/src/ts/ts_microsoft.rs @@ -5,7 +5,9 @@ use crate::runner::{ use biome_js_parser::JsParserOptions; use biome_js_syntax::{JsFileSource, ModuleKind}; use biome_rowan::{AstNode, SyntaxKind}; +use biome_string_case::StrExtension; use regex::Regex; +use std::borrow::Cow; use std::convert::TryFrom; use std::fmt::Write; use std::io; @@ -140,12 +142,13 @@ fn extract_metadata(code: &str, path: &str) -> TestCaseMetadata { for line in code.lines() { if let Some(option) = options_regex.captures(line) { - let option_name = option.name("name").unwrap().as_str().to_lowercase(); + let option_name = option.name("name").unwrap().as_str().to_lowercase_cow(); let option_value = option.name("value").unwrap().as_str().trim(); if option_name == "alwaysstrict" { write!(current_file_content, "\"use strict\";{line_ending}").unwrap(); - } else if matches!(option_name.as_str(), "module" | "target") && files.is_empty() { + } else if matches!(option_name, Cow::Borrowed("module" | "target")) && files.is_empty() + { run_options.extend( option_value .split(',') From ac3bc60f6c451a4c1c3750a61bd1071ca9f5f87b Mon Sep 17 00:00:00 2001 From: Justinas Delinda <8914032+minht11@users.noreply.github.com> Date: Sat, 21 Sep 2024 22:29:19 +0300 Subject: [PATCH 3/4] Split StrExtension into two traits --- clippy.toml | 6 ++-- .../src/lint/a11y/use_generic_font_names.rs | 2 +- ...no_invalid_direction_in_linear_gradient.rs | 2 +- .../lint/correctness/no_unknown_property.rs | 2 +- .../src/lint/correctness/no_unknown_unit.rs | 2 +- .../lint/nursery/no_unknown_pseudo_class.rs | 2 +- .../lint/nursery/no_unknown_pseudo_element.rs | 2 +- .../no_duplicate_at_import_rules.rs | 2 +- .../suspicious/no_duplicate_font_names.rs | 2 +- .../no_duplicate_selectors_keyframe_block.rs | 2 +- crates/biome_css_analyze/src/utils.rs | 2 +- crates/biome_css_formatter/src/lib.rs | 2 +- .../src/utils/component_value_list.rs | 11 +++---- .../src/utils/string_utils.rs | 2 +- crates/biome_css_syntax/src/file_source.rs | 2 +- crates/biome_formatter/src/token/number.rs | 2 +- .../src/lint/nursery/no_duplicated_fields.rs | 2 +- .../biome_graphql_syntax/src/file_source.rs | 2 +- .../src/grit_built_in_functions.rs | 2 +- crates/biome_html_syntax/src/file_source.rs | 2 +- .../src/lint/a11y/no_redundant_alt.rs | 2 +- .../src/lint/a11y/no_svg_without_title.rs | 2 +- .../lint/a11y/use_key_with_click_events.rs | 2 +- .../src/lint/a11y/use_media_caption.rs | 2 +- .../correctness/no_string_case_mismatch.rs | 2 +- .../src/lint/suspicious/use_valid_typeof.rs | 2 +- .../expressions/bigint_literal_expression.rs | 2 +- .../src/ts/types/bigint_literal_type.rs | 2 +- crates/biome_js_syntax/src/file_source.rs | 2 +- crates/biome_json_syntax/src/file_source.rs | 2 +- crates/biome_service/src/file_handlers/mod.rs | 2 +- crates/biome_string_case/src/lib.rs | 31 ++++++++++--------- crates/biome_yaml_syntax/src/file_source.rs | 2 +- xtask/coverage/src/lib.rs | 2 +- xtask/coverage/src/ts/ts_microsoft.rs | 2 +- 35 files changed, 55 insertions(+), 57 deletions(-) diff --git a/clippy.toml b/clippy.toml index 4efa2c76ffa0..617e4150d5d6 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,7 +1,7 @@ allow-dbg-in-tests = true disallowed-methods = [ - { path = "str::to_ascii_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrExtension::to_ascii_lowercase_cow` instead." }, - { path = "std::ffi::OsStr::to_ascii_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrExtension::to_ascii_lowercase_cow` instead." }, - { path = "str::to_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrExtension::to_lowercase_cow` instead." }, + { path = "str::to_ascii_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrOnlyExtension::to_ascii_lowercase_cow` instead." }, + { path = "std::ffi::OsStr::to_ascii_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrLikeExtension::to_ascii_lowercase_cow` instead." }, + { path = "str::to_lowercase", reason = "Avoid memory allocation. Use `biome_string_case::StrOnlyExtension::to_lowercase_cow` instead." }, ] \ No newline at end of file diff --git a/crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs b/crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs index c14e5728e124..20e064ea2877 100644 --- a/crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs +++ b/crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs @@ -7,7 +7,7 @@ use biome_css_syntax::{ CssGenericComponentValueList, CssGenericProperty, CssSyntaxKind, }; use biome_rowan::{AstNode, SyntaxNodeCast, TextRange}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use crate::utils::{ find_font_family, is_css_variable, is_font_family_keyword, is_system_family_name_keyword, diff --git a/crates/biome_css_analyze/src/lint/correctness/no_invalid_direction_in_linear_gradient.rs b/crates/biome_css_analyze/src/lint/correctness/no_invalid_direction_in_linear_gradient.rs index b2566346ef03..022efa9feaa7 100644 --- a/crates/biome_css_analyze/src/lint/correctness/no_invalid_direction_in_linear_gradient.rs +++ b/crates/biome_css_analyze/src/lint/correctness/no_invalid_direction_in_linear_gradient.rs @@ -5,7 +5,7 @@ use biome_console::markup; use biome_css_syntax::{CssFunction, CssParameter}; use biome_rowan::AstNode; use biome_rowan::AstSeparatedList; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use regex::Regex; use std::sync::LazyLock; diff --git a/crates/biome_css_analyze/src/lint/correctness/no_unknown_property.rs b/crates/biome_css_analyze/src/lint/correctness/no_unknown_property.rs index b10bf3322460..8270d2b744e2 100644 --- a/crates/biome_css_analyze/src/lint/correctness/no_unknown_property.rs +++ b/crates/biome_css_analyze/src/lint/correctness/no_unknown_property.rs @@ -4,7 +4,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::CssGenericProperty; use biome_rowan::{AstNode, TextRange}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use crate::utils::{is_known_properties, vendor_prefixed}; diff --git a/crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs b/crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs index 4b77a77a93be..921bc430e6fb 100644 --- a/crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs +++ b/crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs @@ -6,7 +6,7 @@ use biome_css_syntax::{ AnyCssDimension, CssFunction, CssGenericProperty, CssQueryFeaturePlain, CssSyntaxKind, }; use biome_rowan::{SyntaxNodeCast, TextRange}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; const RESOLUTION_MEDIA_FEATURE_NAMES: [&str; 3] = ["resolution", "min-resolution", "max-resolution"]; diff --git a/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_class.rs b/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_class.rs index 97afe026a788..9131516aea85 100644 --- a/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_class.rs +++ b/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_class.rs @@ -14,7 +14,7 @@ use biome_css_syntax::{ CssPseudoClassFunctionValueList, CssPseudoClassIdentifier, CssPseudoElementSelector, }; use biome_rowan::{declare_node_union, AstNode, TextRange}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; declare_lint_rule! { /// Disallow unknown pseudo-class selectors. diff --git a/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_element.rs b/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_element.rs index da853c7cb345..7141e68d5893 100644 --- a/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_element.rs +++ b/crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_element.rs @@ -4,7 +4,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::{AnyCssPseudoElement, CssPseudoElementSelector}; use biome_rowan::AstNode; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use crate::utils::{is_pseudo_elements, vender_prefix}; diff --git a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs index 6fd09dacf5f8..3baad8907616 100644 --- a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs +++ b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_at_import_rules.rs @@ -6,7 +6,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::{AnyCssAtRule, AnyCssRule, CssImportAtRule, CssRuleList}; use biome_rowan::AstNode; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; declare_lint_rule! { /// Disallow duplicate `@import` rules. diff --git a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_font_names.rs b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_font_names.rs index d805f4a320b8..23559767d66e 100644 --- a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_font_names.rs +++ b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_font_names.rs @@ -6,7 +6,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::{AnyCssGenericComponentValue, AnyCssValue, CssGenericProperty}; use biome_rowan::{AstNode, TextRange}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use crate::utils::{find_font_family, is_font_family_keyword}; diff --git a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_selectors_keyframe_block.rs b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_selectors_keyframe_block.rs index 3f3f4154e3ca..c9eacf76cd12 100644 --- a/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_selectors_keyframe_block.rs +++ b/crates/biome_css_analyze/src/lint/suspicious/no_duplicate_selectors_keyframe_block.rs @@ -6,7 +6,7 @@ use biome_analyze::{ use biome_console::markup; use biome_css_syntax::{AnyCssKeyframesItem, AnyCssKeyframesSelector, CssKeyframesBlock}; use biome_rowan::AstNode; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; declare_lint_rule! { /// Disallow duplicate selectors within keyframe blocks. diff --git a/crates/biome_css_analyze/src/utils.rs b/crates/biome_css_analyze/src/utils.rs index dec0f12fca66..9c73f0a94541 100644 --- a/crates/biome_css_analyze/src/utils.rs +++ b/crates/biome_css_analyze/src/utils.rs @@ -15,7 +15,7 @@ use crate::keywords::{ }; use biome_css_syntax::{AnyCssGenericComponentValue, AnyCssValue, CssGenericComponentValueList}; use biome_rowan::{AstNode, SyntaxNodeCast}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; pub fn is_font_family_keyword(value: &str) -> bool { BASIC_KEYWORDS.contains(&value) || FONT_FAMILY_KEYWORDS.contains(&value) diff --git a/crates/biome_css_formatter/src/lib.rs b/crates/biome_css_formatter/src/lib.rs index e14de3cef9dd..47d3cd82a6c1 100644 --- a/crates/biome_css_formatter/src/lib.rs +++ b/crates/biome_css_formatter/src/lib.rs @@ -26,7 +26,7 @@ use biome_formatter::{ }; use biome_formatter::{Formatted, Printed}; use biome_rowan::{AstNode, SyntaxNode, TextRange}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; /// Used to get an object that knows how to format this object. pub(crate) trait AsFormat { diff --git a/crates/biome_css_formatter/src/utils/component_value_list.rs b/crates/biome_css_formatter/src/utils/component_value_list.rs index 381dbe89b639..9e9eeaf2ff77 100644 --- a/crates/biome_css_formatter/src/utils/component_value_list.rs +++ b/crates/biome_css_formatter/src/utils/component_value_list.rs @@ -2,7 +2,7 @@ use crate::comments::CssComments; use biome_css_syntax::{CssGenericDelimiter, CssGenericProperty, CssLanguage, CssSyntaxKind}; use biome_formatter::{write, CstFormatContext}; use biome_formatter::{FormatOptions, FormatResult}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use crate::prelude::*; use crate::CssFormatter; @@ -176,12 +176,9 @@ where let is_grid_property = list .parent::() .and_then(|parent| parent.name().ok()) - .and_then(|name| { - name.as_css_identifier() - .and_then(|identifier| identifier.value_token().ok()) - }) - .map_or(false, |token| { - let name = token.text().to_lowercase_cow(); + .and_then(|name| name.as_css_identifier().map(|name| name.text())) + .map_or(false, |name| { + let name = name.to_lowercase_cow(); name.starts_with("grid-template") || name == "grid" }); diff --git a/crates/biome_css_formatter/src/utils/string_utils.rs b/crates/biome_css_formatter/src/utils/string_utils.rs index 43da3a92b8dd..df97a8f5138f 100644 --- a/crates/biome_css_formatter/src/utils/string_utils.rs +++ b/crates/biome_css_formatter/src/utils/string_utils.rs @@ -13,7 +13,7 @@ use biome_formatter::{ Format, FormatResult, }; use biome_rowan::SyntaxToken; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use crate::{prelude::CssFormatContext, AsFormat, CssFormatter}; diff --git a/crates/biome_css_syntax/src/file_source.rs b/crates/biome_css_syntax/src/file_source.rs index 524fbc2e04ec..03818ad50bf3 100644 --- a/crates/biome_css_syntax/src/file_source.rs +++ b/crates/biome_css_syntax/src/file_source.rs @@ -1,5 +1,5 @@ use biome_rowan::FileSourceError; -use biome_string_case::StrExtension; +use biome_string_case::StrLikeExtension; use std::{ffi::OsStr, path::Path}; #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] diff --git a/crates/biome_formatter/src/token/number.rs b/crates/biome_formatter/src/token/number.rs index 7bba6911a23b..861282b30135 100644 --- a/crates/biome_formatter/src/token/number.rs +++ b/crates/biome_formatter/src/token/number.rs @@ -1,5 +1,5 @@ use biome_rowan::{Language, SyntaxToken}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use std::borrow::Cow; use std::num::NonZeroUsize; diff --git a/crates/biome_graphql_analyze/src/lint/nursery/no_duplicated_fields.rs b/crates/biome_graphql_analyze/src/lint/nursery/no_duplicated_fields.rs index 277c197a6925..77676cf462df 100644 --- a/crates/biome_graphql_analyze/src/lint/nursery/no_duplicated_fields.rs +++ b/crates/biome_graphql_analyze/src/lint/nursery/no_duplicated_fields.rs @@ -9,7 +9,7 @@ use biome_graphql_syntax::{ GraphqlVariableDefinitions, }; use biome_rowan::{AstNode, TextRange}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; declare_lint_rule! { /// No duplicated fields in GraphQL operations. diff --git a/crates/biome_graphql_syntax/src/file_source.rs b/crates/biome_graphql_syntax/src/file_source.rs index ce906f63d424..87f6885dc8fc 100644 --- a/crates/biome_graphql_syntax/src/file_source.rs +++ b/crates/biome_graphql_syntax/src/file_source.rs @@ -1,5 +1,5 @@ use biome_rowan::FileSourceError; -use biome_string_case::StrExtension; +use biome_string_case::StrLikeExtension; use std::ffi::OsStr; use std::path::Path; diff --git a/crates/biome_grit_patterns/src/grit_built_in_functions.rs b/crates/biome_grit_patterns/src/grit_built_in_functions.rs index ff4bbd4f4620..9c8902f83d7f 100644 --- a/crates/biome_grit_patterns/src/grit_built_in_functions.rs +++ b/crates/biome_grit_patterns/src/grit_built_in_functions.rs @@ -3,7 +3,7 @@ use crate::{ grit_resolved_pattern::GritResolvedPattern, }; use anyhow::{anyhow, bail, Result}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use grit_pattern_matcher::{ binding::Binding, constant::Constant, diff --git a/crates/biome_html_syntax/src/file_source.rs b/crates/biome_html_syntax/src/file_source.rs index 1f0a9908f9d5..d8815ba64d2e 100644 --- a/crates/biome_html_syntax/src/file_source.rs +++ b/crates/biome_html_syntax/src/file_source.rs @@ -1,5 +1,5 @@ use biome_rowan::FileSourceError; -use biome_string_case::StrExtension; +use biome_string_case::StrLikeExtension; use std::{ffi::OsStr, path::Path}; #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] diff --git a/crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs b/crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs index 647ec1c70faa..86209ecd8b8a 100644 --- a/crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs +++ b/crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs @@ -6,7 +6,7 @@ use biome_js_syntax::{ AnyJsExpression, AnyJsLiteralExpression, AnyJsTemplateElement, AnyJsxAttributeValue, }; use biome_rowan::AstNode; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; declare_lint_rule! { /// Enforce `img` alt prop does not contain the word "image", "picture", or "photo". diff --git a/crates/biome_js_analyze/src/lint/a11y/no_svg_without_title.rs b/crates/biome_js_analyze/src/lint/a11y/no_svg_without_title.rs index 9ecca2ef9a7c..2608f97d49e3 100644 --- a/crates/biome_js_analyze/src/lint/a11y/no_svg_without_title.rs +++ b/crates/biome_js_analyze/src/lint/a11y/no_svg_without_title.rs @@ -4,7 +4,7 @@ use biome_analyze::{context::RuleContext, declare_lint_rule, Ast, Rule, RuleDiag use biome_console::markup; use biome_js_syntax::{jsx_ext::AnyJsxElement, JsxAttribute, JsxChildList, JsxElement}; use biome_rowan::{AstNode, AstNodeList}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; declare_lint_rule! { /// Enforces the usage of the `title` element for the `svg` element. diff --git a/crates/biome_js_analyze/src/lint/a11y/use_key_with_click_events.rs b/crates/biome_js_analyze/src/lint/a11y/use_key_with_click_events.rs index a890a69117d8..9de4c03e05e1 100644 --- a/crates/biome_js_analyze/src/lint/a11y/use_key_with_click_events.rs +++ b/crates/biome_js_analyze/src/lint/a11y/use_key_with_click_events.rs @@ -6,7 +6,7 @@ use biome_analyze::{ use biome_console::markup; use biome_js_syntax::{jsx_ext::AnyJsxElement, AnyJsxAttribute, AnyJsxElementName}; use biome_rowan::AstNode; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; declare_lint_rule! { /// Enforce onClick is accompanied by at least one of the following: `onKeyUp`, `onKeyDown`, `onKeyPress`. diff --git a/crates/biome_js_analyze/src/lint/a11y/use_media_caption.rs b/crates/biome_js_analyze/src/lint/a11y/use_media_caption.rs index 0dd07da7176f..0981e535d0ff 100644 --- a/crates/biome_js_analyze/src/lint/a11y/use_media_caption.rs +++ b/crates/biome_js_analyze/src/lint/a11y/use_media_caption.rs @@ -4,7 +4,7 @@ use biome_console::markup; use biome_js_syntax::jsx_ext::AnyJsxElement; use biome_js_syntax::{AnyJsxChild, JsxElement, TextRange}; use biome_rowan::AstNode; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; declare_lint_rule! { /// Enforces that `audio` and `video` elements must have a `track` for captions. diff --git a/crates/biome_js_analyze/src/lint/correctness/no_string_case_mismatch.rs b/crates/biome_js_analyze/src/lint/correctness/no_string_case_mismatch.rs index b5c912965922..3efdd136e8b7 100644 --- a/crates/biome_js_analyze/src/lint/correctness/no_string_case_mismatch.rs +++ b/crates/biome_js_analyze/src/lint/correctness/no_string_case_mismatch.rs @@ -8,7 +8,7 @@ use biome_console::markup; use biome_js_factory::make; use biome_js_syntax::*; use biome_rowan::{declare_node_union, AstNode, AstSeparatedList, BatchMutationExt}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use crate::JsRuleAction; diff --git a/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs b/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs index c30d822c7765..a75dbadf88b3 100644 --- a/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs +++ b/crates/biome_js_analyze/src/lint/suspicious/use_valid_typeof.rs @@ -9,7 +9,7 @@ use biome_js_syntax::{ JsBinaryOperator, JsUnaryOperator, TextRange, }; use biome_rowan::{AstNode, BatchMutationExt}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use crate::JsRuleAction; diff --git a/crates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rs b/crates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rs index 7bdaa69d67fa..72060b4e5303 100644 --- a/crates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rs +++ b/crates/biome_js_formatter/src/js/expressions/bigint_literal_expression.rs @@ -4,7 +4,7 @@ use biome_formatter::write; use biome_js_syntax::parentheses::NeedsParentheses; use biome_js_syntax::JsBigintLiteralExpression; use biome_js_syntax::JsBigintLiteralExpressionFields; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use std::borrow::Cow; #[derive(Debug, Clone, Default)] diff --git a/crates/biome_js_formatter/src/ts/types/bigint_literal_type.rs b/crates/biome_js_formatter/src/ts/types/bigint_literal_type.rs index 97c29dc5668c..8d5021144efc 100644 --- a/crates/biome_js_formatter/src/ts/types/bigint_literal_type.rs +++ b/crates/biome_js_formatter/src/ts/types/bigint_literal_type.rs @@ -4,7 +4,7 @@ use crate::prelude::*; use biome_formatter::write; use biome_js_syntax::{TsBigintLiteralType, TsBigintLiteralTypeFields}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; #[derive(Debug, Clone, Default)] pub struct FormatTsBigintLiteralType; diff --git a/crates/biome_js_syntax/src/file_source.rs b/crates/biome_js_syntax/src/file_source.rs index 18e3c8e36222..9d091b81d548 100644 --- a/crates/biome_js_syntax/src/file_source.rs +++ b/crates/biome_js_syntax/src/file_source.rs @@ -1,5 +1,5 @@ use biome_rowan::FileSourceError; -use biome_string_case::StrExtension; +use biome_string_case::StrLikeExtension; use std::{borrow::Cow, ffi::OsStr, path::Path}; /// Enum of the different ECMAScript standard versions. diff --git a/crates/biome_json_syntax/src/file_source.rs b/crates/biome_json_syntax/src/file_source.rs index ff2824013af6..14d6a198d283 100644 --- a/crates/biome_json_syntax/src/file_source.rs +++ b/crates/biome_json_syntax/src/file_source.rs @@ -1,5 +1,5 @@ use biome_rowan::FileSourceError; -use biome_string_case::StrExtension; +use biome_string_case::StrLikeExtension; use core::str; use std::{ ffi::OsStr, diff --git a/crates/biome_service/src/file_handlers/mod.rs b/crates/biome_service/src/file_handlers/mod.rs index 469793f8b2e6..e5ffc4f5f14e 100644 --- a/crates/biome_service/src/file_handlers/mod.rs +++ b/crates/biome_service/src/file_handlers/mod.rs @@ -37,7 +37,7 @@ use biome_json_syntax::{JsonFileSource, JsonLanguage}; use biome_parser::AnyParse; use biome_project::PackageJson; use biome_rowan::{FileSourceError, NodeCache}; -use biome_string_case::StrExtension; +use biome_string_case::StrLikeExtension; use html::HtmlFileHandler; pub use javascript::JsFormatterSettings; use std::borrow::Cow; diff --git a/crates/biome_string_case/src/lib.rs b/crates/biome_string_case/src/lib.rs index 62133761ce9a..adcad87c8654 100644 --- a/crates/biome_string_case/src/lib.rs +++ b/crates/biome_string_case/src/lib.rs @@ -415,18 +415,25 @@ const LEADING_BIT_INDEX_TO_CASE: [Case; 11] = [ Case::Unknown, ]; -pub trait StrExtension: ToOwned { +pub trait StrLikeExtension: ToOwned { /// Returns the same value as String::to_lowercase. The only difference /// is that this functions returns ```Cow``` and does not allocate /// if the string is already in lowercase. fn to_ascii_lowercase_cow(&self) -> std::borrow::Cow; +} + +pub trait StrOnlyExtension: ToOwned { /// Returns the same value as String::to_lowercase. The only difference /// is that this functions returns ```Cow``` and does not allocate /// if the string is already in lowercase. fn to_lowercase_cow(&self) -> std::borrow::Cow; + /// Returns the same value as String::to_lowercase. The only difference + /// is that this functions returns ```Cow``` and does not allocate + /// if the string is already in lowercase. + fn to_ascii_lowercase_cow(&self) -> std::borrow::Cow; } -impl StrExtension for str { +impl StrOnlyExtension for str { fn to_ascii_lowercase_cow(&self) -> Cow { let has_ascii_uppercase = self.bytes().any(|b| b.is_ascii_uppercase()); if has_ascii_uppercase { @@ -448,7 +455,7 @@ impl StrExtension for str { } } -impl StrExtension for std::ffi::OsStr { +impl StrLikeExtension for std::ffi::OsStr { fn to_ascii_lowercase_cow(&self) -> Cow { let has_ascii_uppercase = self .as_encoded_bytes() @@ -461,13 +468,9 @@ impl StrExtension for std::ffi::OsStr { Cow::Borrowed(self) } } - - fn to_lowercase_cow(&self) -> Cow { - panic!("OsStr is not supported") - } } -impl StrExtension for [u8] { +impl StrLikeExtension for [u8] { fn to_ascii_lowercase_cow(&self) -> Cow { let has_ascii_uppercase = self.iter().any(|b| b.is_ascii_uppercase()); if has_ascii_uppercase { @@ -476,13 +479,13 @@ impl StrExtension for [u8] { Cow::Borrowed(self) } } - - fn to_lowercase_cow(&self) -> Cow { - // u8 is always ASCII - Self::to_ascii_lowercase_cow(self) - } } +// TODO. Once trait-alias are stabilized it would be enough to `use` this trait instead of individual ones. +// https://doc.rust-lang.org/stable/unstable-book/language-features/trait-alias.html +pub trait StrExtension: StrOnlyExtension + StrLikeExtension {} +impl StrExtension for T {} + #[cfg(test)] mod tests { use std::ffi::OsStr; @@ -905,11 +908,9 @@ mod tests { #[test] fn to_lowercase_cow() { assert_eq!("test", "Test".to_lowercase_cow()); - assert_eq!(b"test", b"Test".to_lowercase_cow().as_ref()); assert_eq!("test", "teSt".to_lowercase_cow()); assert_eq!("te😀st", "te😀St".to_lowercase_cow()); - assert_eq!(b"test", b"teSt".to_lowercase_cow().as_ref()); assert!(matches!("test".to_lowercase_cow(), Cow::Borrowed(_))); diff --git a/crates/biome_yaml_syntax/src/file_source.rs b/crates/biome_yaml_syntax/src/file_source.rs index 83e928a4c563..54101d89c676 100644 --- a/crates/biome_yaml_syntax/src/file_source.rs +++ b/crates/biome_yaml_syntax/src/file_source.rs @@ -1,6 +1,6 @@ use biome_rowan::FileSourceError; use std::{ffi::OsStr, path::Path}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; #[cfg_attr(feature = "schema", derive(schemars::YamlSchema))] #[derive( diff --git a/xtask/coverage/src/lib.rs b/xtask/coverage/src/lib.rs index 43d9f149bebd..39e562b30c34 100644 --- a/xtask/coverage/src/lib.rs +++ b/xtask/coverage/src/lib.rs @@ -17,7 +17,7 @@ use crate::reporters::{ }; use crate::runner::{run_test_suite, TestRunContext, TestSuite}; use biome_parser::diagnostic::ParseDiagnostic; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use jsx::jsx_babel::BabelJsxTestSuite; use serde::{Deserialize, Serialize}; use std::any::Any; diff --git a/xtask/coverage/src/ts/ts_microsoft.rs b/xtask/coverage/src/ts/ts_microsoft.rs index 8e9f185a0f1b..d0f498e03360 100644 --- a/xtask/coverage/src/ts/ts_microsoft.rs +++ b/xtask/coverage/src/ts/ts_microsoft.rs @@ -5,7 +5,7 @@ use crate::runner::{ use biome_js_parser::JsParserOptions; use biome_js_syntax::{JsFileSource, ModuleKind}; use biome_rowan::{AstNode, SyntaxKind}; -use biome_string_case::StrExtension; +use biome_string_case::StrOnlyExtension; use regex::Regex; use std::borrow::Cow; use std::convert::TryFrom; From fdec82300b319a4e972e0b1f6f8eb786af463cfb Mon Sep 17 00:00:00 2001 From: Justinas Delinda <8914032+minht11@users.noreply.github.com> Date: Thu, 26 Sep 2024 19:37:08 +0300 Subject: [PATCH 4/4] fix --- crates/biome_grit_syntax/src/file_source.rs | 2 +- crates/biome_service/src/file_handlers/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/biome_grit_syntax/src/file_source.rs b/crates/biome_grit_syntax/src/file_source.rs index 259ec5317b90..d603d31f0cb3 100644 --- a/crates/biome_grit_syntax/src/file_source.rs +++ b/crates/biome_grit_syntax/src/file_source.rs @@ -1,5 +1,5 @@ use biome_rowan::FileSourceError; -use biome_string_case::StrExtension; +use biome_string_case::StrLikeExtension; use std::{ffi::OsStr, path::Path}; #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive( diff --git a/crates/biome_service/src/file_handlers/mod.rs b/crates/biome_service/src/file_handlers/mod.rs index 600b33d9c1d6..eb249430a9b6 100644 --- a/crates/biome_service/src/file_handlers/mod.rs +++ b/crates/biome_service/src/file_handlers/mod.rs @@ -38,7 +38,7 @@ use biome_json_syntax::{JsonFileSource, JsonLanguage}; use biome_parser::AnyParse; use biome_project::PackageJson; use biome_rowan::{FileSourceError, NodeCache}; -use biome_string_case::StrExtension; +use biome_string_case::StrLikeExtension; use grit::GritFileHandler; use html::HtmlFileHandler;