Skip to content

fix(zod-to-valibot): convert the .brand() method - #1560

Open
n0liu wants to merge 1 commit into
open-circle:mainfrom
n0liu:fix/codemod-brand
Open

fix(zod-to-valibot): convert the .brand() method#1560
n0liu wants to merge 1 commit into
open-circle:mainfrom
n0liu:fix/codemod-brand

Conversation

@n0liu

@n0liu n0liu commented Jul 22, 2026

Copy link
Copy Markdown

Fixes #1501

The @valibot/zod-to-valibot codemod did not recognize .brand(), so it dropped the method name and produced invalid output:

// in
z.string().brand("StationNumber")
// out (before) — not valid
v.string()("StationNumber")

brand is now registered as a validator that maps to v.brand(name), so it composes into the pipe the same way the other validators do:

// out (after)
v.pipe(v.string(), v.brand("StationNumber"))

The change follows the existing validator pattern: a transformBrand in validators/brand/, exported from validators/index.ts, dispatched from the toValibotActionExp switch, and brand added to ZOD_VALIDATORS. The .brand() argument is passed straight through since it carries no message option.

A __testfixtures__/brand fixture is added (registered in sorted order). It fails on main (the transform drops the brand) and passes with the change; vitest run is green with 72 fixtures and no regressions.

Summary by CodeRabbit

  • New Features

    • Added support for converting Zod branded schemas to equivalent Valibot schemas.
    • Supports branded strings and objects, including custom brand names.
  • Tests

    • Added coverage for branded schema transformations, including chained schema actions.

`.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")))`.
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. fix A smaller enhancement or bug fix labels Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds brand support to the Zod-to-Valibot codemod by registering the validator, dispatching it to a new AST transformer, and generating Valibot brand actions. Adds fixtures and test registration for branded string and object schemas.

Possibly related PRs

  • open-circle/valibot#1542: Adds similar Zod .brand(...) support through the codemod validator dispatcher and transformer helper.
🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding .brand() conversion support to the zod-to-valibot codemod.
Linked Issues check ✅ Passed The changes add .brand() dispatch, transformation, exports, and fixtures, matching the linked issue's expected output.
Out of Scope Changes check ✅ Passed All edits are directly tied to adding and testing .brand() support; no unrelated changes are evident.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90bc2c7 and 052df46.

📒 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/schemas-and-links.ts
  • codemod/zod-to-valibot/src/transform/schemas-and-links/validators/brand/brand.ts
  • codemod/zod-to-valibot/src/transform/schemas-and-links/validators/brand/index.ts
  • codemod/zod-to-valibot/src/transform/schemas-and-links/validators/index.ts

Comment on lines +3 to +6
export function transformBrand(
valibotIdentifier: string,
args: j.CallExpression['arguments']
) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 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

@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

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:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codemod breaks z.brand

1 participant