-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(useClickableProps): Codemod for changing dataTestId to data-testid #2406
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!!
packages/codemod/transformations/core/v2-to-v3/use-clickable-props-hook-migration.ts
Outdated
Show resolved
Hide resolved
root | ||
.find(j.CallExpression, { | ||
callee: { | ||
type: "Identifier", | ||
name: "useClickableProps" | ||
} | ||
}) | ||
.forEach(path => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would using JSCodeshift's findVariableDeclarators(hookName)
help here?
and then you can maybe find the ObjectExpression, with Property of key
of { type: 'Identifier' and name: 'dataTestId }
something like:
findVariableDeclarators(hookName)
.find(ObjectExpression)
.find(Property, {
key: {
type: 'Identifier',
name: 'dataTestId',
}
})
this can save you all the code from line 21 to 28 I believe
the rest can be changed with iterating over the Collection been made with forEach
on each path
.
something like:
path.node.key = j.literal('data-testid');
those two can turn into a generic util for changing a Callee argument name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 💪🏼
https://monday.monday.com/boards/3532714909/views/80492480/pulses/7338211944