fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
5.59k stars 169 forks source link

Codemod skipping certain schema #623

Open hyunbinseo opened 1 month ago

hyunbinseo commented 1 month ago

This is the only schema that the Codemod failed to transform.

// Codemod: valibot/migrate-to-v0.31.0@0.1.0
// Original code is formatted using tabs, not spaces.

// Untouched
const RevokeUsersSchema = transform(
  SqidsArraySchema, //
  (encodedUserIds) => encodedUserIds.map((encodedUserId) => sqids.decode(encodedUserId)[0]),
);

// Expected
const RevokeUsersSchema = pipe(
  SqidsArraySchema,
  transform((encodedUserIds) =>
    encodedUserIds.map((encodedUserId) => sqids.decode(encodedUserId)[0]),
  ),
);
fabian-hiller commented 1 month ago

Actually, there are a few more cases, but my time is limited. We will try to fix the important parts in the long run. Thank you for your feedback!

fabian-hiller commented 1 month ago

I think it does not work because of your comment. Without it it seems to work.

hyunbinseo commented 1 month ago

For context, the // is added to format the code multi-line using Prettier.

fabian-hiller commented 1 month ago

We will investigate it 🫡

HerringtonDarkholme commented 4 weeks ago

Hi ast-grep author here. 👋 ast-grep is used in the underlying codemod library.

The issue here is probably because the pattern used here is sensitive to comment.

I can give it a look to see if the pattern code can be rewritten into a more robust form.

morgante commented 3 weeks ago

Hi @hyunbinseo, did you try the Grit version? It isn't sensitive to the comment issue.