fix(zod-to-valibot): convert the .brand() method - #1560
Conversation
`.brand(name)` was not recognized, so the codemod dropped the method name and
emitted the invalid `v.string()("name")`. Register `brand` as a validator that
maps to `v.brand(name)`, so it composes into the pipe like the other validators
(`v.pipe(v.string(), v.brand("name")))`.
WalkthroughAdds 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: 2
🤖 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/validators/brand/brand.ts`:
- Around line 3-6: Add the required JSDoc describing the exported transformBrand
function, and place the // `@__NO_SIDE_EFFECTS__` annotation immediately before
its declaration to mark it as a pure factory function.
In
`@codemod/zod-to-valibot/src/transform/schemas-and-links/validators/brand/index.ts`:
- Line 1: Update the local re-exports in
codemod/zod-to-valibot/src/transform/schemas-and-links/validators/brand/index.ts
lines 1-1 and
codemod/zod-to-valibot/src/transform/schemas-and-links/validators/index.ts lines
2-2 to include the .ts extension when referencing the brand module.
🪄 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: 52fa26be-1b45-47da-9584-a5039c806f6b
📒 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/schemas-and-links.tscodemod/zod-to-valibot/src/transform/schemas-and-links/validators/brand/brand.tscodemod/zod-to-valibot/src/transform/schemas-and-links/validators/brand/index.tscodemod/zod-to-valibot/src/transform/schemas-and-links/validators/index.ts
| export function transformBrand( | ||
| valibotIdentifier: string, | ||
| args: j.CallExpression['arguments'] | ||
| ) { |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add the required JSDoc and purity annotation.
As per coding guidelines, exported functions under codemod/** require JSDoc, and pure factory functions require // @NO_SIDE_EFFECTS`` before the declaration.
Suggested update
+/**
+ * Creates a Valibot brand action 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, | |
| args: j.CallExpression['arguments'] | |
| ) { | |
| /** | |
| * Creates a Valibot brand action expression. | |
| */ | |
| // `@__NO_SIDE_EFFECTS__` | |
| export function transformBrand( | |
| valibotIdentifier: string, | |
| 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/validators/brand/brand.ts`
around lines 3 - 6, Add the required JSDoc describing the exported
transformBrand function, and place the // `@__NO_SIDE_EFFECTS__` annotation
immediately before its declaration to mark it as a pure factory function.
Source: Coding guidelines
| @@ -0,0 +1 @@ | |||
| export * from './brand'; | |||
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add .ts extensions to both new local re-exports.
codemod/zod-to-valibot/src/transform/schemas-and-links/validators/brand/index.ts#L1-L1: re-export from./brand.ts.codemod/zod-to-valibot/src/transform/schemas-and-links/validators/index.ts#L2-L2: re-export from./brand.ts.
As per coding guidelines, ESM imports must use .ts extensions.
📍 Affects 2 files
codemod/zod-to-valibot/src/transform/schemas-and-links/validators/brand/index.ts#L1-L1(this comment)codemod/zod-to-valibot/src/transform/schemas-and-links/validators/index.ts#L2-L2
🤖 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/validators/brand/index.ts`
at line 1, Update the local re-exports in
codemod/zod-to-valibot/src/transform/schemas-and-links/validators/brand/index.ts
lines 1-1 and
codemod/zod-to-valibot/src/transform/schemas-and-links/validators/index.ts lines
2-2 to include the .ts extension when referencing the brand module.
Source: Coding guidelines
Fixes #1501
The
@valibot/zod-to-valibotcodemod did not recognize.brand(), so it dropped the method name and produced invalid output:brandis now registered as a validator that maps tov.brand(name), so it composes into the pipe the same way the other validators do:The change follows the existing validator pattern: a
transformBrandinvalidators/brand/, exported fromvalidators/index.ts, dispatched from thetoValibotActionExpswitch, andbrandadded toZOD_VALIDATORS. The.brand()argument is passed straight through since it carries no message option.A
__testfixtures__/brandfixture is added (registered in sorted order). It fails onmain(the transform drops the brand) and passes with the change;vitest runis green with 72 fixtures and no regressions.Summary by CodeRabbit
New Features
Tests