Skip to content

Commit

Permalink
refactor(linter): shorten code in react/jsx_no_useless_fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Aug 30, 2024
1 parent 83b9a82 commit d129949
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit d129949

Please sign in to comment.