diff --git a/crates/oxc_linter/src/rules/jsx_a11y/aria_props.rs b/crates/oxc_linter/src/rules/jsx_a11y/aria_props.rs index 27b7fd108..05d2ec3c2 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/aria_props.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/aria_props.rs @@ -7,7 +7,8 @@ use oxc_macros::declare_oxc_lint; use oxc_span::Span; use crate::{ - context::LintContext, globals::VALID_ARIA_PROPS, rule::Rule, utils::get_attribute_name, AstNode, + context::LintContext, globals::VALID_ARIA_PROPS, rule::Rule, utils::get_jsx_attribute_name, + AstNode, }; #[derive(Debug, Error, Diagnostic)] @@ -41,7 +42,7 @@ declare_oxc_lint!( impl Rule for AriaProps { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { if let AstKind::JSXAttributeItem(JSXAttributeItem::Attribute(attr)) = node.kind() { - let name = get_attribute_name(&attr.name).to_lowercase(); + let name = get_jsx_attribute_name(&attr.name).to_lowercase(); if name.starts_with("aria-") && !VALID_ARIA_PROPS.contains(&name) { ctx.diagnostic(AriaPropsDiagnostic(attr.span, name)); } diff --git a/crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs b/crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs index 0fa72e4fa..3d34b8830 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/aria_unsupported_elements.rs @@ -10,7 +10,7 @@ use phf::phf_set; use crate::{ globals::RESERVED_HTML_TAG, rule::Rule, - utils::{get_attribute_name, get_element_type}, + utils::{get_element_type, get_jsx_attribute_name}, AstNode, LintContext, }; @@ -53,7 +53,7 @@ impl Rule for AriaUnsupportedElements { JSXAttributeItem::Attribute(attr) => attr, JSXAttributeItem::SpreadAttribute(_) => continue, }; - let attr_name = get_attribute_name(&attr.name).to_lowercase(); + let attr_name = get_jsx_attribute_name(&attr.name).to_lowercase(); if INVALID_ATTRIBUTES.contains(&attr_name) { ctx.diagnostic(AriaUnsupportedElementsDiagnostic(attr.span, attr_name)); } diff --git a/crates/oxc_linter/src/rules/jsx_a11y/role_support_aria_props.rs b/crates/oxc_linter/src/rules/jsx_a11y/role_support_aria_props.rs index 9d4a8bfde..9b660d065 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/role_support_aria_props.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/role_support_aria_props.rs @@ -15,7 +15,8 @@ use crate::{ globals::{VALID_ARIA_PROPS, VALID_ARIA_ROLES}, rule::Rule, utils::{ - get_attribute_name, get_element_type, get_string_literal_prop_value, has_jsx_prop_lowercase, + get_element_type, get_jsx_attribute_name, get_string_literal_prop_value, + has_jsx_prop_lowercase, }, AstNode, }; @@ -77,7 +78,7 @@ impl Rule for RoleSupportAriaProps { let invalid_props = get_invalid_aria_props_for_role(role_value); for attr in &jsx_el.attributes { if let JSXAttributeItem::Attribute(attr) = attr { - let name = get_attribute_name(&attr.name).to_lowercase(); + let name = get_jsx_attribute_name(&attr.name).to_lowercase(); if invalid_props.contains(&&name.as_str()) { ctx.diagnostic(if is_implicit { RoleSupportAriaPropsDiagnostic::IsImplicit( diff --git a/crates/oxc_linter/src/rules/react/no_unknown_property.rs b/crates/oxc_linter/src/rules/react/no_unknown_property.rs index 3e25053b9..eb210d126 100644 --- a/crates/oxc_linter/src/rules/react/no_unknown_property.rs +++ b/crates/oxc_linter/src/rules/react/no_unknown_property.rs @@ -19,7 +19,7 @@ use std::collections::hash_set::HashSet; use crate::{ context::LintContext, rule::Rule, - utils::{get_element_type, get_prop_name}, + utils::{get_element_type, get_jsx_attribute_name}, AstNode, }; @@ -482,7 +482,7 @@ impl Rule for NoUnknownProperty { }) .for_each(|attr| { let span = attr.name.span(); - let actual_name = get_prop_name(&attr.name); + let actual_name = get_jsx_attribute_name(&attr.name); if self.0.ignore.contains(&(actual_name)) { return; }; diff --git a/crates/oxc_linter/src/utils/jsx_a11y.rs b/crates/oxc_linter/src/utils/jsx_a11y.rs deleted file mode 100644 index 933c164ae..000000000 --- a/crates/oxc_linter/src/utils/jsx_a11y.rs +++ /dev/null @@ -1,10 +0,0 @@ -use oxc_ast::ast::JSXAttributeName; - -pub fn get_attribute_name(attr: &JSXAttributeName) -> String { - match attr { - JSXAttributeName::Identifier(ident) => ident.name.to_string(), - JSXAttributeName::NamespacedName(namespaced_name) => { - format!("{}:{}", namespaced_name.namespace.name, namespaced_name.property.name) - } - } -} diff --git a/crates/oxc_linter/src/utils/mod.rs b/crates/oxc_linter/src/utils/mod.rs index ac0b2b7e7..b432d7dbd 100644 --- a/crates/oxc_linter/src/utils/mod.rs +++ b/crates/oxc_linter/src/utils/mod.rs @@ -1,7 +1,6 @@ mod jest; -mod jsx_a11y; mod node; mod react; mod unicorn; -pub use self::{jest::*, jsx_a11y::*, node::*, react::*, unicorn::*}; +pub use self::{jest::*, node::*, react::*, unicorn::*}; diff --git a/crates/oxc_linter/src/utils/react.rs b/crates/oxc_linter/src/utils/react.rs index 828ba505c..1e6bbe5ac 100644 --- a/crates/oxc_linter/src/utils/react.rs +++ b/crates/oxc_linter/src/utils/react.rs @@ -54,10 +54,10 @@ pub fn get_prop_value<'a, 'b>(item: &'b JSXAttributeItem<'a>) -> Option<&'b JSXA } } -pub fn get_prop_name(item: &JSXAttributeName) -> String { - match item { +pub fn get_jsx_attribute_name(attr: &JSXAttributeName) -> String { + match attr { JSXAttributeName::NamespacedName(name) => { - format!("{}:{}", name.namespace.name.as_str(), name.property.name.as_str()) + format!("{}:{}", name.namespace.name, name.property.name) } JSXAttributeName::Identifier(ident) => ident.name.to_string(), }