fix(codemod): convert z.brand to v.pipe(.., v.brand(..))#1514
fix(codemod): convert z.brand to v.pipe(.., v.brand(..))#1514MerlijnW70 wants to merge 1 commit into
z.brand to v.pipe(.., v.brand(..))#1514Conversation
The zod-to-valibot codemod did not handle `.brand()`, so
`z.string().brand("X")` was mangled into the invalid
`v.string()("X")`. Add a `brand` method handler that appends
`v.brand(...)` to the schema's pipe, producing
`v.pipe(v.string(), v.brand("X"))`.
Closes #1501
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@intentos-dev is attempting to deploy a commit to the Open Circle Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe pull request adds support for transforming Zod's 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: 4
🤖 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`:
- Line 2: The import statement for addToPipe is missing the explicit `.ts`
extension on the relative path. Change the import statement from import {
addToPipe } from '../../helpers' to include the `.ts` extension at the end of
the helpers path, so it becomes import { addToPipe } from '../../helpers.ts', to
satisfy the repository ESLint rule requiring explicit file extensions in local
ESM imports.
- Around line 4-8: The exported function transformBrand is missing required
JSDoc documentation and the purity annotation. Add a JSDoc comment block above
the function that describes its purpose and parameters, and add the //
`@__NO_SIDE_EFFECTS__` comment immediately before the function declaration to
indicate it is a pure function and enable tree-shaking optimization.
In
`@codemod/zod-to-valibot/src/transform/schemas-and-links/methods/brand/index.ts`:
- Line 1: The barrel re-export statement is missing the explicit `.ts` extension
in the import path. In the index.ts file in the brand directory, update the
export statement from `export * from './brand';` to include the `.ts` extension
as `export * from './brand.ts';` to comply with the ESM import guidelines that
require explicit file extensions.
In `@codemod/zod-to-valibot/src/transform/schemas-and-links/methods/index.ts`:
- Line 2: The re-export statement for `brand` is missing the `.ts` file
extension. Update the export statement to include the explicit `.ts` extension
in the import path to align with the ESM import rules and ESLint enforcement.
Change the import path from `'./brand'` to `'./brand.ts'` in the export
statement.
🪄 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: 7f7b338e-8abd-4ec1-9402-c3fc1eac73cc
📒 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
| @@ -0,0 +1,20 @@ | |||
| import j from 'jscodeshift'; | |||
| import { addToPipe } from '../../helpers'; | |||
There was a problem hiding this comment.
Use .ts extension in local ESM import.
Line 2 should use an explicit .ts extension to satisfy the repository ESLint rule.
As per coding guidelines, "**/*.{ts,tsx,js,jsx}: Use ESM with .ts extensions in imports (enforced by ESLint)".
Suggested fix
-import { addToPipe } from '../../helpers';
+import { addToPipe } from '../../helpers.ts';📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { addToPipe } from '../../helpers'; | |
| import { addToPipe } from '../../helpers.ts'; |
🤖 Prompt for 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.
In
`@codemod/zod-to-valibot/src/transform/schemas-and-links/methods/brand/brand.ts`
at line 2, The import statement for addToPipe is missing the explicit `.ts`
extension on the relative path. Change the import statement from import {
addToPipe } from '../../helpers' to include the `.ts` extension at the end of
the helpers path, so it becomes import { addToPipe } from '../../helpers.ts', to
satisfy the repository ESLint rule requiring explicit file extensions in local
ESM imports.
Source: Coding guidelines
| export function transformBrand( | ||
| valibotIdentifier: string, | ||
| schemaExp: j.CallExpression | j.MemberExpression | j.Identifier, | ||
| args: j.CallExpression['arguments'] | ||
| ) { |
There was a problem hiding this comment.
Add required JSDoc and purity annotation on exported transformer.
This exported pure factory-style transformer is missing the required JSDoc and // @NO_SIDE_EFFECTS`` marker.
As per coding guidelines, "{library,packages,codemod}/**/*.{ts,tsx,js,jsx}: JSDoc required on exported functions ... Add // @NO_SIDE_EFFECTS`` comment before pure factory functions for tree-shaking optimization".
Suggested fix
+/**
+ * Appends `v.brand(...)` to the current schema pipe expression.
+ */
+// `@__NO_SIDE_EFFECTS__`
export function transformBrand(📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export function transformBrand( | |
| valibotIdentifier: string, | |
| schemaExp: j.CallExpression | j.MemberExpression | j.Identifier, | |
| args: j.CallExpression['arguments'] | |
| ) { | |
| /** | |
| * Appends `v.brand(...)` to the current schema pipe expression. | |
| */ | |
| // `@__NO_SIDE_EFFECTS__` | |
| export function transformBrand( | |
| valibotIdentifier: string, | |
| schemaExp: j.CallExpression | j.MemberExpression | j.Identifier, | |
| args: j.CallExpression['arguments'] | |
| ) { |
🤖 Prompt for 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.
In
`@codemod/zod-to-valibot/src/transform/schemas-and-links/methods/brand/brand.ts`
around lines 4 - 8, The exported function transformBrand is missing required
JSDoc documentation and the purity annotation. Add a JSDoc comment block above
the function that describes its purpose and parameters, and add the //
`@__NO_SIDE_EFFECTS__` comment immediately before the function declaration to
indicate it is a pure function and enable tree-shaking optimization.
Source: Coding guidelines
| @@ -0,0 +1 @@ | |||
| export * from './brand'; | |||
There was a problem hiding this comment.
Use .ts extension in barrel re-export.
Please make the re-export path explicit with .ts.
As per coding guidelines, "**/*.{ts,tsx,js,jsx}: Use ESM with .ts extensions in imports (enforced by ESLint)".
Suggested fix
-export * from './brand';
+export * from './brand.ts';📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export * from './brand'; | |
| export * from './brand.ts'; |
🤖 Prompt for 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.
In
`@codemod/zod-to-valibot/src/transform/schemas-and-links/methods/brand/index.ts`
at line 1, The barrel re-export statement is missing the explicit `.ts`
extension in the import path. In the index.ts file in the brand directory,
update the export statement from `export * from './brand';` to include the `.ts`
extension as `export * from './brand.ts';` to comply with the ESM import
guidelines that require explicit file extensions.
Source: Coding guidelines
| @@ -1,4 +1,5 @@ | |||
| export * from './array'; | |||
| export * from './brand'; | |||
There was a problem hiding this comment.
Use .ts extension in method re-export.
The new re-export should include .ts to align with the enforced import rule.
As per coding guidelines, "**/*.{ts,tsx,js,jsx}: Use ESM with .ts extensions in imports (enforced by ESLint)".
Suggested fix
-export * from './brand';
+export * from './brand.ts';📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export * from './brand'; | |
| export * from './brand.ts'; |
🤖 Prompt for 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.
In `@codemod/zod-to-valibot/src/transform/schemas-and-links/methods/index.ts` at
line 2, The re-export statement for `brand` is missing the `.ts` file extension.
Update the export statement to include the explicit `.ts` extension in the
import path to align with the ESM import rules and ESLint enforcement. Change
the import path from `'./brand'` to `'./brand.ts'` in the export statement.
Source: Coding guidelines
Closes #1501.
Problem
The
zod-to-valibotcodemod did not handle.brand(). The method name was not registered, so the.brand("…")call was left dangling on the converted schema, producing invalid output:Fix
Add a
brandmethod handler that appendsv.brand(...)to the schema's pipe via the existingaddToPipehelper (same shape as thetransformhandler), registerbrandinZOD_METHODS, and wire it into the method dispatch switch.Handles the basic case, brands after a validator chain, brands on object schemas, and brands on linked schemas:
Tests
Adds a
brandfixture (__testfixtures__/brand) covering the cases above and registers it in the test suite. Verified red without the fix (reproduces thev.string()("…")mangling) and green with it; the codemod package build + test suite passes.Summary by cubic
Fixes the
zod-to-valibotcodemod to correctly transformz.brand()intov.pipe(..., v.brand(...)), preventing invalid outputs likev.string()("X").brandmethod handler that appendsv.brand(...)viaaddToPipe.brandinZOD_METHODSand wired it into the method dispatcher.Written for commit 99922f0. Summary will update on new commits.