-
-
Notifications
You must be signed in to change notification settings - Fork 262
feat: graceful multiple imports exit + transform
and refine
#1273
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
base: main
Are you sure you want to change the base?
feat: graceful multiple imports exit + transform
and refine
#1273
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Pull Request Overview
This PR adds support for transforming Zod's refine
and transform
methods to their Valibot equivalents and improves error handling for multiple import scenarios. The changes enhance the codemod to handle more Zod patterns while providing better feedback when transformation fails.
- Adds transformation support for
refine
(to Valibot'scheck
) andtransform
methods - Improves error handling by adding descriptive comments when imports cannot be transformed
- Includes comprehensive test coverage for the new functionality
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
schemas-and-links.ts | Registers refine and transform method transformers |
transform/transform.ts | Implements Zod transform to Valibot transform conversion |
refine/refine.ts | Implements Zod refine to Valibot check conversion with message extraction |
index.ts | Adds error comment injection for unsuccessful import transformations |
imports.ts | Adds cause field to error return types for better error reporting |
constants.ts | Adds refine and transform to supported Zod methods list |
test files | Adds test fixtures for new functionality and multiple import scenarios |
return arg.properties[0].value; | ||
} | ||
return arg; | ||
}) as typeof args; |
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.
The type assertion as typeof args
is potentially unsafe. Consider using a type guard or proper type narrowing to ensure type safety when transforming arguments.
}) as typeof args; | |
}); |
Copilot uses AI. Check for mistakes.
// If the argument is an object with { message: "..." }, extract the message | ||
if ( | ||
arg.type === 'ObjectExpression' && | ||
arg.properties.length === 1 && | ||
arg.properties[0].type === 'ObjectProperty' && | ||
arg.properties[0].key.type === 'Identifier' && | ||
arg.properties[0].key.name === 'message' | ||
) { | ||
return arg.properties[0].value; |
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.
The nested conditional checks for object structure are complex and brittle. Consider extracting this logic into a separate helper function with proper type guards for better maintainability and testing.
// If the argument is an object with { message: "..." }, extract the message | |
if ( | |
arg.type === 'ObjectExpression' && | |
arg.properties.length === 1 && | |
arg.properties[0].type === 'ObjectProperty' && | |
arg.properties[0].key.type === 'Identifier' && | |
arg.properties[0].key.name === 'message' | |
) { | |
return arg.properties[0].value; | |
if (isMessageObjectExpression(arg)) { | |
// If the argument is an object with { message: "..." }, extract the message | |
// TypeScript type narrowing ensures arg is ObjectExpression here | |
return (arg.properties[0] as j.ObjectProperty).value; |
Copilot uses AI. Check for mistakes.
transform
and refine
commit: |
Some other small codemod fixes: this fixes
transform
,refine
and adds a comment to explain why it's not possible to migrate the file when there's multiple zod imports (i also think we could try to be a bit smarter here and still migrate if at least one import isz
fromzod
but that would lead to squiggles in the file unless we also replace all the zod types)