Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions codemod/zod-to-valibot/__testfixtures__/brand/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { z } from "zod";

const Schema1 = z.string().brand("StationNumber");
const Schema2 = z.object({key: z.string()}).brand("Config");
4 changes: 4 additions & 0 deletions codemod/zod-to-valibot/__testfixtures__/brand/output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as v from "valibot";

const Schema1 = v.pipe(v.string(), v.brand("StationNumber"));
const Schema2 = v.pipe(v.object({key: v.string()}), v.brand("Config"));
1 change: 1 addition & 0 deletions codemod/zod-to-valibot/src/test-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defineTests(transform, [
'array-schema',
'array-validation-methods',
'bigint-validation-methods',
'brand',
'coerce-bigint-schema',
'coerce-boolean-schema',
'coerce-date-schema',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const ZOD_VALUE_TYPE_SCHEMAS: readonly (typeof ZOD_SCHEMAS)[number][] = [
export const ZOD_VALIDATORS = [
'base64',
'base64url',
'brand',
'cidr',
'cuid',
'cuid2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
import { ObjectModifier, ZodSchemaType } from './types';
import {
transformBase64,
transformBrand,
transformCUID2,
transformDateTime,
transformDate as transformDateValidator,
Expand Down Expand Up @@ -260,6 +261,8 @@ function toValibotActionExp(
return transformBase64(...args);
case 'base64url':
return transformUnimplemented(...args, 'base64url');
case 'brand':
return transformBrand(...args);
case 'cidr':
return transformUnimplemented(...args, 'cidr');
case 'cuid':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import j from 'jscodeshift';

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

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

return j.callExpression(
j.memberExpression(j.identifier(valibotIdentifier), j.identifier('brand')),
args
);
}
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './base64';
export * from './brand';
export * from './cuid2';
export * from './date';
export * from './datetime';
Expand Down