Skip to content
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

Merged
merged 3 commits into from
Sep 2, 2024

Conversation

rivka-ungar
Copy link
Contributor

@rivka-ungar rivka-ungar requested a review from a team as a code owner September 1, 2024 07:11
@talkor talkor changed the title Chore(Icon): Codemod for changing dataTestId to data-testid chore(useClickableProps): Codemod for changing dataTestId to data-testid Sep 1, 2024
Copy link
Contributor

@YossiSaadi YossiSaadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!!

Comment on lines 13 to 20
root
.find(j.CallExpression, {
callee: {
type: "Identifier",
name: "useClickableProps"
}
})
.forEach(path => {
Copy link
Contributor

@YossiSaadi YossiSaadi Sep 1, 2024

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

Copy link
Contributor

@YossiSaadi YossiSaadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 💪🏼

@rivka-ungar rivka-ungar merged commit 259fb0b into vibe3 Sep 2, 2024
10 checks passed
@rivka-ungar rivka-ungar deleted the codemod-for-useclickableprops-7338211944 branch September 2, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants