fix(linter): incorrect reporting for jsx_key (#1020)

tested on a different repo and noticed an issue (despite passing all of
the eslint test cases)

If we are in the following scenario:

```tsx
    const columns: ColumnDef<User>[] = [
        {
            accessorKey: 'firstName',
            header: ({ column }) => <DataTableColumnHeader column={column} title="First Name" />,
            cell: ({ row }) => <div>{row.getValue('firstName')}</div>,
            enableSorting: true,
            enableHiding: false,
        },
        ]
```

Previously an error would be reported however it did not make sense to
as the object has to be mapped again before it is displayed in react
(hence lets check there instead)
This commit is contained in:
Cameron 2023-10-20 14:50:58 +01:00 committed by GitHub
parent 5e083b156c
commit ee134f022c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,6 +79,15 @@ fn is_in_array_or_iter<'a, 'b>(
};
match parent.kind() {
AstKind::ArrowExpression(_) | AstKind::Function(_) => {
let Some(parent) = ctx.nodes().parent_node(parent.id()) else {
return None;
};
if let AstKind::ObjectProperty(_) = parent.kind() {
return None;
}
}
AstKind::ArrayExpression(_) => return Some(InsideArrayOrIterator::Array),
AstKind::CallExpression(v) => {
let callee = &v.callee.without_parenthesized();
@ -94,8 +103,9 @@ fn is_in_array_or_iter<'a, 'b>(
return None;
}
AstKind::JSXElement(_) | AstKind::JSXOpeningElement(_) => return None,
_ => node = parent,
_ => {}
}
node = parent;
}
}
@ -290,10 +300,33 @@ fn test() {
}
export const clusterFrameMap = observable.map<string, ClusterFrameInfo>();
"#,
None,
),
(
r#"
const columns: ColumnDef<User>[] = [{
accessorKey: 'lastName',
header: ({ column }) => <DataTableColumnHeader column={column} title="Last Name" />,
cell: ({ row }) => <div>{row.getValue('lastName')}</div>,
enableSorting: true,
enableHiding: false,
}]
"#,
None,
),
(
r#"
const columns: ColumnDef<User>[] = [{
accessorKey: 'lastName',
header: function ({ column }) { return <DataTableColumnHeader column={column} title="Last Name" /> },
cell: ({ row }) => <div>{row.getValue('lastName')}</div>,
enableSorting: true,
enableHiding: false,
}]
"#,
None,
),
];
let fail = vec![