Skip to content

fix(codemod): convert z.brand to v.pipe(.., v.brand(..))#1514

Closed
MerlijnW70 wants to merge 1 commit into
open-circle:mainfrom
MerlijnW70:fix/codemod-brand
Closed

fix(codemod): convert z.brand to v.pipe(.., v.brand(..))#1514
MerlijnW70 wants to merge 1 commit into
open-circle:mainfrom
MerlijnW70:fix/codemod-brand

Conversation

@MerlijnW70

@MerlijnW70 MerlijnW70 commented Jun 19, 2026

Copy link
Copy Markdown

Closes #1501.

Problem

The zod-to-valibot codemod did not handle .brand(). The method name was not registered, so the .brand("…") call was left dangling on the converted schema, producing invalid output:

// input
z.string().brand("StationNumber");
// before (broken)
v.string()("StationNumber");
// expected
v.pipe(v.string(), v.brand("StationNumber"));

Fix

Add a brand method handler that appends v.brand(...) to the schema's pipe via the existing addToPipe helper (same shape as the transform handler), register brand in ZOD_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:

z.string().min(1).brand("NonEmptyId")    // → v.pipe(v.string(), v.minLength(1), v.brand("NonEmptyId"))
z.object({ id: z.string() }).brand("E")  // → v.pipe(v.object({ id: v.string() }), v.brand("E"))

Tests

Adds a brand fixture (__testfixtures__/brand) covering the cases above and registers it in the test suite. Verified red without the fix (reproduces the v.string()("…") mangling) and green with it; the codemod package build + test suite passes.


Summary by cubic

Fixes the zod-to-valibot codemod to correctly transform z.brand() into v.pipe(..., v.brand(...)), preventing invalid outputs like v.string()("X").

  • Bug Fixes
    • Added a brand method handler that appends v.brand(...) via addToPipe.
    • Registered brand in ZOD_METHODS and wired it into the method dispatcher.
    • Added tests covering basic, chained validators, object schemas, and linked schemas.

Written for commit 99922f0. Summary will update on new commits.

Review in cubic

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>
@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

@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.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. fix A smaller enhancement or bug fix labels Jun 19, 2026
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The pull request adds support for transforming Zod's .brand() method in the zod-to-valibot codemod. A new transformBrand function is introduced that wraps the schema expression and brand arguments into a v.pipe(..., v.brand(...)) call via addToPipe. The function is barrel-exported through a new brand/index.ts and re-exported from the methods/index.ts. The string 'brand' is added to the ZOD_METHODS constant, and a case 'brand' branch is added to the toValibotMethodExp switch in schemas-and-links.ts. Test fixtures covering four .brand() usage patterns and a new test case entry in defineTests are also included.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding support for converting Zod's .brand() method to Valibot's v.pipe(..., v.brand(...)) pattern, which is the core objective of this PR.
Description check ✅ Passed The description is comprehensive and directly related to the changeset. It clearly explains the problem (broken output), the fix applied, concrete examples of transformations, and test coverage verification.
Linked Issues check ✅ Passed The PR successfully addresses issue #1501 by implementing support for .brand() conversion. It correctly transforms z.string().brand(...) to v.pipe(v.string(), v.brand(...)) and handles multiple schema patterns as required.
Out of Scope Changes check ✅ Passed All code changes are directly scoped to implementing the .brand() method handler in the codemod: adding the method handler, registering it in constants, wiring it into dispatch logic, and adding corresponding tests. No unrelated changes detected.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9bb6617 and 99922f0.

📒 Files selected for processing (8)
  • codemod/zod-to-valibot/__testfixtures__/brand/input.ts
  • codemod/zod-to-valibot/__testfixtures__/brand/output.ts
  • codemod/zod-to-valibot/src/test-setup.test.ts
  • codemod/zod-to-valibot/src/transform/schemas-and-links/constants.ts
  • codemod/zod-to-valibot/src/transform/schemas-and-links/methods/brand/brand.ts
  • codemod/zod-to-valibot/src/transform/schemas-and-links/methods/brand/index.ts
  • codemod/zod-to-valibot/src/transform/schemas-and-links/methods/index.ts
  • codemod/zod-to-valibot/src/transform/schemas-and-links/schemas-and-links.ts

@@ -0,0 +1,20 @@
import j from 'jscodeshift';
import { addToPipe } from '../../helpers';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
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

Comment on lines +4 to +8
export function transformBrand(
valibotIdentifier: string,
schemaExp: j.CallExpression | j.MemberExpression | j.Identifier,
args: j.CallExpression['arguments']
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
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';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
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';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 8 files

Re-trigger cubic

@MerlijnW70 MerlijnW70 closed this by deleting the head repository Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A smaller enhancement or bug fix size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codemod breaks z.brand

2 participants