fix(to-valibot): support z.brand() in codemod (#1501) - #1542
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (8)
WalkthroughThe Zod-to-Valibot codemod now recognizes the Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@codemod/zod-to-valibot/src/transform/schemas-and-links/methods/brand/brand.ts`:
- Around line 4-8: Add JSDoc immediately above the exported transformBrand
function describing its purpose, and add the // `@__NO_SIDE_EFFECTS__` annotation
required for this pure factory transformation. Keep the function signature and
implementation unchanged.
- Around line 1-2: Update the relative ESM specifiers in brand.ts,
brand/index.ts, and methods/index.ts to include the .ts extension: use
../../helpers.ts, ./brand.ts, and ./brand.ts respectively. Leave the jscodeshift
package import unchanged.
- Around line 4-20: Update transformBrand to handle Zod’s type-only brand<...>()
form instead of forwarding only runtime args: preserve the brand name by
converting the type argument to the required Valibot name, or explicitly reject
unsupported type-only branding. Add a fixture covering
z.string().brand<"UserId">() and verify the resulting transform behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2ecf73f0-45e6-4781-ac57-4211df4fe6eb
📒 Files selected for processing (8)
codemod/zod-to-valibot/__testfixtures__/brand/input.tscodemod/zod-to-valibot/__testfixtures__/brand/output.tscodemod/zod-to-valibot/src/test-setup.test.tscodemod/zod-to-valibot/src/transform/schemas-and-links/constants.tscodemod/zod-to-valibot/src/transform/schemas-and-links/methods/brand/brand.tscodemod/zod-to-valibot/src/transform/schemas-and-links/methods/brand/index.tscodemod/zod-to-valibot/src/transform/schemas-and-links/methods/index.tscodemod/zod-to-valibot/src/transform/schemas-and-links/schemas-and-links.ts
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
de44991 to
b8efed5
Compare
|
Addressed the review feedback and rebased the branch onto the latest Changes:
Local checks:
|
b8efed5 to
63c87f3
Compare
The codemod did not recognize Zod's .brand() method, so
z.string().brand("X") was emitted as the broken v.string()("X").
Add a brand method handler that maps it into a pipe action,
producing v.pipe(v.string(), v.brand("X")), matching how the
existing transform method is handled.
Fixes open-circle#1501
63c87f3 to
20ea02b
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Overview
The
@valibot/zod-to-valibotcodemod had no handler for Zod's.brand()method. Because the method went unrecognized, it was left in place as a call on the transformed schema, producing invalid output likev.string()("Name")(a schema object called as a function).Fixes #1501
Fix
Added a
brandmethod handler that mapsschema.brand(name)into a pipe action, mirroring how the existingtransformmethod is handled. It uses the sharedaddToPipehelper so the brand is appended to any existing pipe:The handler is wired into
ZOD_METHODS(constants),methods/index.ts, and the schemas-and-links dispatcher.Tests
Added a
brandtest fixture (__testfixtures__/brand/) covering a basic brand, a brand after a validator chain, a brand on a number schema, and a brand on a linked schema, and registered it intest-setup.test.ts. The full codemod suite passes (72/72).Summary by CodeRabbit