diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs index cd5275b72099b..533f0009e6132 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs @@ -95,16 +95,16 @@ impl Rule for PreferDomNodeDataset { match method_name { "setAttribute" => { - ctx.diagnostic(set(span, &dataset_property_name)); + ctx.diagnostic(set(span, dataset_property_name)); } "getAttribute" => { - ctx.diagnostic(get(span, &dataset_property_name)); + ctx.diagnostic(get(span, dataset_property_name)); } - "removeAttribute" => ctx.diagnostic(remove(string_lit.span, &dataset_property_name)), + "removeAttribute" => ctx.diagnostic(remove(string_lit.span, dataset_property_name)), "hasAttribute" => { - ctx.diagnostic(has(span, &dataset_property_name)); + ctx.diagnostic(has(span, dataset_property_name)); } _ => unreachable!(), @@ -112,13 +112,8 @@ impl Rule for PreferDomNodeDataset { } } -fn strip_data_prefix(s: &str) -> Option { - let prefix = "data-"; - if s.len() >= prefix.len() && s[..prefix.len()].eq_ignore_ascii_case(prefix) { - Some(s[prefix.len()..].to_string()) - } else { - None - } +fn strip_data_prefix(s: &str) -> Option<&str> { + s.strip_prefix("data-").or_else(|| s.strip_prefix("DATA-")) } #[test] @@ -184,6 +179,7 @@ fn test() { r"element.getAttribute(0);", r#"element.getAttribute("foo-unicorn");"#, r#"element.getAttribute("data");"#, + r#"element.getAttribute("stylĂ˝");"#, ]; let fail = vec![