fix(linter): jsx-key: handle anonymous functional components in arrays that have a function body (#1983)

Closes #1982
This commit is contained in:
Maurice Nicholson 2024-01-10 22:46:17 +00:00 committed by GitHub
parent 78b427bc50
commit d4acd140ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -83,7 +83,6 @@ fn is_in_array_or_iter<'a, 'b>(
let mut is_outside_containing_function = false;
let mut is_explicit_return = false;
let mut is_arrow_expr_statement = false;
loop {
let Some(parent) = ctx.nodes().parent_node(node.id()) else {
@ -92,7 +91,7 @@ fn is_in_array_or_iter<'a, 'b>(
match parent.kind() {
AstKind::ArrowExpression(arrow_expr) => {
is_arrow_expr_statement = matches!(
let is_arrow_expr_statement = matches!(
arrow_expr.body.statements.first(),
Some(Statement::ExpressionStatement(_))
);
@ -126,7 +125,7 @@ fn is_in_array_or_iter<'a, 'b>(
is_outside_containing_function = true;
}
AstKind::ArrayExpression(_) => {
if is_arrow_expr_statement {
if is_outside_containing_function {
return None;
}
@ -392,6 +391,14 @@ fn test() {
(Component) => <div><Component /></div>
];
",
r"
MyStory.decorators = [
(Component) => {
const store = useMyStore();
return <Provider store={store}><Component /></Provider>;
}
];
",
];
let fail = vec![