From 381d9fe624c14cf14163b34978acf0408897d2f5 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:06:46 +0000 Subject: [PATCH] refactor(linter): shorten code in `react/jsx_no_useless_fragment` (#5350) Shorten code. Also do the enum match first, as its cheaper than a string comparison. --- .../src/rules/react/jsx_no_useless_fragment.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs b/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs index bcd1d274af126..93abdea4bc8ca 100644 --- a/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs +++ b/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs @@ -164,17 +164,13 @@ fn is_html_element(elem_name: &JSXElementName) -> bool { fn is_jsx_fragment(elem: &JSXOpeningElement) -> bool { match &elem.name { - JSXElementName::IdentifierReference(ident) => ident.name.as_str() == "Fragment", + JSXElementName::IdentifierReference(ident) => ident.name == "Fragment", JSXElementName::MemberExpression(mem_expr) => { - if mem_expr.property.name.as_str() != "Fragment" { - return false; + if let JSXMemberExpressionObject::IdentifierReference(ident) = &mem_expr.object { + ident.name == "React" && mem_expr.property.name == "Fragment" + } else { + false } - - let JSXMemberExpressionObject::IdentifierReference(ident) = &mem_expr.object else { - return false; - }; - - return ident.name.as_str() == "React"; } JSXElementName::NamespacedName(_) | JSXElementName::Identifier(_) => false, }