mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 20:28:58 +00:00
refactor(linter): remove duplicate get_jsx_attribute_name (#1971)
This commit is contained in:
parent
78916703c5
commit
64310fa9b1
7 changed files with 14 additions and 23 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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::*};
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue