diff --git a/Cargo.lock b/Cargo.lock index 3b6b01085ffe5..18a9f69154ae5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -327,6 +327,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "cow-utils" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417bef24afe1460300965a25ff4a24b8b45ad011948302ec221e8a0a81eb2c79" + [[package]] name = "cpufeatures" version = "0.2.12" @@ -1621,6 +1627,7 @@ version = "0.9.3" dependencies = [ "bitflags 2.6.0", "convert_case", + "cow-utils", "dashmap 6.0.1", "globset", "insta", diff --git a/Cargo.toml b/Cargo.toml index d1e92e42aef97..75cc4d5f207fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -119,6 +119,7 @@ cfg-if = "1.0.0" compact_str = "0.8.0" console = "0.15.8" convert_case = "0.6.0" +cow-utils = "0.1.3" criterion2 = { version = "1.1.0", default-features = false } daachorse = { version = "1.0.0" } dashmap = "6.0.1" diff --git a/crates/oxc_linter/Cargo.toml b/crates/oxc_linter/Cargo.toml index e1803edc7030b..c8be5acb9a064 100644 --- a/crates/oxc_linter/Cargo.toml +++ b/crates/oxc_linter/Cargo.toml @@ -36,6 +36,7 @@ oxc_syntax = { workspace = true } bitflags = { workspace = true } convert_case = { workspace = true } +cow-utils = { workspace = true } dashmap = { workspace = true } globset = { workspace = true } itertools = { workspace = true } diff --git a/crates/oxc_linter/src/rules/eslint/no_script_url.rs b/crates/oxc_linter/src/rules/eslint/no_script_url.rs index 7d68bbfac8d6d..0c059a7c0dafc 100644 --- a/crates/oxc_linter/src/rules/eslint/no_script_url.rs +++ b/crates/oxc_linter/src/rules/eslint/no_script_url.rs @@ -1,3 +1,4 @@ +use cow_utils::CowUtils; use oxc_ast::AstKind; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; @@ -37,7 +38,7 @@ impl Rule for NoScriptUrl { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { match node.kind() { AstKind::StringLiteral(literal) - if literal.value.to_lowercase().starts_with("javascript:") => + if literal.value.cow_to_lowercase().starts_with("javascript:") => { emit_diagnostic(ctx, literal.span); } @@ -51,7 +52,7 @@ impl Rule for NoScriptUrl { .unwrap() .value .raw - .to_lowercase() + .cow_to_lowercase() .starts_with("javascript:") { emit_diagnostic(ctx, literal.span);